Added a Bow, related to #64

This commit is contained in:
eichhornchen
2021-01-08 18:06:26 +01:00
parent bde33e9232
commit f6210a6356
7 changed files with 105 additions and 6 deletions

View File

@ -40,6 +40,11 @@ class Item(Entity):
Indicates what should be done when the item is used.
"""
def throw(self, direction: int) -> None:
"""
Indicates what should be done when the item is thrown.
"""
def equip(self) -> None:
"""
Indicates what should be done when the item is equipped.
@ -81,7 +86,7 @@ class Item(Entity):
"""
return [BodySnatchPotion, Bomb, Heart, Shield, Sword,\
Chestplate, Helmet, RingCritical, RingXP, \
ScrollofDamage, ScrollofWeakening]
ScrollofDamage, ScrollofWeakening, Ruler, Bow]
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
"""
@ -251,6 +256,13 @@ class Sword(Weapon):
*args, **kwargs):
super().__init__(name=name, price=price, *args, **kwargs)
class Ruler(Weapon):
"""
A basic weapon
"""
def __init__(self, name: str = "ruler", price: int = 2,
damage: int = 1, *args, **kwargs):
super().__init__(name=name, price=price, damage=damage, *args, **kwargs)
class Armor(Item):
"""
@ -428,7 +440,6 @@ class ScrollofDamage(Item):
"""
A scroll that, when used, deals damage to all entities in a certain radius.
"""
def __init__(self, name: str = "scroll_of_damage", price: int = 18,
*args, **kwargs):
super().__init__(name=name, price=price, *args, **kwargs)
@ -449,7 +460,6 @@ class ScrollofWeakening(Item):
"""
A scroll that, when used, reduces the damage of the ennemies for 3 turn.
"""
def __init__(self, name: str = "scroll_of_weakening", price: int = 13,
*args, **kwargs):
super().__init__(name=name, price=price, *args, **kwargs)
@ -459,10 +469,52 @@ class ScrollofWeakening(Item):
Find all entities and reduce their damage.
"""
for entity in self.held_by.map.entities:
if entity.is_fighting_entity(): #and not entity == self.held_by:
if entity.is_fighting_entity() and not entity == self.held_by:
entity.strength = entity.strength - max(1, self.held_by.intelligence//2)
entity.effects.append(["strength", \
-max(1, self.held_by.intelligence//2), 3])
self.held_by.map.logs.add_message(\
_(f"The ennemies have -{max(1, self.held_by.intelligence//2)} strength for 3 turns"))
self.held_by.inventory.remove(self)
class Bow(Item):
"""
A type of throwable weapon that deals damage based on the player's dexterity.
"""
def __init__(self, name: str = "bow", price: int = 22, damage = 4,
rang = 3, *args, **kwargs):
super().__init__(name=name, price=price, *args, **kwargs)
self.damage = damage
self.range = rang
def throw(self, direction: int) -> str:
to_kill = None
for entity in self.held_by.map.entities:
if entity.is_fighting_entity():
if direction == 0 and self.held_by.x == entity.x \
and self.held_by.y-entity.y>0 and \
self.held_by.y-entity.y<=self.range:
to_kill = entity
elif direction == 2 and self.held_by.x == entity.x \
and entity.y-self.held_by.y>0 and \
entity.y-self.held_by.y<=self.range:
to_kill = entity
elif direction == 1 and self.held_by.y == entity.y \
and entity.x-self.held_by.x>0 and \
entity.x-self.held_by.x<=self.range:
to_kill = entity
elif direction == 3 and self.held_by.y == entity.y \
and self.held_by.x-entity.x>0 and \
self.held_by.x-entity.x<=self.range:
to_kill = entity
if to_kill:
self.held_by.map.logs.add_message(_("{name} is shot by an arrow.")\
.format(name=to_kill.translated_name.capitalize())+ " " \
+ to_kill.take_damage(self.held_by, self.damage + self.held_by.dexterity))
def equip(self) -> None:
"""
Equip the bow.
"""
self.held_by.remove_from_inventory(self)
self.held_by.equipped_main = self