Add shields to be more protected, see #48
This commit is contained in:
parent
9aa684fb77
commit
c01307202a
|
@ -70,6 +70,7 @@ TexturePack.ASCII_PACK = TexturePack(
|
||||||
MERCHANT='M',
|
MERCHANT='M',
|
||||||
PLAYER='@',
|
PLAYER='@',
|
||||||
RABBIT='Y',
|
RABBIT='Y',
|
||||||
|
SHIELD='D',
|
||||||
SUNFLOWER='I',
|
SUNFLOWER='I',
|
||||||
SWORD='\u2020',
|
SWORD='\u2020',
|
||||||
TEDDY_BEAR='8',
|
TEDDY_BEAR='8',
|
||||||
|
@ -96,6 +97,7 @@ TexturePack.SQUIRREL_PACK = TexturePack(
|
||||||
PLAYER='🐿️ ️',
|
PLAYER='🐿️ ️',
|
||||||
MERCHANT='🦜',
|
MERCHANT='🦜',
|
||||||
RABBIT='🐇',
|
RABBIT='🐇',
|
||||||
|
SHIELD='🛡️ ',
|
||||||
SUNFLOWER='🌻',
|
SUNFLOWER='🌻',
|
||||||
SWORD='🗡️ ',
|
SWORD='🗡️ ',
|
||||||
TEDDY_BEAR='🧸',
|
TEDDY_BEAR='🧸',
|
||||||
|
|
|
@ -40,14 +40,20 @@ class Item(Entity):
|
||||||
Indicates what should be done when the item is used.
|
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.
|
Indicates what should be done when the item is equipped.
|
||||||
"""
|
"""
|
||||||
if self.held_by.equipped_item:
|
if armor:
|
||||||
self.held_by.equipped_item.unequip()
|
if self.held_by.equipped_armor:
|
||||||
self.held_by.remove_from_inventory(self)
|
self.held_by.equipped_armor.unequip()
|
||||||
self.held_by.equipped_item = self
|
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:
|
def unequip(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -75,7 +81,7 @@ class Item(Entity):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_items() -> list:
|
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:
|
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
|
||||||
"""
|
"""
|
||||||
|
@ -225,20 +231,17 @@ class Sword(Weapon):
|
||||||
"""
|
"""
|
||||||
A basic weapon
|
A basic weapon
|
||||||
"""
|
"""
|
||||||
strength: int
|
def __init__(self, name: str = "sword", price: int = 20,
|
||||||
|
|
||||||
def __init__(self, name: str = "sword", price: int = 20, strength: int = 3,
|
|
||||||
*args, **kwargs):
|
*args, **kwargs):
|
||||||
super().__init__(name=name, price=price, *args, **kwargs)
|
super().__init__(name=name, price=price, *args, **kwargs)
|
||||||
self.name = name
|
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.
|
When a sword is equipped, the player gains strength.
|
||||||
"""
|
"""
|
||||||
super().equip()
|
super().equip()
|
||||||
self.held_by.strength += self.strength
|
self.held_by.strength += self.damage
|
||||||
|
|
||||||
def unequip(self) -> None:
|
def unequip(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -246,7 +249,28 @@ class Sword(Weapon):
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
super().unequip()
|
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):
|
class BodySnatchPotion(Item):
|
||||||
|
|
Loading…
Reference in New Issue