Merge branch 'master' into 'moreitems'
# Conflicts: # squirrelbattle/entities/items.py # squirrelbattle/interfaces.py # squirrelbattle/tests/game_test.py
This commit is contained in:
		@@ -24,6 +24,13 @@ class Item(Entity):
 | 
			
		||||
        self.held_by = held_by
 | 
			
		||||
        self.price = price
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def description(self) -> str:
 | 
			
		||||
        """
 | 
			
		||||
        In the inventory, indicate the usefulness of the item.
 | 
			
		||||
        """
 | 
			
		||||
        return ""
 | 
			
		||||
 | 
			
		||||
    def drop(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        The item is dropped from the inventory onto the floor.
 | 
			
		||||
@@ -84,9 +91,9 @@ class Item(Entity):
 | 
			
		||||
        """
 | 
			
		||||
        Returns the list of all item classes.
 | 
			
		||||
        """
 | 
			
		||||
        return [BodySnatchPotion, Bomb, Heart, Shield, Sword,
 | 
			
		||||
                Chestplate, Helmet, RingCritical, RingXP,
 | 
			
		||||
                ScrollofDamage, ScrollofWeakening, Ruler, Bow, FireBallStaff]
 | 
			
		||||
        return [BodySnatchPotion, Bomb, Bow, Chestplate, FireBallStaff,
 | 
			
		||||
                Heart, Helmet, Monocle, ScrollofDamage, ScrollofWeakening,
 | 
			
		||||
                Shield, Sword, RingCritical, RingXP, Ruler]
 | 
			
		||||
 | 
			
		||||
    def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder,
 | 
			
		||||
                for_free: bool = False) -> bool:
 | 
			
		||||
@@ -120,6 +127,10 @@ class Heart(Item):
 | 
			
		||||
        super().__init__(name=name, price=price, *args, **kwargs)
 | 
			
		||||
        self.healing = healing
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def description(self) -> str:
 | 
			
		||||
        return f"HP+{self.healing}"
 | 
			
		||||
 | 
			
		||||
    def hold(self, entity: InventoryHolder) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        When holding a heart, the player is healed and
 | 
			
		||||
@@ -228,6 +239,10 @@ class Weapon(Item):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.damage = damage
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def description(self) -> str:
 | 
			
		||||
        return f"STR+{self.damage}" if self.damage else super().description
 | 
			
		||||
 | 
			
		||||
    def save_state(self) -> dict:
 | 
			
		||||
        """
 | 
			
		||||
        Saves the state of the weapon into a dictionary
 | 
			
		||||
@@ -281,6 +296,11 @@ class Armor(Item):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.constitution = constitution
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def description(self) -> str:
 | 
			
		||||
        return f"CON+{self.constitution}" if self.constitution \
 | 
			
		||||
            else super().description
 | 
			
		||||
 | 
			
		||||
    def equip(self) -> None:
 | 
			
		||||
        super().equip()
 | 
			
		||||
        self.held_by.constitution += self.constitution
 | 
			
		||||
@@ -398,6 +418,14 @@ class Ring(Item):
 | 
			
		||||
        self.critical = critical
 | 
			
		||||
        self.experience = experience
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def description(self) -> str:
 | 
			
		||||
        fields = [("MAX HP", self.maxhealth), ("STR", self.strength),
 | 
			
		||||
                  ("INT", self.intelligence), ("CHR", self.charisma),
 | 
			
		||||
                  ("DEX", self.dexterity), ("CON", self.constitution),
 | 
			
		||||
                  ("CRI", self.critical), ("XP", self.experience)]
 | 
			
		||||
        return ", ".join(f"{key}+{value}" for key, value in fields if value)
 | 
			
		||||
 | 
			
		||||
    def equip(self) -> None:
 | 
			
		||||
        super().equip()
 | 
			
		||||
        self.held_by.maxhealth += self.maxhealth
 | 
			
		||||
@@ -446,7 +474,6 @@ class RingXP(Ring):
 | 
			
		||||
        super().__init__(name=name, price=price, experience=experience,
 | 
			
		||||
                         *args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ScrollofDamage(Item):
 | 
			
		||||
    """
 | 
			
		||||
    A scroll that, when used, deals damage to all entities in a certain radius.
 | 
			
		||||
@@ -604,3 +631,9 @@ class FireBallStaff(LongRangeWeapon):
 | 
			
		||||
 | 
			
		||||
            explosion = Explosion(y=y, x=x)
 | 
			
		||||
            self.held_by.map.add_entity(explosion)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Monocle(Item):
 | 
			
		||||
    def __init__(self, name: str = "monocle", price: int = 10,
 | 
			
		||||
                 *args, **kwargs):
 | 
			
		||||
        super().__init__(name=name, price=price, *args, **kwargs)
 | 
			
		||||
@@ -43,7 +43,9 @@ class Monster(FightingEntity):
 | 
			
		||||
        # that targets the player.
 | 
			
		||||
        # If they can not move and are already close to the player,
 | 
			
		||||
        # they hit.
 | 
			
		||||
        if target and (self.y, self.x) in target.paths:
 | 
			
		||||
        if target and (self.y, self.x) in target.paths and \
 | 
			
		||||
                self.map.is_visible_from(self.y, self.x,
 | 
			
		||||
                                         target.y, target.x, 5):
 | 
			
		||||
            # Moves to target player by choosing the best available path
 | 
			
		||||
            for next_y, next_x in target.paths[(self.y, self.x)]:
 | 
			
		||||
                moved = self.check_move(next_y, next_x, True)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user