diff --git a/src/atlantis.py b/src/atlantis.py index 9b37d88..2c5802f 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 7) #release, major revision, minor (git) revision +VERSION = (0, 0, 8) #release, major revision, minor (git) revision import sys import os diff --git a/src/atlantis.py b/src/atlantis.py index 9b37d88..2c5802f 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 7) #release, major revision, minor (git) revision +VERSION = (0, 0, 8) #release, major revision, minor (git) revision import sys import os diff --git a/src/character.py b/src/character.py index 8764628..ba00075 100644 --- a/src/character.py +++ b/src/character.py @@ -9,16 +9,18 @@ # date: 02/05/2015 # +import Item from define import DefineCommand, register_define_command + class Race(object): ''' A class to describe the races inhabiting the game world ''' - def __init__(self, name, description, - str_bonus, dex_bonus, - int_bonus, const_bonus): + def __init__(self, name, description="", + str_bonus=0, dex_bonus=0, + int_bonus=0, const_bonus=0): ''' Create a new race. Arguments: name, description: the name and description of the new race @@ -30,8 +32,20 @@ self.bonuses = {'strength':str_bonus, 'dexterity':dex_bonus, 'intelligence':int_bonus, 'constitution':const_bonus} - # Do we need any methods here? I can't think of any at the moment... - # If not, we might be able to turn this class into a simple list. + def set_description(self, description): + self.description = description + + def set_strength(self, str_bonus): + self.bonuses['strength'] = str_bonus + + def set_dexterity(self, dex_bonus): + self.bonuses['dexterity'] = dex_bonus + + def set_constitution(self, const_bonus): + self.bonuses['constitution'] = const_bonus + + def set_intelligence(self, int_bonus): + self.bonuses['intelligence'] = int_bonus class DefineRace(DefineCommand): @@ -41,7 +55,24 @@ def __init__(self): super.__init__("define-race", "Define and describe a race of beings") - #TODO + self.race = None + self.add_option("description", "A description of this race", + self.race.set_description) + self.add_option("strength", "The strength bonus that this race gets", + self.race.set_strength) + self.add_option("dexterity", "The dexterity bonus that this race gets", + self.race.set_dexterity) + self.add_option("constitution", "The constitution bonus that this race gets", + self.race.set_constitution) + self.add_option("intelligence", "The intelligence bonus that this race gets", + self.race.set_intelligence) + + def init_object(self, race_name): + self.race = None + self.race = Race(race_name) + + def return_object(self): + return self.race register_define_command(DefineRace()) @@ -51,7 +82,7 @@ A class to describe all the character classes a player can assume ''' - def __init__(self, name, description, special_items): + def __init__(self, name, description="", special_items=[]): ''' Create a new character class. Arguments: name, description: the name and description of this character class @@ -62,7 +93,13 @@ self.description = description self.items = special_items - # Again, do we need any methods here? If not, turn this class into a list. + def set_description(self, description): + self.description = description + + def add_item(self, item_name): + item = Item.get_item(item_name) + self.items.append(item) + class DefineClass(DefineCommand): ''' @@ -71,7 +108,18 @@ def __init__(self): super.__init__("define-class", "Define and describe a character class") - #TODO + self.char_class = None + self.add_option("description", "Describe this character class", + self.char_class.set_description) + self.add_option("item", "An item that all members of this class carry", + self.char_class.add_item) + + def init_object(self, class_name): + self.char_class = None + self.char_class = CharacterClass(name) + + def return_object(self): + return self.char_class register_define_command(DefineClass()) diff --git a/src/atlantis.py b/src/atlantis.py index 9b37d88..2c5802f 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 7) #release, major revision, minor (git) revision +VERSION = (0, 0, 8) #release, major revision, minor (git) revision import sys import os diff --git a/src/character.py b/src/character.py index 8764628..ba00075 100644 --- a/src/character.py +++ b/src/character.py @@ -9,16 +9,18 @@ # date: 02/05/2015 # +import Item from define import DefineCommand, register_define_command + class Race(object): ''' A class to describe the races inhabiting the game world ''' - def __init__(self, name, description, - str_bonus, dex_bonus, - int_bonus, const_bonus): + def __init__(self, name, description="", + str_bonus=0, dex_bonus=0, + int_bonus=0, const_bonus=0): ''' Create a new race. Arguments: name, description: the name and description of the new race @@ -30,8 +32,20 @@ self.bonuses = {'strength':str_bonus, 'dexterity':dex_bonus, 'intelligence':int_bonus, 'constitution':const_bonus} - # Do we need any methods here? I can't think of any at the moment... - # If not, we might be able to turn this class into a simple list. + def set_description(self, description): + self.description = description + + def set_strength(self, str_bonus): + self.bonuses['strength'] = str_bonus + + def set_dexterity(self, dex_bonus): + self.bonuses['dexterity'] = dex_bonus + + def set_constitution(self, const_bonus): + self.bonuses['constitution'] = const_bonus + + def set_intelligence(self, int_bonus): + self.bonuses['intelligence'] = int_bonus class DefineRace(DefineCommand): @@ -41,7 +55,24 @@ def __init__(self): super.__init__("define-race", "Define and describe a race of beings") - #TODO + self.race = None + self.add_option("description", "A description of this race", + self.race.set_description) + self.add_option("strength", "The strength bonus that this race gets", + self.race.set_strength) + self.add_option("dexterity", "The dexterity bonus that this race gets", + self.race.set_dexterity) + self.add_option("constitution", "The constitution bonus that this race gets", + self.race.set_constitution) + self.add_option("intelligence", "The intelligence bonus that this race gets", + self.race.set_intelligence) + + def init_object(self, race_name): + self.race = None + self.race = Race(race_name) + + def return_object(self): + return self.race register_define_command(DefineRace()) @@ -51,7 +82,7 @@ A class to describe all the character classes a player can assume ''' - def __init__(self, name, description, special_items): + def __init__(self, name, description="", special_items=[]): ''' Create a new character class. Arguments: name, description: the name and description of this character class @@ -62,7 +93,13 @@ self.description = description self.items = special_items - # Again, do we need any methods here? If not, turn this class into a list. + def set_description(self, description): + self.description = description + + def add_item(self, item_name): + item = Item.get_item(item_name) + self.items.append(item) + class DefineClass(DefineCommand): ''' @@ -71,7 +108,18 @@ def __init__(self): super.__init__("define-class", "Define and describe a character class") - #TODO + self.char_class = None + self.add_option("description", "Describe this character class", + self.char_class.set_description) + self.add_option("item", "An item that all members of this class carry", + self.char_class.add_item) + + def init_object(self, class_name): + self.char_class = None + self.char_class = CharacterClass(name) + + def return_object(self): + return self.char_class register_define_command(DefineClass()) diff --git a/src/define.py b/src/define.py index 7111301..8c22e73 100644 --- a/src/define.py +++ b/src/define.py @@ -62,3 +62,5 @@ def register_define_command(def_com): define_command_registry[def_com.name] = def_com +def get_define_command(command_name): + return define_command_registry[command_name] diff --git a/src/atlantis.py b/src/atlantis.py index 9b37d88..2c5802f 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 7) #release, major revision, minor (git) revision +VERSION = (0, 0, 8) #release, major revision, minor (git) revision import sys import os diff --git a/src/character.py b/src/character.py index 8764628..ba00075 100644 --- a/src/character.py +++ b/src/character.py @@ -9,16 +9,18 @@ # date: 02/05/2015 # +import Item from define import DefineCommand, register_define_command + class Race(object): ''' A class to describe the races inhabiting the game world ''' - def __init__(self, name, description, - str_bonus, dex_bonus, - int_bonus, const_bonus): + def __init__(self, name, description="", + str_bonus=0, dex_bonus=0, + int_bonus=0, const_bonus=0): ''' Create a new race. Arguments: name, description: the name and description of the new race @@ -30,8 +32,20 @@ self.bonuses = {'strength':str_bonus, 'dexterity':dex_bonus, 'intelligence':int_bonus, 'constitution':const_bonus} - # Do we need any methods here? I can't think of any at the moment... - # If not, we might be able to turn this class into a simple list. + def set_description(self, description): + self.description = description + + def set_strength(self, str_bonus): + self.bonuses['strength'] = str_bonus + + def set_dexterity(self, dex_bonus): + self.bonuses['dexterity'] = dex_bonus + + def set_constitution(self, const_bonus): + self.bonuses['constitution'] = const_bonus + + def set_intelligence(self, int_bonus): + self.bonuses['intelligence'] = int_bonus class DefineRace(DefineCommand): @@ -41,7 +55,24 @@ def __init__(self): super.__init__("define-race", "Define and describe a race of beings") - #TODO + self.race = None + self.add_option("description", "A description of this race", + self.race.set_description) + self.add_option("strength", "The strength bonus that this race gets", + self.race.set_strength) + self.add_option("dexterity", "The dexterity bonus that this race gets", + self.race.set_dexterity) + self.add_option("constitution", "The constitution bonus that this race gets", + self.race.set_constitution) + self.add_option("intelligence", "The intelligence bonus that this race gets", + self.race.set_intelligence) + + def init_object(self, race_name): + self.race = None + self.race = Race(race_name) + + def return_object(self): + return self.race register_define_command(DefineRace()) @@ -51,7 +82,7 @@ A class to describe all the character classes a player can assume ''' - def __init__(self, name, description, special_items): + def __init__(self, name, description="", special_items=[]): ''' Create a new character class. Arguments: name, description: the name and description of this character class @@ -62,7 +93,13 @@ self.description = description self.items = special_items - # Again, do we need any methods here? If not, turn this class into a list. + def set_description(self, description): + self.description = description + + def add_item(self, item_name): + item = Item.get_item(item_name) + self.items.append(item) + class DefineClass(DefineCommand): ''' @@ -71,7 +108,18 @@ def __init__(self): super.__init__("define-class", "Define and describe a character class") - #TODO + self.char_class = None + self.add_option("description", "Describe this character class", + self.char_class.set_description) + self.add_option("item", "An item that all members of this class carry", + self.char_class.add_item) + + def init_object(self, class_name): + self.char_class = None + self.char_class = CharacterClass(name) + + def return_object(self): + return self.char_class register_define_command(DefineClass()) diff --git a/src/define.py b/src/define.py index 7111301..8c22e73 100644 --- a/src/define.py +++ b/src/define.py @@ -62,3 +62,5 @@ def register_define_command(def_com): define_command_registry[def_com.name] = def_com +def get_define_command(command_name): + return define_command_registry[command_name] diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000..aa71680 --- /dev/null +++ b/src/item.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This module takes care of the internal representation of all game items. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 10/05/2015 +# + +import copy +from define import DefineCommand, register_define_command + + +class Item(object): + ''' + This is the actual Item class, which represents a game item. + ''' + + def __init__(self, name): + pass + + +class ItemCommand(DefineCommand): + ''' + The ATL construct to describe an item + ''' + + def __init__(self): + super.__init__("define-item", + "Describe a new item that players can interact with") + self.item = None + # TODO Add option commands + + def init_object(self, item_name): + self.item = None + self.item = Item(item_name) + + def return_object(self): + return self.item + +register_define_command(ItemCommand()) + +# A list of all the items that have been defined in the game world +item_registry = dict() + +def register_item(item): + item_registry[item.name] = item + +def get_item(self, item_name): + ''' + Returns a copy of the item object stored under the passed name. + This means that registry retains a "pure" instance of every item type + for future reference. + ''' + # is deepcopy the right copy method to use? if shallow copy is + # sufficient, we could just use the inbuilt dict.copy() + return copy.deepcopy(item_registry[item_name]) + diff --git a/src/atlantis.py b/src/atlantis.py index 9b37d88..2c5802f 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 7) #release, major revision, minor (git) revision +VERSION = (0, 0, 8) #release, major revision, minor (git) revision import sys import os diff --git a/src/character.py b/src/character.py index 8764628..ba00075 100644 --- a/src/character.py +++ b/src/character.py @@ -9,16 +9,18 @@ # date: 02/05/2015 # +import Item from define import DefineCommand, register_define_command + class Race(object): ''' A class to describe the races inhabiting the game world ''' - def __init__(self, name, description, - str_bonus, dex_bonus, - int_bonus, const_bonus): + def __init__(self, name, description="", + str_bonus=0, dex_bonus=0, + int_bonus=0, const_bonus=0): ''' Create a new race. Arguments: name, description: the name and description of the new race @@ -30,8 +32,20 @@ self.bonuses = {'strength':str_bonus, 'dexterity':dex_bonus, 'intelligence':int_bonus, 'constitution':const_bonus} - # Do we need any methods here? I can't think of any at the moment... - # If not, we might be able to turn this class into a simple list. + def set_description(self, description): + self.description = description + + def set_strength(self, str_bonus): + self.bonuses['strength'] = str_bonus + + def set_dexterity(self, dex_bonus): + self.bonuses['dexterity'] = dex_bonus + + def set_constitution(self, const_bonus): + self.bonuses['constitution'] = const_bonus + + def set_intelligence(self, int_bonus): + self.bonuses['intelligence'] = int_bonus class DefineRace(DefineCommand): @@ -41,7 +55,24 @@ def __init__(self): super.__init__("define-race", "Define and describe a race of beings") - #TODO + self.race = None + self.add_option("description", "A description of this race", + self.race.set_description) + self.add_option("strength", "The strength bonus that this race gets", + self.race.set_strength) + self.add_option("dexterity", "The dexterity bonus that this race gets", + self.race.set_dexterity) + self.add_option("constitution", "The constitution bonus that this race gets", + self.race.set_constitution) + self.add_option("intelligence", "The intelligence bonus that this race gets", + self.race.set_intelligence) + + def init_object(self, race_name): + self.race = None + self.race = Race(race_name) + + def return_object(self): + return self.race register_define_command(DefineRace()) @@ -51,7 +82,7 @@ A class to describe all the character classes a player can assume ''' - def __init__(self, name, description, special_items): + def __init__(self, name, description="", special_items=[]): ''' Create a new character class. Arguments: name, description: the name and description of this character class @@ -62,7 +93,13 @@ self.description = description self.items = special_items - # Again, do we need any methods here? If not, turn this class into a list. + def set_description(self, description): + self.description = description + + def add_item(self, item_name): + item = Item.get_item(item_name) + self.items.append(item) + class DefineClass(DefineCommand): ''' @@ -71,7 +108,18 @@ def __init__(self): super.__init__("define-class", "Define and describe a character class") - #TODO + self.char_class = None + self.add_option("description", "Describe this character class", + self.char_class.set_description) + self.add_option("item", "An item that all members of this class carry", + self.char_class.add_item) + + def init_object(self, class_name): + self.char_class = None + self.char_class = CharacterClass(name) + + def return_object(self): + return self.char_class register_define_command(DefineClass()) diff --git a/src/define.py b/src/define.py index 7111301..8c22e73 100644 --- a/src/define.py +++ b/src/define.py @@ -62,3 +62,5 @@ def register_define_command(def_com): define_command_registry[def_com.name] = def_com +def get_define_command(command_name): + return define_command_registry[command_name] diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000..aa71680 --- /dev/null +++ b/src/item.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This module takes care of the internal representation of all game items. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 10/05/2015 +# + +import copy +from define import DefineCommand, register_define_command + + +class Item(object): + ''' + This is the actual Item class, which represents a game item. + ''' + + def __init__(self, name): + pass + + +class ItemCommand(DefineCommand): + ''' + The ATL construct to describe an item + ''' + + def __init__(self): + super.__init__("define-item", + "Describe a new item that players can interact with") + self.item = None + # TODO Add option commands + + def init_object(self, item_name): + self.item = None + self.item = Item(item_name) + + def return_object(self): + return self.item + +register_define_command(ItemCommand()) + +# A list of all the items that have been defined in the game world +item_registry = dict() + +def register_item(item): + item_registry[item.name] = item + +def get_item(self, item_name): + ''' + Returns a copy of the item object stored under the passed name. + This means that registry retains a "pure" instance of every item type + for future reference. + ''' + # is deepcopy the right copy method to use? if shallow copy is + # sufficient, we could just use the inbuilt dict.copy() + return copy.deepcopy(item_registry[item_name]) + diff --git a/src/world.py b/src/world.py index 291070d..a603c26 100644 --- a/src/world.py +++ b/src/world.py @@ -18,6 +18,17 @@ The World class saves and gives access to the current state of the game world. ''' + + # Originally it was intended that the world hold a copy of every game + # object defined, and thus act as a meta-registry. However, that will + # most likely lead to circular dependencies. (For example, CharacterClass + # requires access to the item registry. If the latter was located here in + # world.py, character.py would have to import world.py, which in turn + # imports character.py...) + # Thus it seems better that each registry be moved to the module that + # deals with the relevant game object. The item registry has already been + # moved to item.py. The monster registry needs to follow suit. I am not + # yet sure what to do with the place and NPC registries. def __init__(self): ''' @@ -29,7 +40,6 @@ self.players = dict() self.starting_place = None self.npc = dict() - self.items = dict() self.monsters = dict() def register_player(self, player): @@ -53,8 +63,6 @@ self.add_place(game_object) elif object_type == "npc": self.add_npc(game_object) - elif object_type == "item": - self.add_item(game_object) elif object_type == "monster": self.add_monster(game_object) @@ -67,9 +75,6 @@ def add_npc(self, npc): self.npc[npc.name] = npc - def add_item(self, item): - self.items[item.name] = item - def get_player(self, name): return self.players[name] @@ -82,17 +87,8 @@ def get_npc(self, npc_name): return self.npc[npc_name] - def get_item(self, item_name): - ''' - Returns a copy of the item object stored under the passed name. - This means that World retains a "pure" instance of every item type - for future reference. Each Place holds its own item objects that - can be changed or removed at will. - ''' - # is deepcopy the right copy method to use? if shallow copy is - # sufficient, we could just use the inbuilt dict.copy() - return copy.deepcopy(self.items[item_name]) + # TODO Move to monster.py def get_monster(self, monster_name): ''' Returns a copy of the monster object stored under the passed name.