def setUp(self): """ Test that the BuffSchema's values are as expected Test that the convert_to_beneficial_buff_object function works as expected """ self.buff_entry = 1 self.name = 'Heart of a Lion' self.duration = 5 self.expected_buff = BeneficialBuff(name="Heart of a Lion", buff_stats_and_amounts=[ ('strength', 15) ], duration=5)
def _apply_buff(self, buff: BeneficialBuff): """ Add the buff to the living thing's stats""" buff_attributes: {str: int} = buff.get_buffed_attributes() # iterate through the buffed attributes and apply them to the entity for buff_type, buff_amount in buff_attributes.items(): if buff_type == "health": if not self._in_combat: self.health += buff_amount self.max_health += buff_amount elif buff_type == "mana": if not self._in_combat: self.mana += buff_amount self.max_mana += buff_amount
def _deapply_buff(self, buff: BeneficialBuff): """ Remove the buff from the character's stats""" buff_attributes: {str: int} = buff.get_buffed_attributes() # iterate through the buffed attributes and remove them from the character for buff_type, buff_amount in buff_attributes.items(): if buff_type == "health": self.attributes[KEY_BONUS_HEALTH_ATTRIBUTE] -= buff_amount elif buff_type == "mana": self.attributes[KEY_BONUS_MANA_ATTRIBUTE] -= buff_amount else: self.attributes[buff_type] -= buff_amount self._calculate_stats_formulas() # always recalculate the formulas when stats are changed
def _deapply_buff(self, buff: BeneficialBuff): """ Remove the buff from the character's stats""" buff_attributes: {str: int} = buff.get_buffed_attributes() # iterate through the buffed attributes and remove them from the character for buff_type, buff_amount in buff_attributes.items(): if buff_type == "health": self.attributes[KEY_BONUS_HEALTH_ATTRIBUTE] -= buff_amount elif buff_type == "mana": self.attributes[KEY_BONUS_MANA_ATTRIBUTE] -= buff_amount else: self.attributes[buff_type] -= buff_amount self._calculate_stats_formulas( ) # always recalculate the formulas when stats are changed
def _deapply_buff(self, buff: BeneficialBuff): """ Remove the buff from the living thing's stats""" buff_attributes = buff.get_buffed_attributes() # type: dict # iterate through the buffed attributes and remove them from the entity for buff_type, buff_amount in buff_attributes.items(): if buff_type == "health": # TODO: Reduce health method to reduce active health too, otherwise we can end up with 10/5 HP self.max_health -= buff_amount if self.health > self.max_health: self.health = self.max_health elif buff_type == "mana": # TODO: Reduce mana method to reduce active mana too self.max_mana -= buff_amount if self.mana > self.max_mana: self.mana = self.max_mana
def test_decide_drops(self): """ Test the decide drops function by calling it multiple times until all the items drop """ l_table = session.query(LootTableSchema).get(self.loot_table_entry) self.expected_item1 = Item(name='Linen Cloth', item_id=self.item_1, buy_price=1, sell_price=1) self.effect: BeneficialBuff = BeneficialBuff(name="Heart of a Lion", buff_stats_and_amounts=[ ('strength', 15) ], duration=5) self.expected_item2 = Potion(name='Strength Potion', item_id=4, buy_price=1, sell_price=1, buff=self.effect, quest_id=0) self.expected_item3 = Weapon(name='Worn Axe', item_id=3, buy_price=1, sell_price=1, min_damage=2, max_damage=6, attributes={ 'bonus_health': 0, 'bonus_mana': 0, 'armor': 0, 'strength': 0, 'agility': 0 }) received_items_count = 0 for _ in range(100): drops: [Item] = l_table.decide_drops() for drop in drops: equal_to_one_of_the_three_items = ( drop == self.expected_item1 or drop == self.expected_item2 or drop == self.expected_item3) self.assertTrue(equal_to_one_of_the_three_items) received_items_count += 1 self.assertGreater(received_items_count, 10)
def setUp(self): self.item_entry = 4 self.name = 'Strength Potion' self.buy_price = 1 self.sell_price = 1 self.effect_id = 1 self.effect: BeneficialBuff = BeneficialBuff(name="Heart of a Lion", buff_stats_and_amounts=[ ('strength', 15) ], duration=5) self.potion = Potion(name=self.name, item_id=self.item_entry, buy_price=self.buy_price, sell_price=self.sell_price, buff=self.effect, quest_id=0)
def get_expected_quests(self) -> {str: Quest}: quest_entry, name, level_required = 1, 'A Canine Menace', 1 monster_required, xp_reward = 'Wolf', 300 expected_kill_quest = KillQuest(quest_name=name, quest_id=quest_entry, xp_reward=xp_reward, item_reward_dict={}, reward_choice_enabled=False, level_required=level_required, is_completed=False, required_monster=monster_required, required_kills=5) entry, name, type = 2, 'Canine-Like Hunger', 'fetchquest' level_required, monster_required, amount_required = 1, None, 2 zone, sub_zone, xp_reward = 'Northshire Abbey', 'Northshire Valley', 300 item_rewards = { 'Wolf Meat': Item(name='Wolf Meat', item_id=1, buy_price=1, sell_price=1, quest_id=2), 'Strength Potion': Potion(name='Strength Potion', item_id=4, buy_price=1, sell_price=1, buff=BeneficialBuff(name="Heart of a Lion", buff_stats_and_amounts=[('strength', 15) ], duration=5)) } expected_quest = FetchQuest(quest_name=name, quest_id=entry, required_item='Wolf Meat', xp_reward=xp_reward, item_reward_dict=item_rewards, reward_choice_enabled=True, level_required=level_required, required_item_count=amount_required, is_completed=False) return { expected_quest.name: expected_quest, expected_kill_quest.name: expected_kill_quest }
def convert_to_beneficial_buff_object(self) -> BeneficialBuff: """ Convert it to a BeneficialBuff object """ buff_name: str = self.name buff_stat1: str = self.stat1 buff_amount1: int = parse_int(self.amount1) buff_stat2: str = self.stat2 buff_amount2: int = parse_int(self.amount2) buff_stat3: str = self.stat3 buff_amount3: int = parse_int(self.amount3) buff_duration: int = parse_int(self.duration) buffs: [(str, int)] = [(buff_stat1, buff_amount1), (buff_stat2, buff_amount2), (buff_stat3, buff_amount3)] return BeneficialBuff(name=buff_name, buff_stats_and_amounts=[(stat, amount) for stat, amount in buffs if stat is not None and amount is not None], duration=buff_duration)
def test_convert_to_quest_object_fetchquest(self): """ Create the expected FetchQuest and compare it with the one that is loaded :return: """ entry, name, type = 2, 'Canine-Like Hunger', 'fetchquest' level_required, monster_required, amount_required = 1, None, 2 zone, sub_zone, xp_reward = 'Northshire Abbey', 'Northshire Valley', 300 description = 'Obtain 2 Wolf Meats' item_rewards = { 'Wolf Meat': Item(name='Wolf Meat', item_id=1, buy_price=1, sell_price=1, quest_id=2), 'Strength Potion': Potion(name='Strength Potion', item_id=4, buy_price=1, sell_price=1, buff=BeneficialBuff(name="Heart of a Lion", buff_stats_and_amounts=[('strength', 15) ], duration=5)) } expected_quest = FetchQuest(quest_name=name, quest_id=entry, required_item='Wolf Meat', xp_reward=xp_reward, item_reward_dict=item_rewards, reward_choice_enabled=True, level_required=level_required, required_item_count=amount_required, is_completed=False) received_quest = session.query(QuestSchema).get( entry).convert_to_quest_object() self.assertEqual(vars(received_quest), vars(expected_quest))