From 4ad7d6c37cca74080536c9a1f684d6138ce664b7 Mon Sep 17 00:00:00 2001 From: eichhornchen Date: Wed, 6 Jan 2021 11:44:52 +0100 Subject: [PATCH] Added rings that can augment the player's statistics. Also added a new statistic : xp_buff, which helps the player level up sooner. --- squirrelbattle/display/texturepack.py | 8 +++- squirrelbattle/entities/items.py | 68 ++++++++++++++++++++++++++- squirrelbattle/entities/player.py | 6 ++- squirrelbattle/interfaces.py | 4 +- 4 files changed, 81 insertions(+), 5 deletions(-) diff --git a/squirrelbattle/display/texturepack.py b/squirrelbattle/display/texturepack.py index 8d4e785..bd4b563 100644 --- a/squirrelbattle/display/texturepack.py +++ b/squirrelbattle/display/texturepack.py @@ -34,6 +34,8 @@ class TexturePack: SHIELD: str CHESTPLATE: str HELMET: str + RING_OF_MORE_EXPERIENCE: str + RING_OF_CRITICAL_DAMAGE: str ASCII_PACK: "TexturePack" SQUIRREL_PACK: "TexturePack" @@ -64,7 +66,7 @@ TexturePack.ASCII_PACK = TexturePack( entity_bg_color=curses.COLOR_BLACK, BODY_SNATCH_POTION='S', - BOMB='o', + BOMB='รง', EMPTY=' ', EXPLOSION='%', FLOOR='.', @@ -83,6 +85,8 @@ TexturePack.ASCII_PACK = TexturePack( EAGLE='ยต', CHESTPLATE='(', HELMET='0', + RING_OF_MORE_EXPERIENCE='o', + RING_OF_CRITICAL_DAMAGE='o', ) TexturePack.SQUIRREL_PACK = TexturePack( @@ -113,4 +117,6 @@ TexturePack.SQUIRREL_PACK = TexturePack( EAGLE='๐Ÿฆ…', CHESTPLATE='๐Ÿฆบ', HELMET='โ›‘๏ธ', + RING_OF_MORE_EXPERIENCE='๐Ÿ’', + RING_OF_CRITICAL_DAMAGE='๐Ÿ’', ) diff --git a/squirrelbattle/entities/items.py b/squirrelbattle/entities/items.py index 05654e9..336d3e5 100644 --- a/squirrelbattle/entities/items.py +++ b/squirrelbattle/entities/items.py @@ -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) diff --git a/squirrelbattle/entities/player.py b/squirrelbattle/entities/player.py index a0ddd6c..854bd93 100644 --- a/squirrelbattle/entities/player.py +++ b/squirrelbattle/entities/player.py @@ -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: diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index cc5b36e..b6a3a51 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -374,7 +374,7 @@ class Entity: TeddyBear, GiantSeaEagle from squirrelbattle.entities.friendly import Merchant, Sunflower from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \ - Heart, Sword, Shield, Chestplate, Helmet + Heart, Sword, Shield, Chestplate, Helmet, RingCritical, RingXP return { "Tiger": Tiger, "Bomb": Bomb, @@ -391,6 +391,8 @@ class Entity: "Shield": Shield, "Chestplate": Chestplate, "Helmet": Helmet, + "RingCritical": RingCritical, + "RingXP": RingXP, } def save_state(self) -> dict: