Added modification functions to class system.

This commit is contained in:
Chris Davoren 2023-06-30 15:48:37 +10:00
parent 9263aa2b52
commit 7993df5831
1 changed files with 33 additions and 1 deletions

View File

@ -176,6 +176,15 @@ class Ship:
def add_character(self, character): def add_character(self, character):
self.characters.append(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: class Player:
@ -196,7 +205,7 @@ class GameData:
def populate(self): def populate(self):
# Step 1 - Player data # Step 1 - Player data
char_tag = self.soup.find('playerBank') char_tag = self.soup.find('playerBank')
currency = char_tag['ca'] currency = int(char_tag['ca'])
self.player = Player(currency, char_tag) self.player = Player(currency, char_tag)
# Step 2 - Ship data # Step 2 - Ship data
@ -285,6 +294,8 @@ class GameData:
# Step 1 - Update characters # Step 1 - Update characters
# Names etc will be done automatically - just need to reconstruct skills and attributes # 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 ship in self.ships:
for character in ship.characters: for character in ship.characters:
# Cloned character tags have to be added to the list # 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) new_tag = self.soup.new_tag('s', attrs=tag_dict)
area_tag.append(new_tag) 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): def print_summary(self):
print("Start game summary:") print("Start game summary:")
print(" Player currency: {}".format(self.player.currency)) print(" Player currency: {}".format(self.player.currency))
@ -509,6 +538,9 @@ def main():
game_data = GameData(soup, item_code_database) game_data = GameData(soup, item_code_database)
game_data.populate() game_data.populate()
game_data.add_item(1759, 100)
game_data.buff_characters()
game_data.add_currency(10000)
game_data.print_summary() game_data.print_summary()
game_data.writeback() game_data.writeback()