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

@ -34,6 +34,8 @@ class TexturePack:
SHIELD: str SHIELD: str
CHESTPLATE: str CHESTPLATE: str
HELMET: str HELMET: str
RING_OF_MORE_EXPERIENCE: str
RING_OF_CRITICAL_DAMAGE: str
ASCII_PACK: "TexturePack" ASCII_PACK: "TexturePack"
SQUIRREL_PACK: "TexturePack" SQUIRREL_PACK: "TexturePack"
@ -64,7 +66,7 @@ TexturePack.ASCII_PACK = TexturePack(
entity_bg_color=curses.COLOR_BLACK, entity_bg_color=curses.COLOR_BLACK,
BODY_SNATCH_POTION='S', BODY_SNATCH_POTION='S',
BOMB='o', BOMB='ç',
EMPTY=' ', EMPTY=' ',
EXPLOSION='%', EXPLOSION='%',
FLOOR='.', FLOOR='.',
@ -83,6 +85,8 @@ TexturePack.ASCII_PACK = TexturePack(
EAGLE='µ', EAGLE='µ',
CHESTPLATE='(', CHESTPLATE='(',
HELMET='0', HELMET='0',
RING_OF_MORE_EXPERIENCE='o',
RING_OF_CRITICAL_DAMAGE='o',
) )
TexturePack.SQUIRREL_PACK = TexturePack( TexturePack.SQUIRREL_PACK = TexturePack(
@ -113,4 +117,6 @@ TexturePack.SQUIRREL_PACK = TexturePack(
EAGLE='🦅', EAGLE='🦅',
CHESTPLATE='🦺', CHESTPLATE='🦺',
HELMET='⛑️', HELMET='⛑️',
RING_OF_MORE_EXPERIENCE='💍',
RING_OF_CRITICAL_DAMAGE='💍',
) )

View File

@ -108,7 +108,7 @@ class Item(Entity):
@staticmethod @staticmethod
def get_all_items() -> list: def get_all_items() -> list:
return [BodySnatchPotion, Bomb, Heart, Shield, Sword,\ return [BodySnatchPotion, Bomb, Heart, Shield, Sword,\
Chestplate, Helmet] Chestplate, Helmet, RingCritical, RingXP]
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool: def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
""" """
@ -361,3 +361,69 @@ class BodySnatchPotion(Item):
self.held_by.recalculate_paths() self.held_by.recalculate_paths()
self.held_by.inventory.remove(self) 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 current_xp: int = 0
max_xp: int = 10 max_xp: int = 10
xp_buff: float = 1
paths: Dict[Tuple[int, int], Tuple[int, int]] paths: Dict[Tuple[int, int], Tuple[int, int]]
equipped_main: Optional[Item] equipped_main: Optional[Item]
equipped_secondary: Optional[Item] equipped_secondary: Optional[Item]
@ -29,7 +30,7 @@ class Player(InventoryHolder, FightingEntity):
hazel: int = 42, equipped_main: Optional[Item] = None, hazel: int = 42, equipped_main: Optional[Item] = None,
equipped_armor: Optional[Item] = None, critical: int = 5,\ equipped_armor: Optional[Item] = None, critical: int = 5,\
equipped_secondary: Optional[Item] = None, \ equipped_secondary: Optional[Item] = None, \
equipped_helmet: Optional[Item] = None, \ equipped_helmet: Optional[Item] = None, xp_buff: float = 1,\
*args, **kwargs) -> None: *args, **kwargs) -> None:
super().__init__(name=name, maxhealth=maxhealth, strength=strength, super().__init__(name=name, maxhealth=maxhealth, strength=strength,
intelligence=intelligence, charisma=charisma, intelligence=intelligence, charisma=charisma,
@ -37,6 +38,7 @@ class Player(InventoryHolder, FightingEntity):
level=level, critical=critical, *args, **kwargs) level=level, critical=critical, *args, **kwargs)
self.current_xp = current_xp self.current_xp = current_xp
self.max_xp = max_xp self.max_xp = max_xp
self.xp_buff = xp_buff
self.inventory = self.translate_inventory(inventory or []) self.inventory = self.translate_inventory(inventory or [])
self.paths = dict() self.paths = dict()
self.hazel = hazel self.hazel = hazel
@ -82,7 +84,7 @@ class Player(InventoryHolder, FightingEntity):
Add some experience to the player. Add some experience to the player.
If the required amount is reached, level up. If the required amount is reached, level up.
""" """
self.current_xp += xp self.current_xp += int(xp*self.xp_buff)
self.level_up() self.level_up()
def remove_from_inventory(self, obj: Item) -> None: def remove_from_inventory(self, obj: Item) -> None:

View File

@ -374,7 +374,7 @@ class Entity:
TeddyBear, GiantSeaEagle TeddyBear, GiantSeaEagle
from squirrelbattle.entities.friendly import Merchant, Sunflower from squirrelbattle.entities.friendly import Merchant, Sunflower
from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \ from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \
Heart, Sword, Shield, Chestplate, Helmet Heart, Sword, Shield, Chestplate, Helmet, RingCritical, RingXP
return { return {
"Tiger": Tiger, "Tiger": Tiger,
"Bomb": Bomb, "Bomb": Bomb,
@ -391,6 +391,8 @@ class Entity:
"Shield": Shield, "Shield": Shield,
"Chestplate": Chestplate, "Chestplate": Chestplate,
"Helmet": Helmet, "Helmet": Helmet,
"RingCritical": RingCritical,
"RingXP": RingXP,
} }
def save_state(self) -> dict: def save_state(self) -> dict: