diff --git a/html/gachapy/controller.html b/html/gachapy/controller.html deleted file mode 100644 index d7ef39d..0000000 --- a/html/gachapy/controller.html +++ /dev/null @@ -1,1878 +0,0 @@ - - - - - - -gachapy.controller API documentation - - - - - - - - - - - -
-
-
-

Module gachapy.controller

-
-
-

The controller used for all high level management of the gacha game

-

Classes

-

Controller -A controller for an instance of a gacha game

-

Exceptions

-

PullError -An exception thrown when pulling from a banner

-

Functions

-

sort_player_key(player) : int -The key used to sort players in a list of players -default_key(rarity) : float -The default key function

-
- -Expand source code - -
"""The controller used for all high level management of the gacha game
-
-Classes
--------
-Controller
-    A controller for an instance of a gacha game
-
-Exceptions
-----------
-PullError
-    An exception thrown when pulling from a banner
-
-Functions
----------
-sort_player_key(player) : int
-    The key used to sort players in a list of players
-default_key(rarity) : float
-    The default key function
-"""
-
-from typing import Optional
-from gachapy.objects import *
-
-def default_key(rarity) -> float :
-    """The default key function
-
-    Parameters
-    ----------
-    rarity : float
-        the rarity of the item
-    
-    Returns
-    -------
-    float
-        the weight for the rarity
-    """
-    return 1 / rarity
-
-class PullError(Exception) :
-    """An exception thrown when pulling from a banner
-    """
-    pass
-
-class Controller :
-    """A controller for an instance of a gacha game
-
-    Fields
-    ------
-    items : List[Item]
-        the list of items that are in the item pool for the gacha
-    banners : List[Banner]
-        the list of banners that are available for the gacha
-    players : List[Player]
-        the list of players enrolled in the gacha
-    
-    Methods
-    -------
-    find_item_by_name(item_name) : Optional[Item]
-        Returns the Item object with the given name or None if not found
-    find_banner_by_name(banner_name) : Optional[Banner]
-        Returns the Banner object with the given name or None if not found
-    find_player_by_name(player_name) : Optional[Banner]
-        Returns the Player object with the given name or None if not found
-    find_item_by_id(item_id) : Optional[Item]
-        Returns the Item object with the given id or None if not found
-    find_player_by_id(player_id) : Optional[Player]
-        Returns the Player object with the given id or None if not found
-    pull(player_id,banner_name) : Optional[Item]
-        Pulls and returns an item from the specified banner for the specified player
-    change_money_player(player_id,amount) : bool
-        Changes the specified player's money by the amount specified
-    add_new_item(name,id,rarity) : Optional[Item]
-        Adds a new item to the gacha game
-    add_new_banner(name,item_list_str,price) : Optional[Banner]
-        Adds a new banner to the gacha game
-    add_new_player(name,id,start_money,items_str) : Optional[Player]
-        Adds a new player to the gacha game
-    remove_item(id) : Optional[Item]
-        Removes the specified item from the gacha game
-    remove_banner(name) : Optional[Banner]
-        Removes the specified banner from the gacha game
-    remove_player(id) : Optional[Player]
-        Removes the specified player from the gacha game
-    create_random_banner(name,num_items,price) -> Optional[Banner]
-        Creates a random banner with the given name and number of items
-    remove_all_banners() : None
-        Removes all of the banners in the game
-    top_items(num_items) : List[Item]
-        Returns the top specified number of items in the game in terms of rarity
-    top_players(num_players) : List[Player]
-        Returns the top specified number of players in the game in terms of net worth
-    """
-
-    def __init__(self,items=[],banners=[],players=[]) -> None:
-        """Creates an instance of a gacha controller
-
-        Parameters
-        ----------
-        items : List[Item]
-            the list of items that are in the item pool for the gacha
-        banners : List[Banner]
-            the list of banners that are available for the gacha
-        players : List[Player]
-            the list of players enrolled in the gacha
-        """
-        self.items = items
-        self.banners = banners
-        self.players = players
-    
-    def find_item_by_name(self, item_name) -> Optional[Item]:
-        """Returns the Item object with the given name or None if not found
-
-        Parameters
-        ----------
-        item_name : str
-            the name of the item
-        
-        Returns
-        -------
-        Optional[Item]
-            the item object with the given name or None if not found 
-        """
-        items = [i for i in self.items if i.name == item_name]
-        if len(items) < 1 :
-            return None
-        return items[0]
-    
-    def find_banner_by_name(self, banner_name) -> Optional[Banner]:
-        """Returns the Banner object with the given name or None if not found
-
-        Parameters
-        ----------
-        banner_name : str
-            the name of the banner
-        
-        Returns
-        -------
-        Optional[Banner]
-            the banner object with the given name or None if not found 
-        """
-        banners = [i for i in self.banners if i.name == banner_name]
-        if len(banners) < 1 :
-            return None
-        return banners[0]
-
-    
-    def find_player_by_name(self,player_name) -> Optional[Player]:
-        """Returns the Player object with the given name or None if not found
-
-        Parameters
-        ----------
-        player_name : str
-            the name of the player
-        
-        Returns
-        -------
-        Optional[player]
-            the player object with the given name or None if not found 
-        """
-        players = [i for i in self.players if i.name == player_name]
-        if len(players) < 1 :
-            return None
-        return players[0]
-    
-    def find_item_by_id(self, item_id) -> Optional[Item]:
-        """Returns the Item object with the given id or None if not found
-
-        Parameters
-        ----------
-        item_id : str
-            the id of the item
-        
-        Returns
-        -------
-        Optional[Item]
-            the item object with the given id or None if not found 
-        """
-        items = [i for i in self.items if i.id == item_id]
-        if len(items) < 1 :
-            return None
-        return items[0]
-    
-    def find_player_by_id(self,player_id) -> Optional[Player]:
-        """Returns the Player object with the given id or None if not found
-
-        Parameters
-        ----------
-        player_id : str
-            the id of the player
-        
-        Returns
-        -------
-        Optional[player]
-            the player object with the given id or None if not found 
-        """
-        players = [i for i in self.players if i.id == player_id]
-        if len(players) < 1 :
-            return None
-        return players[0]
-
-    def pull(self,player_id,banner_name) -> Optional[Item] :
-        """Pulls and returns an item from the specified banner for the specified player
-
-        Parameters
-        ----------
-        player_id : str
-            the id of the selected player, must be valid
-        banner_name : str
-            the name of the selected player, must be valid
-
-        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
-        """
-        player = self.find_player_by_id(player_id)
-        if player == None :
-            raise PullError("Player not found")
-        banner = self.find_banner_by_name(banner_name)
-        if banner == None :
-            raise PullError("Banner not found")
-        if player.change_money(-1 * banner.price) :
-            item = banner.pull()
-            player.add_item(item)
-            return item
-        return None
-
-    def change_money_player(self,player_id,amount) -> bool :
-        """Changes the specified player's money by the amount specified
-
-        Parameters
-        ----------
-        player_name : str
-            the name of the player
-        amount : float
-            the amount to change the money by (positive for add, negative for subtract)
-
-        Returns
-        ------
-        bool
-            True if the amount was able to be added or removed from account (does not create 
-            negative money value), False otherwise
-        """
-        player = self.find_player_by_id(player_id)
-        if player == None :
-            return False
-        return player.change_money(amount)
-
-    def add_new_item(self,name,id,rarity) -> Optional[Item] :
-        """Adds a new item to the gacha game
-
-        Parameters
-        ----------
-        name : str
-            the name of the new item
-        description : str
-            the description of the new item
-        rarity : int
-            the rarity of the item
-
-        Returns
-        -------
-        Optional[Item]
-            the Item object representing the new item or None if the item already exists
-        """
-        item = self.find_item_by_id(id)
-        if item != None :
-            return None
-        new_item = Item(name,id,rarity)
-        self.items.append(new_item)
-        return new_item
-    
-    def add_new_banner(self,name,item_list_str,price,key=default_key) -> Optional[Banner] :
-        """Adds a new banner to the gacha game
-
-        Parameters
-        ----------
-        name : str
-            the name of the new banner
-        item_list_str : List[str]
-            the list of the ids of the items in the banner
-        price : float
-            the price of pulling from the banner
-        key : func
-            function that determines drop rate from rarity
-        
-        Returns
-        -------
-        Optional[Banner]
-            the Banner object representing the new banner or None if the banner already exists
-        """
-        banner = self.find_banner_by_name(name)
-        if banner != None :
-            return None
-        item_list = [self.find_item_by_id(i) for i in item_list_str]
-        new_banner = Banner(name,item_list,price,key)
-        self.banners.append(new_banner)
-        return Banner
-
-    def add_new_player(self,name,id,start_money,items_str=[]) -> Optional[Player] :
-        """Adds a new player to the gacha game
-
-        Parameters
-        ----------
-        name : str
-            the name of the new player
-        id : str
-            the id of the new player
-        start_money : float
-            the amount of money the new player will start with
-        items_str : List[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 the player already exists
-        """
-        player = self.find_player_by_id(id)
-        if player != None :
-            return None
-        items_list = [self.find_item_by_id(i) for i in items_str]
-        new_player = Player(name,id,items_list,start_money)
-        self.players.append(new_player)
-        return new_player
-
-    def remove_item(self,item_id) -> Optional[Item]:
-        """Removes the specified item from the gacha game
-
-        Parameters
-        ----------
-        item_id : str
-            the name of the item to remove
-
-        Returns
-        -------
-        Optional[Item]
-            the removed item or None if item does not exist
-        """
-        for item in self.items :
-            if item.id == item_id :
-                self.items.remove(item)
-                return item
-        return None
-
-    
-    def remove_banner(self,name) -> Optional[Banner] :
-        """Removes the specified banner from the gacha game
-
-        Parameters
-        ----------
-        name : str
-            the name of the banner to remove
-
-        Returns
-        -------
-        Optional[Banner]
-            the removed banner or None if banner does not exist
-        """
-        for banner in self.banners :
-            if banner.name == name :
-                self.banner.remove(banner)
-                return banner
-        return None
-    
-    def remove_player(self,player_id) -> Optional[Player] :
-        """Removes the specified player from the gacha game
-
-        Parameters
-        ----------
-        player_id : str
-            the id of the player to remove
-
-        Returns
-        -------
-        Optional[Player]
-            the removed player or None if player does not exist
-        """
-        for player in self.players :
-            if player.id == player_id :
-                self.players.remove(player)
-                return player
-        return None
-    
-    def create_random_banner(self,name,num_items,price=-1,key=default_key) -> Optional[Banner] :
-        """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
-        ----------
-        name : str
-            the name of the random banner
-        num_items : int
-            the number of items in the banner
-        price : float
-            the price of the banner
-        key : func
-            function that determines drop rate from rarity
-        
-        Returns
-        -------
-        Optional[Banner]
-            the banner created or None if a banner with the name specified already exists
-        """
-        item_list = random.choices(self.items,k=num_items)
-        item_list_str = [item.id for item in item_list]
-        if price < 0 :
-            price = 0
-            for item in item_list :
-                price += item.rarity
-            price /= len(item_list)
-        return self.add_new_banner(name,item_list_str,price)
-    
-    def remove_all_banners(self) -> None:
-        """Removes all of the banners in the game
-
-        Returns
-        -------
-        None
-        """
-        self.banners = []
-
-    def top_items(self,num_items) -> List[Item] :
-        """Returns the top specified number of items in the game in terms of rarity
-
-        Parameters
-        ----------
-        num_items : int
-            the number of items to return
-        
-        Returns
-        -------
-        List[Item]
-            the list of top items
-        """
-        sort_list = sorted(self.items,key=sort_item_key,reverse=True)
-        return sort_list[:num_items-1]
-
-    def top_players(self,num_players) -> List[Player] :
-        """Returns the top specified number of players in the game in terms of net worth
-
-        Parameters
-        ----------
-        num_players : int
-            the number of players to return
-        
-        Returns
-        -------
-        List[Player]
-            the list of top players
-        """
-        sort_list = sorted(self.players,key=sort_player_key,reverse=True)
-        return sort_list[:num_players-1]
-
-def sort_player_key(player) -> int :
-    """The key used to sort players in a list of players
-
-    Parameters
-    ----------
-    player : Player
-        the player to extract the key from
-    
-    Returns
-    -------
-    int
-        the key of the player
-    """
-    return sum([i.rarity for i in player.items])
-
-
-
-
-
-
-
-

Functions

-
-
-def default_key(rarity) ‑> float -
-
-

The default key function

-

Parameters

-
-
rarity : float
-
the rarity of the item
-
-

Returns

-
-
float
-
the weight for the rarity
-
-
- -Expand source code - -
def default_key(rarity) -> float :
-    """The default key function
-
-    Parameters
-    ----------
-    rarity : float
-        the rarity of the item
-    
-    Returns
-    -------
-    float
-        the weight for the rarity
-    """
-    return 1 / rarity
-
-
-
-def sort_player_key(player) ‑> int -
-
-

The key used to sort players in a list of players

-

Parameters

-
-
player : Player
-
the player to extract the key from
-
-

Returns

-
-
int
-
the key of the player
-
-
- -Expand source code - -
def sort_player_key(player) -> int :
-    """The key used to sort players in a list of players
-
-    Parameters
-    ----------
-    player : Player
-        the player to extract the key from
-    
-    Returns
-    -------
-    int
-        the key of the player
-    """
-    return sum([i.rarity for i in player.items])
-
-
-
-
-
-

Classes

-
-
-class Controller -(items=[], banners=[], players=[]) -
-
-

A controller for an instance of a gacha game

-

Fields

-

items : List[Item] -the list of items that are in the item pool for the gacha -banners : List[Banner] -the list of banners that are available for the gacha -players : List[Player] -the list of players enrolled in the gacha

-

Methods

-

find_item_by_name(item_name) : Optional[Item] -Returns the Item object with the given name or None if not found -find_banner_by_name(banner_name) : Optional[Banner] -Returns the Banner object with the given name or None if not found -find_player_by_name(player_name) : Optional[Banner] -Returns the Player object with the given name or None if not found -find_item_by_id(item_id) : Optional[Item] -Returns the Item object with the given id or None if not found -find_player_by_id(player_id) : Optional[Player] -Returns the Player object with the given id or None if not found -pull(player_id,banner_name) : Optional[Item] -Pulls and returns an item from the specified banner for the specified player -change_money_player(player_id,amount) : bool -Changes the specified player's money by the amount specified -add_new_item(name,id,rarity) : Optional[Item] -Adds a new item to the gacha game -add_new_banner(name,item_list_str,price) : Optional[Banner] -Adds a new banner to the gacha game -add_new_player(name,id,start_money,items_str) : Optional[Player] -Adds a new player to the gacha game -remove_item(id) : Optional[Item] -Removes the specified item from the gacha game -remove_banner(name) : Optional[Banner] -Removes the specified banner from the gacha game -remove_player(id) : Optional[Player] -Removes the specified player from the gacha game -create_random_banner(name,num_items,price) -> Optional[Banner] -Creates a random banner with the given name and number of items -remove_all_banners() : None -Removes all of the banners in the game -top_items(num_items) : List[Item] -Returns the top specified number of items in the game in terms of rarity -top_players(num_players) : List[Player] -Returns the top specified number of players in the game in terms of net worth

-

Creates an instance of a gacha controller

-

Parameters

-
-
items : List[Item]
-
the list of items that are in the item pool for the gacha
-
banners : List[Banner]
-
the list of banners that are available for the gacha
-
players : List[Player]
-
the list of players enrolled in the gacha
-
-
- -Expand source code - -
class Controller :
-    """A controller for an instance of a gacha game
-
-    Fields
-    ------
-    items : List[Item]
-        the list of items that are in the item pool for the gacha
-    banners : List[Banner]
-        the list of banners that are available for the gacha
-    players : List[Player]
-        the list of players enrolled in the gacha
-    
-    Methods
-    -------
-    find_item_by_name(item_name) : Optional[Item]
-        Returns the Item object with the given name or None if not found
-    find_banner_by_name(banner_name) : Optional[Banner]
-        Returns the Banner object with the given name or None if not found
-    find_player_by_name(player_name) : Optional[Banner]
-        Returns the Player object with the given name or None if not found
-    find_item_by_id(item_id) : Optional[Item]
-        Returns the Item object with the given id or None if not found
-    find_player_by_id(player_id) : Optional[Player]
-        Returns the Player object with the given id or None if not found
-    pull(player_id,banner_name) : Optional[Item]
-        Pulls and returns an item from the specified banner for the specified player
-    change_money_player(player_id,amount) : bool
-        Changes the specified player's money by the amount specified
-    add_new_item(name,id,rarity) : Optional[Item]
-        Adds a new item to the gacha game
-    add_new_banner(name,item_list_str,price) : Optional[Banner]
-        Adds a new banner to the gacha game
-    add_new_player(name,id,start_money,items_str) : Optional[Player]
-        Adds a new player to the gacha game
-    remove_item(id) : Optional[Item]
-        Removes the specified item from the gacha game
-    remove_banner(name) : Optional[Banner]
-        Removes the specified banner from the gacha game
-    remove_player(id) : Optional[Player]
-        Removes the specified player from the gacha game
-    create_random_banner(name,num_items,price) -> Optional[Banner]
-        Creates a random banner with the given name and number of items
-    remove_all_banners() : None
-        Removes all of the banners in the game
-    top_items(num_items) : List[Item]
-        Returns the top specified number of items in the game in terms of rarity
-    top_players(num_players) : List[Player]
-        Returns the top specified number of players in the game in terms of net worth
-    """
-
-    def __init__(self,items=[],banners=[],players=[]) -> None:
-        """Creates an instance of a gacha controller
-
-        Parameters
-        ----------
-        items : List[Item]
-            the list of items that are in the item pool for the gacha
-        banners : List[Banner]
-            the list of banners that are available for the gacha
-        players : List[Player]
-            the list of players enrolled in the gacha
-        """
-        self.items = items
-        self.banners = banners
-        self.players = players
-    
-    def find_item_by_name(self, item_name) -> Optional[Item]:
-        """Returns the Item object with the given name or None if not found
-
-        Parameters
-        ----------
-        item_name : str
-            the name of the item
-        
-        Returns
-        -------
-        Optional[Item]
-            the item object with the given name or None if not found 
-        """
-        items = [i for i in self.items if i.name == item_name]
-        if len(items) < 1 :
-            return None
-        return items[0]
-    
-    def find_banner_by_name(self, banner_name) -> Optional[Banner]:
-        """Returns the Banner object with the given name or None if not found
-
-        Parameters
-        ----------
-        banner_name : str
-            the name of the banner
-        
-        Returns
-        -------
-        Optional[Banner]
-            the banner object with the given name or None if not found 
-        """
-        banners = [i for i in self.banners if i.name == banner_name]
-        if len(banners) < 1 :
-            return None
-        return banners[0]
-
-    
-    def find_player_by_name(self,player_name) -> Optional[Player]:
-        """Returns the Player object with the given name or None if not found
-
-        Parameters
-        ----------
-        player_name : str
-            the name of the player
-        
-        Returns
-        -------
-        Optional[player]
-            the player object with the given name or None if not found 
-        """
-        players = [i for i in self.players if i.name == player_name]
-        if len(players) < 1 :
-            return None
-        return players[0]
-    
-    def find_item_by_id(self, item_id) -> Optional[Item]:
-        """Returns the Item object with the given id or None if not found
-
-        Parameters
-        ----------
-        item_id : str
-            the id of the item
-        
-        Returns
-        -------
-        Optional[Item]
-            the item object with the given id or None if not found 
-        """
-        items = [i for i in self.items if i.id == item_id]
-        if len(items) < 1 :
-            return None
-        return items[0]
-    
-    def find_player_by_id(self,player_id) -> Optional[Player]:
-        """Returns the Player object with the given id or None if not found
-
-        Parameters
-        ----------
-        player_id : str
-            the id of the player
-        
-        Returns
-        -------
-        Optional[player]
-            the player object with the given id or None if not found 
-        """
-        players = [i for i in self.players if i.id == player_id]
-        if len(players) < 1 :
-            return None
-        return players[0]
-
-    def pull(self,player_id,banner_name) -> Optional[Item] :
-        """Pulls and returns an item from the specified banner for the specified player
-
-        Parameters
-        ----------
-        player_id : str
-            the id of the selected player, must be valid
-        banner_name : str
-            the name of the selected player, must be valid
-
-        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
-        """
-        player = self.find_player_by_id(player_id)
-        if player == None :
-            raise PullError("Player not found")
-        banner = self.find_banner_by_name(banner_name)
-        if banner == None :
-            raise PullError("Banner not found")
-        if player.change_money(-1 * banner.price) :
-            item = banner.pull()
-            player.add_item(item)
-            return item
-        return None
-
-    def change_money_player(self,player_id,amount) -> bool :
-        """Changes the specified player's money by the amount specified
-
-        Parameters
-        ----------
-        player_name : str
-            the name of the player
-        amount : float
-            the amount to change the money by (positive for add, negative for subtract)
-
-        Returns
-        ------
-        bool
-            True if the amount was able to be added or removed from account (does not create 
-            negative money value), False otherwise
-        """
-        player = self.find_player_by_id(player_id)
-        if player == None :
-            return False
-        return player.change_money(amount)
-
-    def add_new_item(self,name,id,rarity) -> Optional[Item] :
-        """Adds a new item to the gacha game
-
-        Parameters
-        ----------
-        name : str
-            the name of the new item
-        description : str
-            the description of the new item
-        rarity : int
-            the rarity of the item
-
-        Returns
-        -------
-        Optional[Item]
-            the Item object representing the new item or None if the item already exists
-        """
-        item = self.find_item_by_id(id)
-        if item != None :
-            return None
-        new_item = Item(name,id,rarity)
-        self.items.append(new_item)
-        return new_item
-    
-    def add_new_banner(self,name,item_list_str,price,key=default_key) -> Optional[Banner] :
-        """Adds a new banner to the gacha game
-
-        Parameters
-        ----------
-        name : str
-            the name of the new banner
-        item_list_str : List[str]
-            the list of the ids of the items in the banner
-        price : float
-            the price of pulling from the banner
-        key : func
-            function that determines drop rate from rarity
-        
-        Returns
-        -------
-        Optional[Banner]
-            the Banner object representing the new banner or None if the banner already exists
-        """
-        banner = self.find_banner_by_name(name)
-        if banner != None :
-            return None
-        item_list = [self.find_item_by_id(i) for i in item_list_str]
-        new_banner = Banner(name,item_list,price,key)
-        self.banners.append(new_banner)
-        return Banner
-
-    def add_new_player(self,name,id,start_money,items_str=[]) -> Optional[Player] :
-        """Adds a new player to the gacha game
-
-        Parameters
-        ----------
-        name : str
-            the name of the new player
-        id : str
-            the id of the new player
-        start_money : float
-            the amount of money the new player will start with
-        items_str : List[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 the player already exists
-        """
-        player = self.find_player_by_id(id)
-        if player != None :
-            return None
-        items_list = [self.find_item_by_id(i) for i in items_str]
-        new_player = Player(name,id,items_list,start_money)
-        self.players.append(new_player)
-        return new_player
-
-    def remove_item(self,item_id) -> Optional[Item]:
-        """Removes the specified item from the gacha game
-
-        Parameters
-        ----------
-        item_id : str
-            the name of the item to remove
-
-        Returns
-        -------
-        Optional[Item]
-            the removed item or None if item does not exist
-        """
-        for item in self.items :
-            if item.id == item_id :
-                self.items.remove(item)
-                return item
-        return None
-
-    
-    def remove_banner(self,name) -> Optional[Banner] :
-        """Removes the specified banner from the gacha game
-
-        Parameters
-        ----------
-        name : str
-            the name of the banner to remove
-
-        Returns
-        -------
-        Optional[Banner]
-            the removed banner or None if banner does not exist
-        """
-        for banner in self.banners :
-            if banner.name == name :
-                self.banner.remove(banner)
-                return banner
-        return None
-    
-    def remove_player(self,player_id) -> Optional[Player] :
-        """Removes the specified player from the gacha game
-
-        Parameters
-        ----------
-        player_id : str
-            the id of the player to remove
-
-        Returns
-        -------
-        Optional[Player]
-            the removed player or None if player does not exist
-        """
-        for player in self.players :
-            if player.id == player_id :
-                self.players.remove(player)
-                return player
-        return None
-    
-    def create_random_banner(self,name,num_items,price=-1,key=default_key) -> Optional[Banner] :
-        """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
-        ----------
-        name : str
-            the name of the random banner
-        num_items : int
-            the number of items in the banner
-        price : float
-            the price of the banner
-        key : func
-            function that determines drop rate from rarity
-        
-        Returns
-        -------
-        Optional[Banner]
-            the banner created or None if a banner with the name specified already exists
-        """
-        item_list = random.choices(self.items,k=num_items)
-        item_list_str = [item.id for item in item_list]
-        if price < 0 :
-            price = 0
-            for item in item_list :
-                price += item.rarity
-            price /= len(item_list)
-        return self.add_new_banner(name,item_list_str,price)
-    
-    def remove_all_banners(self) -> None:
-        """Removes all of the banners in the game
-
-        Returns
-        -------
-        None
-        """
-        self.banners = []
-
-    def top_items(self,num_items) -> List[Item] :
-        """Returns the top specified number of items in the game in terms of rarity
-
-        Parameters
-        ----------
-        num_items : int
-            the number of items to return
-        
-        Returns
-        -------
-        List[Item]
-            the list of top items
-        """
-        sort_list = sorted(self.items,key=sort_item_key,reverse=True)
-        return sort_list[:num_items-1]
-
-    def top_players(self,num_players) -> List[Player] :
-        """Returns the top specified number of players in the game in terms of net worth
-
-        Parameters
-        ----------
-        num_players : int
-            the number of players to return
-        
-        Returns
-        -------
-        List[Player]
-            the list of top players
-        """
-        sort_list = sorted(self.players,key=sort_player_key,reverse=True)
-        return sort_list[:num_players-1]
-
-

Methods

-
-
-def add_new_banner(self, name, item_list_str, price, key=<function default_key>) ‑> Optional[Banner] -
-
-

Adds a new banner to the gacha game

-

Parameters

-
-
name : str
-
the name of the new banner
-
item_list_str : List[str]
-
the list of the ids of the items in the banner
-
price : float
-
the price of pulling from the banner
-
key : func
-
function that determines drop rate from rarity
-
-

Returns

-
-
Optional[Banner]
-
the Banner object representing the new banner or None if the banner already exists
-
-
- -Expand source code - -
def add_new_banner(self,name,item_list_str,price,key=default_key) -> Optional[Banner] :
-    """Adds a new banner to the gacha game
-
-    Parameters
-    ----------
-    name : str
-        the name of the new banner
-    item_list_str : List[str]
-        the list of the ids of the items in the banner
-    price : float
-        the price of pulling from the banner
-    key : func
-        function that determines drop rate from rarity
-    
-    Returns
-    -------
-    Optional[Banner]
-        the Banner object representing the new banner or None if the banner already exists
-    """
-    banner = self.find_banner_by_name(name)
-    if banner != None :
-        return None
-    item_list = [self.find_item_by_id(i) for i in item_list_str]
-    new_banner = Banner(name,item_list,price,key)
-    self.banners.append(new_banner)
-    return Banner
-
-
-
-def add_new_item(self, name, id, rarity) ‑> Optional[Item] -
-
-

Adds a new item to the gacha game

-

Parameters

-
-
name : str
-
the name of the new item
-
description : str
-
the description of the new item
-
rarity : int
-
the rarity of the item
-
-

Returns

-
-
Optional[Item]
-
the Item object representing the new item or None if the item already exists
-
-
- -Expand source code - -
def add_new_item(self,name,id,rarity) -> Optional[Item] :
-    """Adds a new item to the gacha game
-
-    Parameters
-    ----------
-    name : str
-        the name of the new item
-    description : str
-        the description of the new item
-    rarity : int
-        the rarity of the item
-
-    Returns
-    -------
-    Optional[Item]
-        the Item object representing the new item or None if the item already exists
-    """
-    item = self.find_item_by_id(id)
-    if item != None :
-        return None
-    new_item = Item(name,id,rarity)
-    self.items.append(new_item)
-    return new_item
-
-
-
-def add_new_player(self, name, id, start_money, items_str=[]) ‑> Optional[Player] -
-
-

Adds a new player to the gacha game

-

Parameters

-
-
name : str
-
the name of the new player
-
id : str
-
the id of the new player
-
start_money : float
-
the amount of money the new player will start with
-
items_str : List[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 the player already exists
-
-
- -Expand source code - -
def add_new_player(self,name,id,start_money,items_str=[]) -> Optional[Player] :
-    """Adds a new player to the gacha game
-
-    Parameters
-    ----------
-    name : str
-        the name of the new player
-    id : str
-        the id of the new player
-    start_money : float
-        the amount of money the new player will start with
-    items_str : List[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 the player already exists
-    """
-    player = self.find_player_by_id(id)
-    if player != None :
-        return None
-    items_list = [self.find_item_by_id(i) for i in items_str]
-    new_player = Player(name,id,items_list,start_money)
-    self.players.append(new_player)
-    return new_player
-
-
-
-def change_money_player(self, player_id, amount) ‑> bool -
-
-

Changes the specified player's money by the amount specified

-

Parameters

-
-
player_name : str
-
the name of the player
-
amount : float
-
the amount to change the money by (positive for add, negative for subtract)
-
-

Returns

-
-
bool
-
True if the amount was able to be added or removed from account (does not create -negative money value), False otherwise
-
-
- -Expand source code - -
def change_money_player(self,player_id,amount) -> bool :
-    """Changes the specified player's money by the amount specified
-
-    Parameters
-    ----------
-    player_name : str
-        the name of the player
-    amount : float
-        the amount to change the money by (positive for add, negative for subtract)
-
-    Returns
-    ------
-    bool
-        True if the amount was able to be added or removed from account (does not create 
-        negative money value), False otherwise
-    """
-    player = self.find_player_by_id(player_id)
-    if player == None :
-        return False
-    return player.change_money(amount)
-
-
-
-def create_random_banner(self, name, num_items, price=-1, key=<function default_key>) ‑> Optional[Banner] -
-
-

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

-
-
name : str
-
the name of the random banner
-
num_items : int
-
the number of items in the banner
-
price : float
-
the price of the banner
-
key : func
-
function that determines drop rate from rarity
-
-

Returns

-
-
Optional[Banner]
-
the banner created or None if a banner with the name specified already exists
-
-
- -Expand source code - -
def create_random_banner(self,name,num_items,price=-1,key=default_key) -> Optional[Banner] :
-    """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
-    ----------
-    name : str
-        the name of the random banner
-    num_items : int
-        the number of items in the banner
-    price : float
-        the price of the banner
-    key : func
-        function that determines drop rate from rarity
-    
-    Returns
-    -------
-    Optional[Banner]
-        the banner created or None if a banner with the name specified already exists
-    """
-    item_list = random.choices(self.items,k=num_items)
-    item_list_str = [item.id for item in item_list]
-    if price < 0 :
-        price = 0
-        for item in item_list :
-            price += item.rarity
-        price /= len(item_list)
-    return self.add_new_banner(name,item_list_str,price)
-
-
-
-def find_banner_by_name(self, banner_name) ‑> Optional[Banner] -
-
-

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

-

Parameters

-
-
banner_name : str
-
the name of the banner
-
-

Returns

-
-
Optional[Banner]
-
the banner object with the given name or None if not found
-
-
- -Expand source code - -
def find_banner_by_name(self, banner_name) -> Optional[Banner]:
-    """Returns the Banner object with the given name or None if not found
-
-    Parameters
-    ----------
-    banner_name : str
-        the name of the banner
-    
-    Returns
-    -------
-    Optional[Banner]
-        the banner object with the given name or None if not found 
-    """
-    banners = [i for i in self.banners if i.name == banner_name]
-    if len(banners) < 1 :
-        return None
-    return banners[0]
-
-
-
-def find_item_by_id(self, item_id) ‑> Optional[Item] -
-
-

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

-

Parameters

-
-
item_id : str
-
the id of the item
-
-

Returns

-
-
Optional[Item]
-
the item object with the given id or None if not found
-
-
- -Expand source code - -
def find_item_by_id(self, item_id) -> Optional[Item]:
-    """Returns the Item object with the given id or None if not found
-
-    Parameters
-    ----------
-    item_id : str
-        the id of the item
-    
-    Returns
-    -------
-    Optional[Item]
-        the item object with the given id or None if not found 
-    """
-    items = [i for i in self.items if i.id == item_id]
-    if len(items) < 1 :
-        return None
-    return items[0]
-
-
-
-def find_item_by_name(self, item_name) ‑> Optional[Item] -
-
-

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

-

Parameters

-
-
item_name : str
-
the name of the item
-
-

Returns

-
-
Optional[Item]
-
the item object with the given name or None if not found
-
-
- -Expand source code - -
def find_item_by_name(self, item_name) -> Optional[Item]:
-    """Returns the Item object with the given name or None if not found
-
-    Parameters
-    ----------
-    item_name : str
-        the name of the item
-    
-    Returns
-    -------
-    Optional[Item]
-        the item object with the given name or None if not found 
-    """
-    items = [i for i in self.items if i.name == item_name]
-    if len(items) < 1 :
-        return None
-    return items[0]
-
-
-
-def find_player_by_id(self, player_id) ‑> Optional[Player] -
-
-

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

-

Parameters

-
-
player_id : str
-
the id of the player
-
-

Returns

-
-
Optional[player]
-
the player object with the given id or None if not found
-
-
- -Expand source code - -
def find_player_by_id(self,player_id) -> Optional[Player]:
-    """Returns the Player object with the given id or None if not found
-
-    Parameters
-    ----------
-    player_id : str
-        the id of the player
-    
-    Returns
-    -------
-    Optional[player]
-        the player object with the given id or None if not found 
-    """
-    players = [i for i in self.players if i.id == player_id]
-    if len(players) < 1 :
-        return None
-    return players[0]
-
-
-
-def find_player_by_name(self, player_name) ‑> Optional[Player] -
-
-

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

-

Parameters

-
-
player_name : str
-
the name of the player
-
-

Returns

-
-
Optional[player]
-
the player object with the given name or None if not found
-
-
- -Expand source code - -
def find_player_by_name(self,player_name) -> Optional[Player]:
-    """Returns the Player object with the given name or None if not found
-
-    Parameters
-    ----------
-    player_name : str
-        the name of the player
-    
-    Returns
-    -------
-    Optional[player]
-        the player object with the given name or None if not found 
-    """
-    players = [i for i in self.players if i.name == player_name]
-    if len(players) < 1 :
-        return None
-    return players[0]
-
-
-
-def pull(self, player_id, banner_name) ‑> Optional[Item] -
-
-

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

-

Parameters

-
-
player_id : str
-
the id of the selected player, must be valid
-
banner_name : str
-
the name of the selected player, must be valid
-
-

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
-
 
-
-
- -Expand source code - -
def pull(self,player_id,banner_name) -> Optional[Item] :
-    """Pulls and returns an item from the specified banner for the specified player
-
-    Parameters
-    ----------
-    player_id : str
-        the id of the selected player, must be valid
-    banner_name : str
-        the name of the selected player, must be valid
-
-    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
-    """
-    player = self.find_player_by_id(player_id)
-    if player == None :
-        raise PullError("Player not found")
-    banner = self.find_banner_by_name(banner_name)
-    if banner == None :
-        raise PullError("Banner not found")
-    if player.change_money(-1 * banner.price) :
-        item = banner.pull()
-        player.add_item(item)
-        return item
-    return None
-
-
-
-def remove_all_banners(self) ‑> NoneType -
-
-

Removes all of the banners in the game

-

Returns

-
-
None
-
 
-
-
- -Expand source code - -
def remove_all_banners(self) -> None:
-    """Removes all of the banners in the game
-
-    Returns
-    -------
-    None
-    """
-    self.banners = []
-
-
-
-def remove_banner(self, name) ‑> Optional[Banner] -
-
-

Removes the specified banner from the gacha game

-

Parameters

-
-
name : str
-
the name of the banner to remove
-
-

Returns

-
-
Optional[Banner]
-
the removed banner or None if banner does not exist
-
-
- -Expand source code - -
def remove_banner(self,name) -> Optional[Banner] :
-    """Removes the specified banner from the gacha game
-
-    Parameters
-    ----------
-    name : str
-        the name of the banner to remove
-
-    Returns
-    -------
-    Optional[Banner]
-        the removed banner or None if banner does not exist
-    """
-    for banner in self.banners :
-        if banner.name == name :
-            self.banner.remove(banner)
-            return banner
-    return None
-
-
-
-def remove_item(self, item_id) ‑> Optional[Item] -
-
-

Removes the specified item from the gacha game

-

Parameters

-
-
item_id : str
-
the name of the item to remove
-
-

Returns

-
-
Optional[Item]
-
the removed item or None if item does not exist
-
-
- -Expand source code - -
def remove_item(self,item_id) -> Optional[Item]:
-    """Removes the specified item from the gacha game
-
-    Parameters
-    ----------
-    item_id : str
-        the name of the item to remove
-
-    Returns
-    -------
-    Optional[Item]
-        the removed item or None if item does not exist
-    """
-    for item in self.items :
-        if item.id == item_id :
-            self.items.remove(item)
-            return item
-    return None
-
-
-
-def remove_player(self, player_id) ‑> Optional[Player] -
-
-

Removes the specified player from the gacha game

-

Parameters

-
-
player_id : str
-
the id of the player to remove
-
-

Returns

-
-
Optional[Player]
-
the removed player or None if player does not exist
-
-
- -Expand source code - -
def remove_player(self,player_id) -> Optional[Player] :
-    """Removes the specified player from the gacha game
-
-    Parameters
-    ----------
-    player_id : str
-        the id of the player to remove
-
-    Returns
-    -------
-    Optional[Player]
-        the removed player or None if player does not exist
-    """
-    for player in self.players :
-        if player.id == player_id :
-            self.players.remove(player)
-            return player
-    return None
-
-
-
-def top_items(self, num_items) ‑> List[Item] -
-
-

Returns the top specified number of items in the game in terms of rarity

-

Parameters

-
-
num_items : int
-
the number of items to return
-
-

Returns

-
-
List[Item]
-
the list of top items
-
-
- -Expand source code - -
def top_items(self,num_items) -> List[Item] :
-    """Returns the top specified number of items in the game in terms of rarity
-
-    Parameters
-    ----------
-    num_items : int
-        the number of items to return
-    
-    Returns
-    -------
-    List[Item]
-        the list of top items
-    """
-    sort_list = sorted(self.items,key=sort_item_key,reverse=True)
-    return sort_list[:num_items-1]
-
-
-
-def top_players(self, num_players) ‑> List[Player] -
-
-

Returns the top specified number of players in the game in terms of net worth

-

Parameters

-
-
num_players : int
-
the number of players to return
-
-

Returns

-
-
List[Player]
-
the list of top players
-
-
- -Expand source code - -
def top_players(self,num_players) -> List[Player] :
-    """Returns the top specified number of players in the game in terms of net worth
-
-    Parameters
-    ----------
-    num_players : int
-        the number of players to return
-    
-    Returns
-    -------
-    List[Player]
-        the list of top players
-    """
-    sort_list = sorted(self.players,key=sort_player_key,reverse=True)
-    return sort_list[:num_players-1]
-
-
-
-
-
-class PullError -(*args, **kwargs) -
-
-

An exception thrown when pulling from a banner

-
- -Expand source code - -
class PullError(Exception) :
-    """An exception thrown when pulling from a banner
-    """
-    pass
-
-

Ancestors

-
    -
  • builtins.Exception
  • -
  • builtins.BaseException
  • -
-
-
-
-
- -
- - - \ No newline at end of file diff --git a/html/gachapy/index.html b/html/gachapy/index.html deleted file mode 100644 index b5a979a..0000000 --- a/html/gachapy/index.html +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - -gachapy API documentation - - - - - - - - - - - -
-
-
-

Package gachapy

-
-
-
-
-

Sub-modules

-
-
gachapy.controller
-
-

The controller used for all high level management of the gacha game …

-
-
gachapy.loader
-
-

Collection of loader functions for loading gachapy objects from json files …

-
-
gachapy.objects
-
-

Objects used for low level management and data storage of the gacha game …

-
-
-
-
-
-
-
-
-
-
- -
- - - \ No newline at end of file diff --git a/html/gachapy/loader.html b/html/gachapy/loader.html deleted file mode 100644 index cdb551f..0000000 --- a/html/gachapy/loader.html +++ /dev/null @@ -1,447 +0,0 @@ - - - - - - -gachapy.loader API documentation - - - - - - - - - - - -
-
-
-

Module gachapy.loader

-
-
-

Collection of loader functions for loading gachapy objects from json files

-

Functions

-

load_controller(items_filename,banners_filename,players_filename) : Controller -Creates a Controller object from the specified json files -save_controller(controller,items_filename,banners_filename,players_filename) : None -Saves the controller in json format into the specified files -load_items_from_file(filename,controller) : List[Optional[Item]] -Load items into controller from the specified json file -load_banners_from_file(filename,controller) : List[Optional[Banner]] -Load banners into controller from the specified json file -load_players_from_file(filename,controller) : List[Optional[Player]] -Load players into controller from the specified json file

-
- -Expand source code - -
"""Collection of loader functions for loading gachapy objects from json files
-
-Functions
----------
-load_controller(items_filename,banners_filename,players_filename) : Controller
-    Creates a Controller object from the specified json files
-save_controller(controller,items_filename,banners_filename,players_filename) : None
-    Saves the controller in json format into the specified files
-load_items_from_file(filename,controller) : List[Optional[Item]]
-    Load items into controller from the specified json file
-load_banners_from_file(filename,controller) : List[Optional[Banner]]
-    Load banners into controller from the specified json file
-load_players_from_file(filename,controller) : List[Optional[Player]]
-    Load players into controller from the specified json file
-"""
-
-from gachapy.objects import *
-from gachapy.controller import *
-import json
-
-def load_controller(items_filename,banners_filename,players_filename) -> Controller :
-    """Creates a Controller object from the specified json files
-
-    Parameters
-    ----------
-    items_filename : str
-        the path of the items json file
-    banners_filename : str
-        the path of the banners json file
-    players_filename : str
-        the path of the players json file
-    
-    Returns
-    -------
-    Controller
-        the controller loaded from the specified files
-    """
-    controller = Controller()
-    load_items_from_file(items_filename,controller)
-    load_banners_from_file(banners_filename,controller)
-    load_players_from_file(players_filename,controller)
-    return controller
-
-def save_controller(controller,items_filename,banners_filename,players_filename) -> None :
-    """Saves the controller in json format into the specified files
-
-    Parameters
-    ----------
-    controller : Controller 
-        the controller to save into files
-    items_filename : str
-        the path of the items json file
-    banners_filename : str
-        the path of the banners json file
-    players_filename : str
-        the path of the players json file
-
-    Returns
-    -------
-    None
-    """
-    items_list = controller.items
-    item_dict = {"items": [{"name":i.name,"id":i.id,"rarity":i.rarity} for i in items_list]}
-    with open(items_filename, "w") as f:
-        json.dump(item_dict,f)
-    banners_list = controller.banners
-    banner_dict = {"banners": [{"name":i.name,"items":[{"id":j.id} for j in i.item_list],"price":i.price} for i in banners_list]}
-    with open(banners_filename, "w") as f:
-        json.dump(banner_dict,f)
-    players_list = controller.players
-    player_dict = {"players": [{"name":i.name,"id":i.id,"money":i.money,"items":[{"id":j.id} for j in i.items]} for i in players_list]}
-    with open(players_filename, "w") as f:
-        json.dump(player_dict,f)
-
-def load_items_from_file(filename,controller) -> List[Optional[Item]] :
-    """Load items into controller from the specified json file
-
-    Parameters
-    ----------
-    filename : str
-        the path of the json file to load
-    controller : Controller
-        the controller to load the items into
-    
-    Returns
-    -------
-    List[Optional[Item]]
-        the list of items loaded, elements are None if they already exist in controller
-    """
-    with open(filename) as f :
-        j = json.load(f)
-        items_str_list = j["items"]
-        return [controller.add_new_item(i["name"],i["id"],i["rarity"]) for i in items_str_list]
-
-def load_banners_from_file(filename,controller) -> List[Optional[Banner]] :
-    """Load banners into controller from the specified json file
-
-    Parameters
-    ----------
-    filename : str
-        the path of the json file to load
-    controller : Controller
-        the controller to load the banners into
-
-    Returns
-    -------
-    List[Optional[Banner]]
-        the list of banners loaded, elements are None if they already exist in controller
-    """
-    with open(filename) as f :
-        j = json.load(f)
-        banner_str_list = j["banners"]
-        return [controller.add_new_banner(i["name"],[j["id"] for j in i["items"]],i["price"]) for i in banner_str_list]
-
-def load_players_from_file(filename,controller) -> List[Optional[Player]] :
-    """Load players into controller from the specified json file
-
-    Parameters
-    ----------
-    filename : str
-        the path of the json file to load
-    controller : Controller
-        the controller to load the players into
-
-    Returns
-    -------
-    List[Optional[Player]]
-        the list of players loaded, elements are None if they already exist in controller
-    """
-    with open(filename) as f :
-        j = json.load(f)
-        player_str_list = j["players"]
-        return [controller.add_new_player(i["name"],i["id"],i["money"],[j["id"] for j in i["items"]]) for i in player_str_list]
-
-
-
-
-
-
-
-

Functions

-
-
-def load_banners_from_file(filename, controller) ‑> List[Optional[Banner]] -
-
-

Load banners into controller from the specified json file

-

Parameters

-
-
filename : str
-
the path of the json file to load
-
controller : Controller
-
the controller to load the banners into
-
-

Returns

-
-
List[Optional[Banner]]
-
the list of banners loaded, elements are None if they already exist in controller
-
-
- -Expand source code - -
def load_banners_from_file(filename,controller) -> List[Optional[Banner]] :
-    """Load banners into controller from the specified json file
-
-    Parameters
-    ----------
-    filename : str
-        the path of the json file to load
-    controller : Controller
-        the controller to load the banners into
-
-    Returns
-    -------
-    List[Optional[Banner]]
-        the list of banners loaded, elements are None if they already exist in controller
-    """
-    with open(filename) as f :
-        j = json.load(f)
-        banner_str_list = j["banners"]
-        return [controller.add_new_banner(i["name"],[j["id"] for j in i["items"]],i["price"]) for i in banner_str_list]
-
-
-
-def load_controller(items_filename, banners_filename, players_filename) ‑> Controller -
-
-

Creates a Controller object from the specified json files

-

Parameters

-
-
items_filename : str
-
the path of the items json file
-
banners_filename : str
-
the path of the banners json file
-
players_filename : str
-
the path of the players json file
-
-

Returns

-
-
Controller
-
the controller loaded from the specified files
-
-
- -Expand source code - -
def load_controller(items_filename,banners_filename,players_filename) -> Controller :
-    """Creates a Controller object from the specified json files
-
-    Parameters
-    ----------
-    items_filename : str
-        the path of the items json file
-    banners_filename : str
-        the path of the banners json file
-    players_filename : str
-        the path of the players json file
-    
-    Returns
-    -------
-    Controller
-        the controller loaded from the specified files
-    """
-    controller = Controller()
-    load_items_from_file(items_filename,controller)
-    load_banners_from_file(banners_filename,controller)
-    load_players_from_file(players_filename,controller)
-    return controller
-
-
-
-def load_items_from_file(filename, controller) ‑> List[Optional[Item]] -
-
-

Load items into controller from the specified json file

-

Parameters

-
-
filename : str
-
the path of the json file to load
-
controller : Controller
-
the controller to load the items into
-
-

Returns

-
-
List[Optional[Item]]
-
the list of items loaded, elements are None if they already exist in controller
-
-
- -Expand source code - -
def load_items_from_file(filename,controller) -> List[Optional[Item]] :
-    """Load items into controller from the specified json file
-
-    Parameters
-    ----------
-    filename : str
-        the path of the json file to load
-    controller : Controller
-        the controller to load the items into
-    
-    Returns
-    -------
-    List[Optional[Item]]
-        the list of items loaded, elements are None if they already exist in controller
-    """
-    with open(filename) as f :
-        j = json.load(f)
-        items_str_list = j["items"]
-        return [controller.add_new_item(i["name"],i["id"],i["rarity"]) for i in items_str_list]
-
-
-
-def load_players_from_file(filename, controller) ‑> List[Optional[Player]] -
-
-

Load players into controller from the specified json file

-

Parameters

-
-
filename : str
-
the path of the json file to load
-
controller : Controller
-
the controller to load the players into
-
-

Returns

-
-
List[Optional[Player]]
-
the list of players loaded, elements are None if they already exist in controller
-
-
- -Expand source code - -
def load_players_from_file(filename,controller) -> List[Optional[Player]] :
-    """Load players into controller from the specified json file
-
-    Parameters
-    ----------
-    filename : str
-        the path of the json file to load
-    controller : Controller
-        the controller to load the players into
-
-    Returns
-    -------
-    List[Optional[Player]]
-        the list of players loaded, elements are None if they already exist in controller
-    """
-    with open(filename) as f :
-        j = json.load(f)
-        player_str_list = j["players"]
-        return [controller.add_new_player(i["name"],i["id"],i["money"],[j["id"] for j in i["items"]]) for i in player_str_list]
-
-
-
-def save_controller(controller, items_filename, banners_filename, players_filename) ‑> NoneType -
-
-

Saves the controller in json format into the specified files

-

Parameters

-
-
controller : Controller
-
the controller to save into files
-
items_filename : str
-
the path of the items json file
-
banners_filename : str
-
the path of the banners json file
-
players_filename : str
-
the path of the players json file
-
-

Returns

-
-
None
-
 
-
-
- -Expand source code - -
def save_controller(controller,items_filename,banners_filename,players_filename) -> None :
-    """Saves the controller in json format into the specified files
-
-    Parameters
-    ----------
-    controller : Controller 
-        the controller to save into files
-    items_filename : str
-        the path of the items json file
-    banners_filename : str
-        the path of the banners json file
-    players_filename : str
-        the path of the players json file
-
-    Returns
-    -------
-    None
-    """
-    items_list = controller.items
-    item_dict = {"items": [{"name":i.name,"id":i.id,"rarity":i.rarity} for i in items_list]}
-    with open(items_filename, "w") as f:
-        json.dump(item_dict,f)
-    banners_list = controller.banners
-    banner_dict = {"banners": [{"name":i.name,"items":[{"id":j.id} for j in i.item_list],"price":i.price} for i in banners_list]}
-    with open(banners_filename, "w") as f:
-        json.dump(banner_dict,f)
-    players_list = controller.players
-    player_dict = {"players": [{"name":i.name,"id":i.id,"money":i.money,"items":[{"id":j.id} for j in i.items]} for i in players_list]}
-    with open(players_filename, "w") as f:
-        json.dump(player_dict,f)
-
-
-
-
-
-
-
- -
- - - \ No newline at end of file diff --git a/html/gachapy/objects.html b/html/gachapy/objects.html deleted file mode 100644 index cb6a974..0000000 --- a/html/gachapy/objects.html +++ /dev/null @@ -1,1001 +0,0 @@ - - - - - - -gachapy.objects API documentation - - - - - - - - - - - -
-
-
-

Module gachapy.objects

-
-
-

Objects used for low level management and data storage of the gacha game

-

Classes

-

Item -A representation of an item in the gacha game -Banner -A representation of a banner in the gacha game -Player -A representation of a player in the gacha game

-

Functions

-

get_random_weights(items) : List[float] -Returns the random weights of the items for the random function -sort_item_key(item) : int -The key used to sort items in a list of items -player_str_net_worth(player) : str -The string representation of a player and their net worth

-
- -Expand source code - -
"""Objects used for low level management and data storage of the gacha game
-
-Classes
--------
-Item
-    A representation of an item in the gacha game
-Banner
-    A representation of a banner in the gacha game
-Player
-    A representation of a player in the gacha game
-
-Functions
----------
-get_random_weights(items) : List[float]
-    Returns the random weights of the items for the random function
-sort_item_key(item) : int
-    The key used to sort items in a list of items
-player_str_net_worth(player) : str
-    The string representation of a player and their net worth
-"""
-import random
-from typing import List
-
-class Item :
-    """A representation of an item in the gacha game
-
-    Fields
-    ------
-    name : string
-        name of the item
-    id : string
-        description of the item
-        Invariant: must be unique
-    id : int
-        rarity of the item where the higher the numer, the higher the rarity
-
-    Methods
-    -------
-    Item : Item
-        creates an item object
-    """
-
-    def __init__(self, name, id, rarity) -> None :
-        """Creates an Item object
-
-        Parameters
-        name : str
-            name of the item
-        id : str
-            id of the item
-        rarity : int
-            rarity of the item where the higher the numer, the higher the rarity
-        """
-        self.name = name
-        self.id = id
-        self.rarity = rarity
-    
-    def __str__(self) -> str :
-        """Returns the string representation of this Item object
-
-        Returns
-        -------
-        str
-            String representation of this object
-        """
-        return self.name + " (Rarity: " + str(self.rarity) + ")"
-
-def get_random_weights(items,key) -> List[float] :
-    """Returns the random weights of the items for the random function
-
-    Parameters
-    ----------
-    items : List[Item]
-        list of items to find weights of
-    key : func
-        function that determines drop rate from rarity
-
-    Returns
-    -------
-    List[float]
-        the list of weights of the items
-    """
-    weights = []
-    for i in range(len(items)) :
-        weights.append(key(items[i].rarity))
-    return weights
-
-
-class Banner :
-    """A representation of a banner in the gacha game
-
-    Fields
-    ------
-    name : string
-        name of the banner
-    item_list : List[Item]
-        the list of items in the banner 
-    price : float
-        the price of pulling from the banner
-    key : func
-        function that determines drop rate from rarity
-    weights : List[float]
-        list of drop weights for items
-        Invariant: weights[i] corresponds to item_list[i]
-
-    Methods
-    -------
-    add_item(item) : None
-        Adds an item to the banner
-    pull() : Item
-        Returns a random item out of a banner randomized by weight
-    """
-
-    def __init__(self, name, item_list, price, key) -> None :
-        """Creates a Banner object
-
-        Parameters
-        ----------
-        name : str
-            name of the banner
-            Invariant: must be unique
-        item_list : List[Item]
-            the list of items in the banner
-            Invariant: all items must be unique
-        weights : List[float]
-            the list of drop weights
-            Invariant: weights[i] is the drop weight for item_list[i]
-        price : float
-            the price of pulling from the banner
-        key : func
-            function that determines drop rate from rarity
-        """
-        self.name = name
-        self.item_list = item_list
-        self.key = key
-        self.weights = get_random_weights(item_list,key)
-        self.price = price
-
-    def add_item(self, item) -> None:
-        """Adds an item to the banner
-
-        Parameters
-        ----------
-        item : Item
-            item to add to the banner
-        
-        Returns
-        -------
-            None
-        """
-        self.item_list.append(item)
-        self.weights = get_random_weights(self.item_list)
-
-    def pull(self) -> Item:
-        """Returns a random item out of a banner randomized by weight
-
-        Returns
-        -------
-        Item
-            the random item from the pull
-        """
-        return random.choices(self.item_list, weights=self.weights, k=1)[0]
-
-    def __str__(self) -> str :
-        """Returns the string representation of this Banner object
-
-        Returns
-        -------
-        str
-            String representation of this object
-        """
-        return self.name + "\nPrice: " + str(self.price) + "\nItems:\n" + "\n".join([str(elem) for elem in self.item_list])
-
-class Player :
-    """A representation of a player in the gacha game
-
-    Fields
-    ------
-    name : str
-        the name of the player
-    id : str
-        the id of the player
-        Invariant: must be unique
-    items : List[Item]
-        the list of items that the player owns
-    money : float
-        the amount of money that the player owns
-    """
-
-    def __init__(self, name, id, items, money) -> None:
-        """Creates a Player object
-
-        Parameters
-        ----------
-        name : str
-            the name of the player
-        id : str
-            the id of the player
-        items : List[Item]
-            the list of items that the player owns
-        money : float
-            the amount of money that the player owns
-        """
-        self.name = name
-        self.id = id
-        self.items = items
-        self.money = money
-    
-    def add_item(self,item) -> None:
-        """Adds an item to the player's inventory
-
-        Parameters
-        ----------
-        item : Item
-            item to add to player inventory
-
-        Returns
-        -------
-        None
-        """
-        self.items.append(item)
-
-    def change_money(self,amount) -> bool:
-        """Adds or removes money from player
-
-        Parameters
-        ----------
-        amount : float
-            the ammount to add or remove (positive if add, negative if remove)
-
-        Returns
-        -------
-        bool
-            True if the amount was able to be added or removed from account (does not
-            create a negative money value), False otherwise
-        """
-        if (amount < 0 and self.money - amount < 0) :
-            return False
-        self.money += amount
-        return True
-
-    def get_net_worth(self) -> float :
-        """Returns the net worth of the player
-
-        Returns
-        -------
-        float
-            the net worth of the player
-        """
-        return sum([i.rarity for i in self.items])
-    
-    def __str__(self) -> str:
-        """Returns the string representation of this Player object
-
-        Returns
-        -------
-        str
-            string representation of this object
-        """
-        return self.name + "\n\nMoney: " + str(self.money) + "\n\nNet worth: " + str(self.get_net_worth()) + "\n\nTop 10 items:\n" + "\n".join([str(elem) for elem in sorted(self.items,key=sort_item_key,reverse=True)[:10]])
-
-def sort_item_key(item) -> int:
-    """The key used to sort items in a list of items
-
-    Parameters
-    ----------
-    item : Item
-        the item to extract the key from
-    
-    Returns
-    -------
-    int
-        the key of the item
-    """
-    return item.rarity
-
-def player_str_net_worth(player) -> str :
-    """The string representation of a player and their net worth
-
-    Parameters
-    ----------
-    player : Player
-        the player
-    
-    Returns
-    -------
-    str
-        the string representation of a player and their net work
-    """
-    return player.name + " (Net worth " + str(player.get_net_worth()) + ")"
-
-
-
-
-
-
-
-

Functions

-
-
-def get_random_weights(items, key) ‑> List[float] -
-
-

Returns the random weights of the items for the random function

-

Parameters

-
-
items : List[Item]
-
list of items to find weights of
-
key : func
-
function that determines drop rate from rarity
-
-

Returns

-
-
List[float]
-
the list of weights of the items
-
-
- -Expand source code - -
def get_random_weights(items,key) -> List[float] :
-    """Returns the random weights of the items for the random function
-
-    Parameters
-    ----------
-    items : List[Item]
-        list of items to find weights of
-    key : func
-        function that determines drop rate from rarity
-
-    Returns
-    -------
-    List[float]
-        the list of weights of the items
-    """
-    weights = []
-    for i in range(len(items)) :
-        weights.append(key(items[i].rarity))
-    return weights
-
-
-
-def player_str_net_worth(player) ‑> str -
-
-

The string representation of a player and their net worth

-

Parameters

-
-
player : Player
-
the player
-
-

Returns

-
-
str
-
the string representation of a player and their net work
-
-
- -Expand source code - -
def player_str_net_worth(player) -> str :
-    """The string representation of a player and their net worth
-
-    Parameters
-    ----------
-    player : Player
-        the player
-    
-    Returns
-    -------
-    str
-        the string representation of a player and their net work
-    """
-    return player.name + " (Net worth " + str(player.get_net_worth()) + ")"
-
-
-
-def sort_item_key(item) ‑> int -
-
-

The key used to sort items in a list of items

-

Parameters

-
-
item : Item
-
the item to extract the key from
-
-

Returns

-
-
int
-
the key of the item
-
-
- -Expand source code - -
def sort_item_key(item) -> int:
-    """The key used to sort items in a list of items
-
-    Parameters
-    ----------
-    item : Item
-        the item to extract the key from
-    
-    Returns
-    -------
-    int
-        the key of the item
-    """
-    return item.rarity
-
-
-
-
-
-

Classes

-
-
-class Banner -(name, item_list, price, key) -
-
-

A representation of a banner in the gacha game

-

Fields

-

name : string -name of the banner -item_list : List[Item] -the list of items in the banner -price : float -the price of pulling from the banner -key : func -function that determines drop rate from rarity -weights : List[float] -list of drop weights for items -Invariant: weights[i] corresponds to item_list[i]

-

Methods

-

add_item(item) : None -Adds an item to the banner -pull() : Item -Returns a random item out of a banner randomized by weight

-

Creates a Banner object

-

Parameters

-
-
name : str
-
name of the banner -Invariant: must be unique
-
item_list : List[Item]
-
the list of items in the banner -Invariant: all items must be unique
-
weights : List[float]
-
the list of drop weights -Invariant: weights[i] is the drop weight for item_list[i]
-
price : float
-
the price of pulling from the banner
-
key : func
-
function that determines drop rate from rarity
-
-
- -Expand source code - -
class Banner :
-    """A representation of a banner in the gacha game
-
-    Fields
-    ------
-    name : string
-        name of the banner
-    item_list : List[Item]
-        the list of items in the banner 
-    price : float
-        the price of pulling from the banner
-    key : func
-        function that determines drop rate from rarity
-    weights : List[float]
-        list of drop weights for items
-        Invariant: weights[i] corresponds to item_list[i]
-
-    Methods
-    -------
-    add_item(item) : None
-        Adds an item to the banner
-    pull() : Item
-        Returns a random item out of a banner randomized by weight
-    """
-
-    def __init__(self, name, item_list, price, key) -> None :
-        """Creates a Banner object
-
-        Parameters
-        ----------
-        name : str
-            name of the banner
-            Invariant: must be unique
-        item_list : List[Item]
-            the list of items in the banner
-            Invariant: all items must be unique
-        weights : List[float]
-            the list of drop weights
-            Invariant: weights[i] is the drop weight for item_list[i]
-        price : float
-            the price of pulling from the banner
-        key : func
-            function that determines drop rate from rarity
-        """
-        self.name = name
-        self.item_list = item_list
-        self.key = key
-        self.weights = get_random_weights(item_list,key)
-        self.price = price
-
-    def add_item(self, item) -> None:
-        """Adds an item to the banner
-
-        Parameters
-        ----------
-        item : Item
-            item to add to the banner
-        
-        Returns
-        -------
-            None
-        """
-        self.item_list.append(item)
-        self.weights = get_random_weights(self.item_list)
-
-    def pull(self) -> Item:
-        """Returns a random item out of a banner randomized by weight
-
-        Returns
-        -------
-        Item
-            the random item from the pull
-        """
-        return random.choices(self.item_list, weights=self.weights, k=1)[0]
-
-    def __str__(self) -> str :
-        """Returns the string representation of this Banner object
-
-        Returns
-        -------
-        str
-            String representation of this object
-        """
-        return self.name + "\nPrice: " + str(self.price) + "\nItems:\n" + "\n".join([str(elem) for elem in self.item_list])
-
-

Methods

-
-
-def add_item(self, item) ‑> NoneType -
-
-

Adds an item to the banner

-

Parameters

-
-
item : Item
-
item to add to the banner
-
-

Returns

-
None
-
-
- -Expand source code - -
def add_item(self, item) -> None:
-    """Adds an item to the banner
-
-    Parameters
-    ----------
-    item : Item
-        item to add to the banner
-    
-    Returns
-    -------
-        None
-    """
-    self.item_list.append(item)
-    self.weights = get_random_weights(self.item_list)
-
-
-
-def pull(self) ‑> Item -
-
-

Returns a random item out of a banner randomized by weight

-

Returns

-
-
Item
-
the random item from the pull
-
-
- -Expand source code - -
def pull(self) -> Item:
-    """Returns a random item out of a banner randomized by weight
-
-    Returns
-    -------
-    Item
-        the random item from the pull
-    """
-    return random.choices(self.item_list, weights=self.weights, k=1)[0]
-
-
-
-
-
-class Item -(name, id, rarity) -
-
-

A representation of an item in the gacha game

-

Fields

-

name : string -name of the item -id : string -description of the item -Invariant: must be unique -id : int -rarity of the item where the higher the numer, the higher the rarity

-

Methods

-

Item : Item -creates an item object

-

Creates an Item object

-

Parameters -name : str -name of the item -id : str -id of the item -rarity : int -rarity of the item where the higher the numer, the higher the rarity

-
- -Expand source code - -
class Item :
-    """A representation of an item in the gacha game
-
-    Fields
-    ------
-    name : string
-        name of the item
-    id : string
-        description of the item
-        Invariant: must be unique
-    id : int
-        rarity of the item where the higher the numer, the higher the rarity
-
-    Methods
-    -------
-    Item : Item
-        creates an item object
-    """
-
-    def __init__(self, name, id, rarity) -> None :
-        """Creates an Item object
-
-        Parameters
-        name : str
-            name of the item
-        id : str
-            id of the item
-        rarity : int
-            rarity of the item where the higher the numer, the higher the rarity
-        """
-        self.name = name
-        self.id = id
-        self.rarity = rarity
-    
-    def __str__(self) -> str :
-        """Returns the string representation of this Item object
-
-        Returns
-        -------
-        str
-            String representation of this object
-        """
-        return self.name + " (Rarity: " + str(self.rarity) + ")"
-
-
-
-class Player -(name, id, items, money) -
-
-

A representation of a player in the gacha game

-

Fields

-

name : str -the name of the player -id : str -the id of the player -Invariant: must be unique -items : List[Item] -the list of items that the player owns -money : float -the amount of money that the player owns

-

Creates a Player object

-

Parameters

-
-
name : str
-
the name of the player
-
id : str
-
the id of the player
-
items : List[Item]
-
the list of items that the player owns
-
money : float
-
the amount of money that the player owns
-
-
- -Expand source code - -
class Player :
-    """A representation of a player in the gacha game
-
-    Fields
-    ------
-    name : str
-        the name of the player
-    id : str
-        the id of the player
-        Invariant: must be unique
-    items : List[Item]
-        the list of items that the player owns
-    money : float
-        the amount of money that the player owns
-    """
-
-    def __init__(self, name, id, items, money) -> None:
-        """Creates a Player object
-
-        Parameters
-        ----------
-        name : str
-            the name of the player
-        id : str
-            the id of the player
-        items : List[Item]
-            the list of items that the player owns
-        money : float
-            the amount of money that the player owns
-        """
-        self.name = name
-        self.id = id
-        self.items = items
-        self.money = money
-    
-    def add_item(self,item) -> None:
-        """Adds an item to the player's inventory
-
-        Parameters
-        ----------
-        item : Item
-            item to add to player inventory
-
-        Returns
-        -------
-        None
-        """
-        self.items.append(item)
-
-    def change_money(self,amount) -> bool:
-        """Adds or removes money from player
-
-        Parameters
-        ----------
-        amount : float
-            the ammount to add or remove (positive if add, negative if remove)
-
-        Returns
-        -------
-        bool
-            True if the amount was able to be added or removed from account (does not
-            create a negative money value), False otherwise
-        """
-        if (amount < 0 and self.money - amount < 0) :
-            return False
-        self.money += amount
-        return True
-
-    def get_net_worth(self) -> float :
-        """Returns the net worth of the player
-
-        Returns
-        -------
-        float
-            the net worth of the player
-        """
-        return sum([i.rarity for i in self.items])
-    
-    def __str__(self) -> str:
-        """Returns the string representation of this Player object
-
-        Returns
-        -------
-        str
-            string representation of this object
-        """
-        return self.name + "\n\nMoney: " + str(self.money) + "\n\nNet worth: " + str(self.get_net_worth()) + "\n\nTop 10 items:\n" + "\n".join([str(elem) for elem in sorted(self.items,key=sort_item_key,reverse=True)[:10]])
-
-

Methods

-
-
-def add_item(self, item) ‑> NoneType -
-
-

Adds an item to the player's inventory

-

Parameters

-
-
item : Item
-
item to add to player inventory
-
-

Returns

-
-
None
-
 
-
-
- -Expand source code - -
def add_item(self,item) -> None:
-    """Adds an item to the player's inventory
-
-    Parameters
-    ----------
-    item : Item
-        item to add to player inventory
-
-    Returns
-    -------
-    None
-    """
-    self.items.append(item)
-
-
-
-def change_money(self, amount) ‑> bool -
-
-

Adds or removes money from player

-

Parameters

-
-
amount : float
-
the ammount to add or remove (positive if add, negative if remove)
-
-

Returns

-
-
bool
-
True if the amount was able to be added or removed from account (does not -create a negative money value), False otherwise
-
-
- -Expand source code - -
def change_money(self,amount) -> bool:
-    """Adds or removes money from player
-
-    Parameters
-    ----------
-    amount : float
-        the ammount to add or remove (positive if add, negative if remove)
-
-    Returns
-    -------
-    bool
-        True if the amount was able to be added or removed from account (does not
-        create a negative money value), False otherwise
-    """
-    if (amount < 0 and self.money - amount < 0) :
-        return False
-    self.money += amount
-    return True
-
-
-
-def get_net_worth(self) ‑> float -
-
-

Returns the net worth of the player

-

Returns

-
-
float
-
the net worth of the player
-
-
- -Expand source code - -
def get_net_worth(self) -> float :
-    """Returns the net worth of the player
-
-    Returns
-    -------
-    float
-        the net worth of the player
-    """
-    return sum([i.rarity for i in self.items])
-
-
-
-
-
-
-
- -
- - - \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index eb647ca..41eb237 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = gachapy -version = 0.0.19 +version = 0.1.0 author = Jacob Kerr author_email = jck268@cornell.edu description = A gacha engine built in Python for developing gacha games diff --git a/setup.py b/setup.py index 6ce3edd..86bce23 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="gachapy", - version="0.0.19", + version="0.1.0", author="Jacob Kerr", author_email="jck268@cornell.edu", description="A gacha engine built in Python for developing gacha games",