Add shields to be more protected, see #48
This commit is contained in:
		@@ -40,14 +40,20 @@ class Item(Entity):
 | 
			
		||||
        Indicates what should be done when the item is used.
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
    def equip(self) -> None:
 | 
			
		||||
    def equip(self, armor: bool = False) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Indicates what should be done when the item is equipped.
 | 
			
		||||
        """
 | 
			
		||||
        if self.held_by.equipped_item:
 | 
			
		||||
            self.held_by.equipped_item.unequip()
 | 
			
		||||
        self.held_by.remove_from_inventory(self)
 | 
			
		||||
        self.held_by.equipped_item = self
 | 
			
		||||
        if armor:
 | 
			
		||||
            if self.held_by.equipped_armor:
 | 
			
		||||
                self.held_by.equipped_armor.unequip()
 | 
			
		||||
            self.held_by.remove_from_inventory(self)
 | 
			
		||||
            self.held_by.equipped_armor = self
 | 
			
		||||
        else:
 | 
			
		||||
            if self.held_by.equipped_item:
 | 
			
		||||
                self.held_by.equipped_item.unequip()
 | 
			
		||||
            self.held_by.remove_from_inventory(self)
 | 
			
		||||
            self.held_by.equipped_item = self
 | 
			
		||||
 | 
			
		||||
    def unequip(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
@@ -75,7 +81,7 @@ class Item(Entity):
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def get_all_items() -> list:
 | 
			
		||||
        return [BodySnatchPotion, Bomb, Heart, Sword]
 | 
			
		||||
        return [BodySnatchPotion, Bomb, Heart, Shield, Sword]
 | 
			
		||||
 | 
			
		||||
    def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
 | 
			
		||||
        """
 | 
			
		||||
@@ -225,20 +231,17 @@ class Sword(Weapon):
 | 
			
		||||
    """
 | 
			
		||||
    A basic weapon
 | 
			
		||||
    """
 | 
			
		||||
    strength: int
 | 
			
		||||
 | 
			
		||||
    def __init__(self, name: str = "sword", price: int = 20, strength: int = 3,
 | 
			
		||||
    def __init__(self, name: str = "sword", price: int = 20,
 | 
			
		||||
                 *args, **kwargs):
 | 
			
		||||
        super().__init__(name=name, price=price, *args, **kwargs)
 | 
			
		||||
        self.name = name
 | 
			
		||||
        self.strength = strength
 | 
			
		||||
 | 
			
		||||
    def equip(self) -> None:
 | 
			
		||||
    def equip(self, armor: bool = False) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        When a sword is equipped, the player gains strength.
 | 
			
		||||
        """
 | 
			
		||||
        super().equip()
 | 
			
		||||
        self.held_by.strength += self.strength
 | 
			
		||||
        self.held_by.strength += self.damage
 | 
			
		||||
 | 
			
		||||
    def unequip(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
@@ -246,7 +249,28 @@ class Sword(Weapon):
 | 
			
		||||
        :return:
 | 
			
		||||
        """
 | 
			
		||||
        super().unequip()
 | 
			
		||||
        self.held_by.strength -= self.strength
 | 
			
		||||
        self.held_by.strength -= self.damage
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Shield(Item):
 | 
			
		||||
    constitution: int
 | 
			
		||||
 | 
			
		||||
    def __init__(self, constitution: int = 2, *args, **kwargs):
 | 
			
		||||
        super().__init__(name="shield", *args, **kwargs)
 | 
			
		||||
        self.constitution = constitution
 | 
			
		||||
 | 
			
		||||
    def equip(self, armor: bool = True) -> None:
 | 
			
		||||
        super().equip(armor)
 | 
			
		||||
        self.held_by.constitution += self.constitution
 | 
			
		||||
 | 
			
		||||
    def unequip(self) -> None:
 | 
			
		||||
        super().unequip()
 | 
			
		||||
        self.held_by.constitution -= self.constitution
 | 
			
		||||
 | 
			
		||||
    def save_state(self) -> dict:
 | 
			
		||||
        d = super().save_state()
 | 
			
		||||
        d["constitution"] = self.constitution
 | 
			
		||||
        return d
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BodySnatchPotion(Item):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user