Added a second scroll object closes #60

This commit is contained in:
eichhornchen 2021-01-08 16:14:40 +01:00
parent 5736c2300b
commit bde33e9232
4 changed files with 45 additions and 3 deletions

View File

@ -35,6 +35,7 @@ class TexturePack:
RING_OF_CRITICAL_DAMAGE: str RING_OF_CRITICAL_DAMAGE: str
RING_OF_MORE_EXPERIENCE: str RING_OF_MORE_EXPERIENCE: str
SCROLL_OF_DAMAGE: str SCROLL_OF_DAMAGE: str
SCROLL_OF_WEAKENING: str
SHIELD: str SHIELD: str
SUNFLOWER: str SUNFLOWER: str
SWORD: str SWORD: str
@ -97,6 +98,7 @@ TexturePack.ASCII_PACK = TexturePack(
TRUMPET='/', TRUMPET='/',
WALL='#', WALL='#',
SCROLL_OF_DAMAGE=']', SCROLL_OF_DAMAGE=']',
SCROLL_OF_WEAKENING=']',
) )
TexturePack.SQUIRREL_PACK = TexturePack( TexturePack.SQUIRREL_PACK = TexturePack(
@ -134,4 +136,5 @@ TexturePack.SQUIRREL_PACK = TexturePack(
TRUMPET='🎺', TRUMPET='🎺',
WALL='🧱', WALL='🧱',
SCROLL_OF_DAMAGE='📜', SCROLL_OF_DAMAGE='📜',
SCROLL_OF_WEAKENING='📜',
) )

View File

@ -80,7 +80,8 @@ class Item(Entity):
Returns the list of all item classes. Returns the list of all item classes.
""" """
return [BodySnatchPotion, Bomb, Heart, Shield, Sword,\ return [BodySnatchPotion, Bomb, Heart, Shield, Sword,\
Chestplate, Helmet, RingCritical, RingXP] Chestplate, Helmet, RingCritical, RingXP, \
ScrollofDamage, ScrollofWeakening]
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool: def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
""" """
@ -443,3 +444,25 @@ class ScrollofDamage(Item):
self.held_by.map.logs.add_message(entity.take_damage(\ self.held_by.map.logs.add_message(entity.take_damage(\
self.held_by, self.held_by.intelligence)) self.held_by, self.held_by.intelligence))
self.held_by.inventory.remove(self) self.held_by.inventory.remove(self)
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)
def use(self) -> None:
"""
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:
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)

View File

@ -31,6 +31,7 @@ class Monster(FightingEntity):
By default, a monster will move randomly where it is possible By default, a monster will move randomly where it is possible
If the player is closeby, the monster runs to the player. If the player is closeby, the monster runs to the player.
""" """
super().act(m)
target = None target = None
for entity in m.entities: for entity in m.entities:
if self.distance_squared(entity) <= 25 and \ if self.distance_squared(entity) <= 25 and \

View File

@ -630,7 +630,7 @@ class Entity:
Trumpet Trumpet
from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \ from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \
Heart, Sword, Shield, Chestplate, Helmet, RingCritical, RingXP, \ Heart, Sword, Shield, Chestplate, Helmet, RingCritical, RingXP, \
ScrollofDamage ScrollofDamage, ScrollofWeakening
return { return {
"Tiger": Tiger, "Tiger": Tiger,
"Bomb": Bomb, "Bomb": Bomb,
@ -651,6 +651,7 @@ class Entity:
"RingCritical": RingCritical, "RingCritical": RingCritical,
"RingXP": RingXP, "RingXP": RingXP,
"ScrollofDamage": ScrollofDamage, "ScrollofDamage": ScrollofDamage,
"ScrollofWeakening": ScrollofWeakening,
} }
def save_state(self) -> dict: def save_state(self) -> dict:
@ -693,6 +694,7 @@ class FightingEntity(Entity):
self.constitution = constitution self.constitution = constitution
self.level = level self.level = level
self.critical = critical self.critical = critical
self.effects = [] #effects are temporary buff or weakening of the stats.
@property @property
def dead(self) -> bool: def dead(self) -> bool:
@ -701,13 +703,26 @@ class FightingEntity(Entity):
""" """
return self.health <= 0 return self.health <= 0
def act(self, m: Map) -> None:
"""
Refreshes all current effects.
"""
for i in range(len(self.effects)):
self.effects[i][2] -= 1
l = self.effects[:]
for i in range(len(l)):
if l[i][2] <= 0:
setattr(self, l[i][0], getattr(self, l[i][0])-l[i][1])
self.effects.remove(l[i])
def hit(self, opponent: "FightingEntity") -> str: def hit(self, opponent: "FightingEntity") -> str:
""" """
The entity deals damage to the opponent The entity deals damage to the opponent
based on their respective stats. based on their respective stats.
""" """
diceroll = randint(1, 100) diceroll = randint(1, 100)
damage = self.strength damage = max(0, self.strength)
string = " " string = " "
if diceroll <= self.critical: # It is a critical hit if diceroll <= self.critical: # It is a critical hit
damage *= 4 damage *= 4