Added modification functions to class system.
This commit is contained in:
parent
9263aa2b52
commit
7993df5831
|
@ -176,6 +176,15 @@ class Ship:
|
|||
def add_character(self, character):
|
||||
self.characters.append(character)
|
||||
|
||||
def add_item(self, item):
|
||||
min_storage_area = self.storage_areas[0]
|
||||
min_occupancy = min_storage_area.get_total_occupancy()
|
||||
for storage_area in self.storage_areas:
|
||||
if storage_area.get_total_occupancy() < min_occupancy:
|
||||
min_storage_area = storage_area
|
||||
min_occupancy = min_storage_area.get_total_occupancy()
|
||||
min_storage_area.add_item(item)
|
||||
|
||||
|
||||
class Player:
|
||||
|
||||
|
@ -196,7 +205,7 @@ class GameData:
|
|||
def populate(self):
|
||||
# Step 1 - Player data
|
||||
char_tag = self.soup.find('playerBank')
|
||||
currency = char_tag['ca']
|
||||
currency = int(char_tag['ca'])
|
||||
self.player = Player(currency, char_tag)
|
||||
|
||||
# Step 2 - Ship data
|
||||
|
@ -285,6 +294,8 @@ class GameData:
|
|||
# Step 1 - Update characters
|
||||
# Names etc will be done automatically - just need to reconstruct skills and attributes
|
||||
|
||||
self.player.tag['ca'] = self.player.currency
|
||||
|
||||
for ship in self.ships:
|
||||
for character in ship.characters:
|
||||
# Cloned character tags have to be added to the list
|
||||
|
@ -313,6 +324,24 @@ class GameData:
|
|||
new_tag = self.soup.new_tag('s', attrs=tag_dict)
|
||||
area_tag.append(new_tag)
|
||||
|
||||
def add_item(self, item_code, item_quantity):
|
||||
item_name = self.item_database.get_name_from_code(item_code)
|
||||
item = Item(item_code, item_name, item_quantity)
|
||||
for ship in self.ships:
|
||||
if ship.owner == "Player":
|
||||
ship.add_item(item)
|
||||
break
|
||||
|
||||
def buff_characters(self):
|
||||
for ship in self.ships:
|
||||
if ship.owner == "Player":
|
||||
for character in ship.characters:
|
||||
character.maximize_skills()
|
||||
character.maximize_attributes()
|
||||
|
||||
def add_currency(self, amount):
|
||||
self.player.currency += amount
|
||||
|
||||
def print_summary(self):
|
||||
print("Start game summary:")
|
||||
print(" Player currency: {}".format(self.player.currency))
|
||||
|
@ -509,6 +538,9 @@ def main():
|
|||
|
||||
game_data = GameData(soup, item_code_database)
|
||||
game_data.populate()
|
||||
game_data.add_item(1759, 100)
|
||||
game_data.buff_characters()
|
||||
game_data.add_currency(10000)
|
||||
game_data.print_summary()
|
||||
game_data.writeback()
|
||||
|
||||
|
|
Loading…
Reference in New Issue