Player starts with equipped rapier, the power of the weapon increases damage, player can no longer sell equipped items.
Justin Armstrong justinmeister@gmail.com
Thu, 22 May 2014 12:27:32 -0700
6 files changed,
84 insertions(+),
11 deletions(-)
M
data/components/person.py
→
data/components/person.py
@@ -568,8 +568,12 @@ def calculate_hit(self):
""" Calculate hit strength based on attack stats. """ - max_strength = 5 + (self.level * 5) - print max_strength + weapon = self.game_data['player inventory']['equipped weapon'] + if not weapon: + weapon_power = 0 + else: + weapon_power = self.game_data['player inventory'][weapon]['power'] + max_strength = weapon_power + (self.level * 5) min_strength = max_strength // 2 return random.randint(min_strength, max_strength)
M
data/main.py
→
data/main.py
@@ -47,4 +47,4 @@ DUNGEON5: levels.LevelState(DUNGEON5, True)
} run_it.setup_states(state_dict, c.MAIN_MENU) - run_it.main()+ run_it.main()
M
data/shopgui.py
→
data/shopgui.py
@@ -20,6 +20,8 @@ self.player_inventory = level.game_data['player inventory']
self.name = level.name self.state = 'dialogue' self.no_selling = ['Inn', 'Magic Shop'] + self.weapon_list = ['Long Sword', 'Rapier'] + self.armor_list = ['Chain Mail', 'Wooden Shield'] self.font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 22) self.index = 0 self.timer = 0.0@@ -149,7 +151,9 @@ 'acceptsell': self.accept_sale,
'hasitem': self.has_item, 'buysell': self.buy_sell, 'sell': self.sell_items, - 'cantsell': self.cant_sell} + 'cantsell': self.cant_sell, + 'cantsellequippedweapon': self.cant_sell_equipped_weapon, + 'cantsellequippedarmor': self.cant_sell_equipped_armor} return state_dict@@ -277,7 +281,7 @@ self.player_inventory['GOLD']['quantity'] += item['price']
self.state = 'reject' else: if (item['type'] in self.player_inventory and - self.name == c.MAGIC_SHOP): + not self.name == c.POTION_SHOP): self.state = 'hasitem' self.player_inventory['GOLD']['quantity'] += item['price'] else:@@ -290,13 +294,15 @@ """Add item to player's inventory"""
item_type = item['type'] quantity = item['quantity'] value = item['price'] + power = item['power'] magic_list = ['Cure', 'Fire Blast'] player_items = self.level.game_data['player inventory'] player_health = self.level.game_data['player stats']['health'] player_magic = self.level.game_data['player stats']['magic points'] item_to_add = {'quantity': quantity, - 'value': value} + 'value': value, + 'power': power} if item_type in magic_list: item_to_add = {'magic points': item['magic points'],@@ -340,15 +346,36 @@ self.allow_input = True
def sell_item_from_inventory(self): - """Allow player to sell item to shop""" + """ + Allow player to sell item to shop. + """ item_price = self.item_to_be_sold['price'] item_name = self.item_to_be_sold['type'] - self.player_inventory['gold'] += (item_price / 2) + + if item_name in self.weapon_list: + if item_name == self.game_data['player inventory']['equipped weapon']: + self.state = 'cantsellequippedweapon' + else: + self.sell_inventory_data_adjust(item_price, item_name) + + elif item_name in self.armor_list: + if item_name in self.game_data['player inventory']['equipped armor']: + self.state = 'cantsellequippedarmor' + else: + self.sell_inventory_data_adjust(item_price, item_name) + + def sell_inventory_data_adjust(self, item_price, item_name): + """ + Add gold and subtract item during sale. + """ + self.player_inventory['GOLD']['quantity'] += (item_price / 2) self.state = 'acceptsell' if self.player_inventory[item_name]['quantity'] > 1: self.player_inventory[item_name]['quantity'] -= 1 else: del self.player_inventory[self.item_to_be_sold['type']] + + def reject_insufficient_gold(self, keys, current_time):@@ -499,7 +526,7 @@ elif self.arrow_index == 1 and len(choices) == 3:
self.state = 'confirmsell' self.allow_input = False for item in self.items: - if item['type'] == choices[1]: + if item['type'] == item_list[1]: self.item_to_be_sold = item else: self.state = 'buysell'@@ -522,6 +549,35 @@
if not keys[pg.K_SPACE]: self.allow_input = True + + def cant_sell_equipped_weapon(self, keys, *args): + """ + Do not sell weapon the player has equipped. + """ + dialogue = ["You can't sell an equipped weapon."] + self.dialogue_box = self.make_dialogue_box(dialogue, 0) + + if keys[pg.K_SPACE] and self.allow_input: + self.state = 'buysell' + self.allow_input = False + + if not keys[pg.K_SPACE]: + self.allow_input = True + + def cant_sell_equipped_armor(self, keys, *args): + """ + Do not sell armor the player has equipped. + """ + dialogue = ["You can't sell equipped armor."] + self.dialogue_box = self.make_dialogue_box(dialogue, 0) + + if keys[pg.K_SPACE] and self.allow_input: + self.state = 'buysell' + self.allow_input = False + + if not keys[pg.K_SPACE]: + self.allow_input = True + def update(self, keys, current_time):
M
data/states/battle.py
→
data/states/battle.py
@@ -46,7 +46,8 @@ new_dict = {c.OVERWORLD: 1,
c.DUNGEON: 2, c.DUNGEON2: 2, c.DUNGEON3: 3, - c.DUNGEON4: 2} + c.DUNGEON4: 2, + c.DUNGEON5: 5} return new_dict@@ -223,6 +224,10 @@
elif self.state == c.BATTLE_WON: if (self.current_time - self.timer) > 1800: self.enter_show_experience_state() + + elif self.state == c.LEVEL_UP: + if (self.current_time - self.timer) > 2200: + self.end_battle() elif self.state == c.SHOW_EXPERIENCE: if (self.current_time - self.timer) > 2200:
M
data/states/shop.py
→
data/states/shop.py
@@ -140,6 +140,7 @@
item = {'type': 'room', 'price': 30, 'quantity': 0, + 'power': None, 'dialogue': dialogue} return [item]@@ -169,11 +170,13 @@
item2 = {'type': 'Long Sword', 'price': 100, 'quantity': 1, + 'power': 10, 'dialogue': longsword_dialogue} item1 = {'type': 'Rapier', 'price': 50, 'quantity': 1, + 'power': 5, 'dialogue': rapier_dialogue} return [item1, item2]@@ -202,11 +205,13 @@
item = {'type': 'Chain Mail', 'price': 50, 'quantity': 1, + 'power': 1, 'dialogue': chainmail_dialogue} item2 = {'type': 'Wooden Shield', 'price': 75, 'quantity': 1, + 'power': 1, 'dialogue': shield_dialogue} return [item, item2]
M
data/tools.py
→
data/tools.py
@@ -179,7 +179,10 @@ 'Ether Potion': dict([('quantity',5),
('value', 15)]), 'Cure': dict([('magic points', 25), ('power', 50)]), - 'equipped weapon': None, + 'Rapier': dict([('quantity', 1), + ('value', 50), + ('power', 10)]), + 'equipped weapon': 'Rapier', 'equipped armor': []} player_health = {'current': 100,