Added rings that can augment the player's statistics. Also added a new statistic : xp_buff, which helps the player level up sooner.

This commit is contained in:
eichhornchen
2021-01-06 11:44:52 +01:00
parent a9aeb9ca3a
commit 4ad7d6c37c
4 changed files with 81 additions and 5 deletions

View File

@ -108,7 +108,7 @@ class Item(Entity):
@staticmethod
def get_all_items() -> list:
return [BodySnatchPotion, Bomb, Heart, Shield, Sword,\
Chestplate, Helmet]
Chestplate, Helmet, RingCritical, RingXP]
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
"""
@ -361,3 +361,69 @@ class BodySnatchPotion(Item):
self.held_by.recalculate_paths()
self.held_by.inventory.remove(self)
class Ring(Item):
"""
A class of rings that boost the player's statistics.
"""
maxhealth: int
strength: int
intelligence: int
charisma: int
dexterity: int
constitution: int
critical: int
experience: float
def __init__(self, maxhealth: int = 0, strength: int = 0,\
intelligence: int = 0, charisma: int = 0,\
dexterity: int = 0, constitution: int = 0,\
critical: int = 0, experience: float = 0, *args, **kwargs):
super().__init__(*args, **kwargs)
self.maxhealth = maxhealth
self.strength = strength
self.intelligence = intelligence
self.charisma = charisma
self.dexterity = dexterity
self.constitution = constitution
self.critical = critical
self.experience = experience
def equip(self) -> None:
super().equip()
self.held_by.maxhealth += self.maxhealth
self.held_by.strength += self.strength
self.held_by.intelligence += self.intelligence
self.held_by.charisma += self.charisma
self.held_by.dexterity += self.dexterity
self.held_by.constitution += self.constitution
self.held_by.critical += self.critical
self.held_by.xp_buff += self.experience
def unequip(self) -> None:
super().unequip()
self.held_by.maxhealth -= self.maxhealth
self.held_by.strength -= self.strength
self.held_by.intelligence -= self.intelligence
self.held_by.charisma -= self.charisma
self.held_by.dexterity -= self.dexterity
self.held_by.constitution -= self.constitution
self.held_by.critical -= self.critical
self.held_by.xp_buff -= self.experience
def save_state(self) -> dict:
d = super().save_state()
d["constitution"] = self.constitution
return d
class RingCritical(Ring):
def __init__(self, name: str = "ring_of_critical_damage", price: int = 15,
critical: int = 20, *args, **kwargs):
super().__init__(name=name, price=price, critical=critical, \
*args, **kwargs)
class RingXP(Ring):
def __init__(self, name: str = "ring_of_more_experience", price: int = 25,
experience: float = 2, *args, **kwargs):
super().__init__(name=name, price=price, experience=experience, \
*args, **kwargs)

View File

@ -16,6 +16,7 @@ class Player(InventoryHolder, FightingEntity):
"""
current_xp: int = 0
max_xp: int = 10
xp_buff: float = 1
paths: Dict[Tuple[int, int], Tuple[int, int]]
equipped_main: Optional[Item]
equipped_secondary: Optional[Item]
@ -29,7 +30,7 @@ class Player(InventoryHolder, FightingEntity):
hazel: int = 42, equipped_main: Optional[Item] = None,
equipped_armor: Optional[Item] = None, critical: int = 5,\
equipped_secondary: Optional[Item] = None, \
equipped_helmet: Optional[Item] = None, \
equipped_helmet: Optional[Item] = None, xp_buff: float = 1,\
*args, **kwargs) -> None:
super().__init__(name=name, maxhealth=maxhealth, strength=strength,
intelligence=intelligence, charisma=charisma,
@ -37,6 +38,7 @@ class Player(InventoryHolder, FightingEntity):
level=level, critical=critical, *args, **kwargs)
self.current_xp = current_xp
self.max_xp = max_xp
self.xp_buff = xp_buff
self.inventory = self.translate_inventory(inventory or [])
self.paths = dict()
self.hazel = hazel
@ -82,7 +84,7 @@ class Player(InventoryHolder, FightingEntity):
Add some experience to the player.
If the required amount is reached, level up.
"""
self.current_xp += xp
self.current_xp += int(xp*self.xp_buff)
self.level_up()
def remove_from_inventory(self, obj: Item) -> None: