2020-11-27 15:33:17 +00:00
|
|
|
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-12-05 13:20:58 +00:00
|
|
|
from random import choice, randint
|
2020-11-11 15:47:19 +00:00
|
|
|
from typing import Optional
|
|
|
|
|
2020-12-11 16:20:50 +00:00
|
|
|
from ..interfaces import Entity, FightingEntity, Map, InventoryHolder
|
2020-12-04 16:10:23 +00:00
|
|
|
from ..translations import gettext as _
|
2020-11-06 14:33:26 +00:00
|
|
|
|
2020-10-23 14:51:48 +00:00
|
|
|
|
|
|
|
class Item(Entity):
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
A class for items.
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-11-06 14:33:26 +00:00
|
|
|
held: bool
|
2020-12-11 16:28:16 +00:00
|
|
|
held_by: Optional[InventoryHolder]
|
2020-12-11 15:49:17 +00:00
|
|
|
price: int
|
2020-10-23 14:51:48 +00:00
|
|
|
|
2020-12-11 16:28:16 +00:00
|
|
|
def __init__(self, held: bool = False,
|
|
|
|
held_by: Optional[InventoryHolder] = None,
|
2020-12-11 17:17:08 +00:00
|
|
|
price: int = 2, *args, **kwargs):
|
2020-11-06 14:33:26 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
2020-11-18 13:54:21 +00:00
|
|
|
self.held = held
|
|
|
|
self.held_by = held_by
|
2020-12-11 15:49:17 +00:00
|
|
|
self.price = price
|
2020-11-06 14:33:26 +00:00
|
|
|
|
2020-12-04 15:53:27 +00:00
|
|
|
def drop(self) -> None:
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
The item is dropped from the inventory onto the floor.
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-11-11 22:41:06 +00:00
|
|
|
if self.held:
|
2020-12-18 16:57:42 +00:00
|
|
|
self.held_by.remove_from_inventory(self)
|
2020-12-11 17:33:47 +00:00
|
|
|
self.held_by.map.add_entity(self)
|
2020-12-04 15:53:27 +00:00
|
|
|
self.move(self.held_by.y, self.held_by.x)
|
2020-11-11 22:41:06 +00:00
|
|
|
self.held = False
|
|
|
|
self.held_by = None
|
2020-12-04 15:53:27 +00:00
|
|
|
|
|
|
|
def use(self) -> None:
|
|
|
|
"""
|
|
|
|
Indicates what should be done when the item is used.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def equip(self) -> None:
|
|
|
|
"""
|
|
|
|
Indicates what should be done when the item is equipped.
|
|
|
|
"""
|
2021-01-06 09:46:36 +00:00
|
|
|
if isinstance(self, Chestplate):
|
2020-12-18 19:01:52 +00:00
|
|
|
if self.held_by.equipped_armor:
|
|
|
|
self.held_by.equipped_armor.unequip()
|
|
|
|
self.held_by.remove_from_inventory(self)
|
|
|
|
self.held_by.equipped_armor = self
|
2021-01-06 09:46:36 +00:00
|
|
|
elif isinstance(self, Helmet):
|
|
|
|
if self.held_by.equipped_helmet:
|
|
|
|
self.held_by.equipped_helmet.unequip()
|
|
|
|
self.held_by.remove_from_inventory(self)
|
|
|
|
self.held_by.equipped_helmet = self
|
|
|
|
elif isinstance(self, Weapon):
|
|
|
|
if self.held_by.equipped_main:
|
|
|
|
if self.held_by.equipped_secondary:
|
|
|
|
self.held_by.equipped_secondary.unequip()
|
|
|
|
self.held_by.remove_from_inventory(self)
|
|
|
|
self.held_by.equipped_secondary = self
|
|
|
|
# For weapons, they are equipped as main only if main is empty.
|
|
|
|
else:
|
|
|
|
self.held_by.remove_from_inventory(self)
|
|
|
|
self.held_by.equipped_main = self
|
2020-12-18 19:01:52 +00:00
|
|
|
else:
|
2021-01-06 09:46:36 +00:00
|
|
|
# Other objects are only equipped as secondary.
|
|
|
|
if self.held_by.equipped_secondary:
|
|
|
|
self.held_by.equipped_secondary.unequip()
|
2020-12-18 19:01:52 +00:00
|
|
|
self.held_by.remove_from_inventory(self)
|
2021-01-06 09:46:36 +00:00
|
|
|
self.held_by.equipped_secondary = self
|
2020-11-06 14:33:26 +00:00
|
|
|
|
2020-12-18 16:30:03 +00:00
|
|
|
def unequip(self) -> None:
|
|
|
|
"""
|
|
|
|
Indicates what should be done when the item is unequipped.
|
|
|
|
"""
|
2021-01-06 09:46:36 +00:00
|
|
|
if isinstance(self, Chestplate):
|
|
|
|
self.held_by.equipped_armor = None
|
|
|
|
elif isinstance(self, Helmet):
|
|
|
|
self.held_by.equipped_helmet = None
|
|
|
|
elif isinstance(self, Weapon):
|
|
|
|
if self.held_by.equipped_main == self:
|
|
|
|
self.held_by.equipped_main = None
|
|
|
|
else:
|
|
|
|
self.held_by.equipped_secondary = None
|
|
|
|
else:
|
|
|
|
self.held_by.equipped_secondary = None
|
2020-12-18 16:30:03 +00:00
|
|
|
self.held_by.add_to_inventory(self)
|
2020-11-06 14:33:26 +00:00
|
|
|
|
2020-12-18 16:30:03 +00:00
|
|
|
def hold(self, holder: InventoryHolder) -> None:
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
The item is taken from the floor and put into the inventory.
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-10-23 14:51:48 +00:00
|
|
|
self.held = True
|
2020-12-18 16:30:03 +00:00
|
|
|
self.held_by = holder
|
2020-12-11 17:33:47 +00:00
|
|
|
self.held_by.map.remove_entity(self)
|
2020-12-18 16:30:03 +00:00
|
|
|
holder.add_to_inventory(self)
|
2020-10-23 16:02:57 +00:00
|
|
|
|
2020-11-18 23:10:37 +00:00
|
|
|
def save_state(self) -> dict:
|
2020-11-18 21:42:46 +00:00
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
Saves the state of the item into a dictionary.
|
2020-11-18 21:42:46 +00:00
|
|
|
"""
|
|
|
|
d = super().save_state()
|
|
|
|
d["held"] = self.held
|
2020-11-18 23:10:37 +00:00
|
|
|
return d
|
2020-11-18 21:42:46 +00:00
|
|
|
|
2020-12-07 20:13:55 +00:00
|
|
|
@staticmethod
|
2020-12-07 19:54:53 +00:00
|
|
|
def get_all_items() -> list:
|
2020-12-13 20:29:25 +00:00
|
|
|
"""
|
|
|
|
Returns the list of all item classes.
|
|
|
|
"""
|
2021-01-06 09:46:36 +00:00
|
|
|
return [BodySnatchPotion, Bomb, Heart, Shield, Sword,\
|
2021-01-06 10:44:52 +00:00
|
|
|
Chestplate, Helmet, RingCritical, RingXP]
|
2020-11-18 21:42:46 +00:00
|
|
|
|
2020-12-11 16:28:16 +00:00
|
|
|
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
|
2020-12-11 15:49:17 +00:00
|
|
|
"""
|
|
|
|
Does all necessary actions when an object is to be sold.
|
2020-12-11 16:06:30 +00:00
|
|
|
Is overwritten by some classes that cannot exist in the player's
|
2020-12-13 20:29:25 +00:00
|
|
|
inventory.
|
2020-12-11 15:49:17 +00:00
|
|
|
"""
|
2020-12-11 16:06:30 +00:00
|
|
|
if buyer.hazel >= self.price:
|
2020-12-11 16:28:16 +00:00
|
|
|
self.hold(buyer)
|
2020-12-11 15:49:17 +00:00
|
|
|
seller.remove_from_inventory(self)
|
|
|
|
buyer.change_hazel_balance(-self.price)
|
|
|
|
seller.change_hazel_balance(self.price)
|
|
|
|
return True
|
2020-12-11 16:06:30 +00:00
|
|
|
else:
|
2020-12-11 15:49:17 +00:00
|
|
|
return False
|
2020-11-06 14:33:26 +00:00
|
|
|
|
|
|
|
|
2020-11-11 15:23:27 +00:00
|
|
|
class Heart(Item):
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
A heart item to return health to the player.
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-11-18 13:54:21 +00:00
|
|
|
healing: int
|
|
|
|
|
2020-12-11 16:06:30 +00:00
|
|
|
def __init__(self, name: str = "heart", healing: int = 5, price: int = 3,
|
|
|
|
*args, **kwargs):
|
2020-12-11 15:49:17 +00:00
|
|
|
super().__init__(name=name, price=price, *args, **kwargs)
|
2020-11-18 13:54:21 +00:00
|
|
|
self.healing = healing
|
2020-11-11 15:47:19 +00:00
|
|
|
|
2020-12-11 16:20:50 +00:00
|
|
|
def hold(self, entity: InventoryHolder) -> None:
|
2020-11-11 15:47:19 +00:00
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
When holding a heart, the player is healed and
|
|
|
|
the item is not put in the inventory.
|
2020-11-11 15:47:19 +00:00
|
|
|
"""
|
2020-12-11 16:20:50 +00:00
|
|
|
entity.health = min(entity.maxhealth, entity.health + self.healing)
|
|
|
|
entity.map.remove_entity(self)
|
2020-11-11 15:23:27 +00:00
|
|
|
|
2020-11-19 00:11:11 +00:00
|
|
|
def save_state(self) -> dict:
|
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
Saves the state of the heart into a dictionary.
|
2020-11-19 00:11:11 +00:00
|
|
|
"""
|
|
|
|
d = super().save_state()
|
|
|
|
d["healing"] = self.healing
|
|
|
|
return d
|
|
|
|
|
2020-11-11 15:23:27 +00:00
|
|
|
|
2020-10-23 16:02:57 +00:00
|
|
|
class Bomb(Item):
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-11-18 13:54:21 +00:00
|
|
|
A bomb item intended to deal damage to enemies at long range
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-11-06 14:33:26 +00:00
|
|
|
damage: int = 5
|
|
|
|
exploding: bool
|
2020-12-18 16:30:03 +00:00
|
|
|
owner: Optional["InventoryHolder"]
|
2020-12-04 17:16:46 +00:00
|
|
|
tick: int
|
2020-10-23 16:02:57 +00:00
|
|
|
|
2020-12-05 13:25:22 +00:00
|
|
|
def __init__(self, name: str = "bomb", damage: int = 5,
|
2020-12-11 15:49:17 +00:00
|
|
|
exploding: bool = False, price: int = 4, *args, **kwargs):
|
|
|
|
super().__init__(name=name, price=price, *args, **kwargs)
|
2020-11-18 13:54:21 +00:00
|
|
|
self.damage = damage
|
|
|
|
self.exploding = exploding
|
2020-12-04 16:10:23 +00:00
|
|
|
self.tick = 4
|
2020-12-04 17:16:46 +00:00
|
|
|
self.owner = None
|
2020-10-23 16:02:57 +00:00
|
|
|
|
2020-12-04 15:53:27 +00:00
|
|
|
def use(self) -> None:
|
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
When the bomb is used, it is thrown and then it explodes.
|
2020-12-04 15:53:27 +00:00
|
|
|
"""
|
|
|
|
if self.held:
|
2020-12-04 16:10:23 +00:00
|
|
|
self.owner = self.held_by
|
2020-12-04 15:53:27 +00:00
|
|
|
super().drop()
|
|
|
|
self.exploding = True
|
2020-11-06 14:33:26 +00:00
|
|
|
|
|
|
|
def act(self, m: Map) -> None:
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
Special exploding action of the bomb.
|
2020-11-18 11:27:59 +00:00
|
|
|
"""
|
2020-10-23 16:02:57 +00:00
|
|
|
if self.exploding:
|
2020-12-04 15:53:27 +00:00
|
|
|
if self.tick > 0:
|
2020-12-04 16:10:23 +00:00
|
|
|
# The bomb will explode in <tick> moves
|
2020-12-04 15:53:27 +00:00
|
|
|
self.tick -= 1
|
|
|
|
else:
|
2020-12-04 16:10:23 +00:00
|
|
|
# The bomb is exploding.
|
|
|
|
# Each entity that is close to the bomb takes damages.
|
|
|
|
# The player earn XP if the entity was killed.
|
|
|
|
log_message = _("Bomb is exploding.")
|
2020-12-04 15:53:27 +00:00
|
|
|
for e in m.entities.copy():
|
2020-12-04 16:10:23 +00:00
|
|
|
if abs(e.x - self.x) + abs(e.y - self.y) <= 3 and \
|
2020-12-04 15:53:27 +00:00
|
|
|
isinstance(e, FightingEntity):
|
2020-12-04 16:10:23 +00:00
|
|
|
log_message += " " + e.take_damage(self, self.damage)
|
|
|
|
if e.dead:
|
|
|
|
self.owner.add_xp(randint(3, 7))
|
|
|
|
m.logs.add_message(log_message)
|
2020-12-04 15:53:27 +00:00
|
|
|
m.entities.remove(self)
|
2020-11-19 00:11:11 +00:00
|
|
|
|
2020-12-12 15:50:01 +00:00
|
|
|
# Add sparkles where the bomb exploded.
|
|
|
|
explosion = Explosion(y=self.y, x=self.x)
|
|
|
|
self.map.add_entity(explosion)
|
|
|
|
|
2020-11-19 00:11:11 +00:00
|
|
|
def save_state(self) -> dict:
|
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
Saves the state of the bomb into a dictionary.
|
2020-11-19 00:11:11 +00:00
|
|
|
"""
|
|
|
|
d = super().save_state()
|
|
|
|
d["exploding"] = self.exploding
|
|
|
|
d["damage"] = self.damage
|
|
|
|
return d
|
2020-12-05 13:20:58 +00:00
|
|
|
|
|
|
|
|
2020-12-12 15:50:01 +00:00
|
|
|
class Explosion(Item):
|
|
|
|
"""
|
|
|
|
When a bomb explodes, the explosion is displayed.
|
|
|
|
"""
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(name="explosion", *args, **kwargs)
|
|
|
|
|
|
|
|
def act(self, m: Map) -> None:
|
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
The bomb disappears after exploding.
|
2020-12-12 15:50:01 +00:00
|
|
|
"""
|
|
|
|
m.remove_entity(self)
|
|
|
|
|
|
|
|
def hold(self, player: InventoryHolder) -> None:
|
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
The player can't hold an explosion.
|
2020-12-12 15:50:01 +00:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-11-27 16:56:01 +00:00
|
|
|
class Weapon(Item):
|
|
|
|
"""
|
|
|
|
Non-throwable items that improve player damage
|
|
|
|
"""
|
|
|
|
damage: int
|
|
|
|
|
|
|
|
def __init__(self, damage: int = 3, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.damage = damage
|
|
|
|
|
|
|
|
def save_state(self) -> dict:
|
|
|
|
"""
|
|
|
|
Saves the state of the weapon into a dictionary
|
|
|
|
"""
|
|
|
|
d = super().save_state()
|
|
|
|
d["damage"] = self.damage
|
|
|
|
return d
|
|
|
|
|
2021-01-06 09:46:36 +00:00
|
|
|
def equip(self) -> None:
|
2020-12-18 16:39:11 +00:00
|
|
|
"""
|
2021-01-05 18:18:25 +00:00
|
|
|
When a weapon is equipped, the player gains strength.
|
2020-12-18 16:39:11 +00:00
|
|
|
"""
|
|
|
|
super().equip()
|
2020-12-18 19:01:52 +00:00
|
|
|
self.held_by.strength += self.damage
|
2020-12-18 16:39:11 +00:00
|
|
|
|
|
|
|
def unequip(self) -> None:
|
|
|
|
"""
|
2021-01-05 18:18:25 +00:00
|
|
|
Remove the strength earned by the weapon.
|
2020-12-18 16:39:11 +00:00
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
super().unequip()
|
2020-12-18 19:01:52 +00:00
|
|
|
self.held_by.strength -= self.damage
|
|
|
|
|
2020-12-07 20:22:06 +00:00
|
|
|
|
|
|
|
class Sword(Weapon):
|
2020-11-27 16:56:01 +00:00
|
|
|
"""
|
|
|
|
A basic weapon
|
|
|
|
"""
|
2021-01-05 18:18:25 +00:00
|
|
|
def __init__(self, name: str = "sword", price: int = 20,
|
|
|
|
*args, **kwargs):
|
2020-12-11 15:49:17 +00:00
|
|
|
super().__init__(name=name, price=price, *args, **kwargs)
|
2021-01-05 18:18:25 +00:00
|
|
|
|
|
|
|
|
2021-01-06 09:46:36 +00:00
|
|
|
class Armor(Item):
|
|
|
|
"""
|
|
|
|
Class of items that increase the player's constitution.
|
|
|
|
"""
|
2020-12-18 19:01:52 +00:00
|
|
|
constitution: int
|
2021-01-06 09:46:36 +00:00
|
|
|
|
|
|
|
def __init__(self, constitution: int, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2020-12-18 19:01:52 +00:00
|
|
|
self.constitution = constitution
|
|
|
|
|
2021-01-06 09:46:36 +00:00
|
|
|
def equip(self) -> None:
|
|
|
|
super().equip()
|
2020-12-18 19:01:52 +00:00
|
|
|
self.held_by.constitution += self.constitution
|
|
|
|
|
|
|
|
def unequip(self) -> None:
|
|
|
|
super().unequip()
|
|
|
|
self.held_by.constitution -= self.constitution
|
|
|
|
|
|
|
|
def save_state(self) -> dict:
|
|
|
|
d = super().save_state()
|
|
|
|
d["constitution"] = self.constitution
|
|
|
|
return d
|
2020-12-07 20:22:06 +00:00
|
|
|
|
2021-01-06 09:46:36 +00:00
|
|
|
class Shield(Armor):
|
|
|
|
"""
|
|
|
|
Class of shield items, they can be equipped in the other hand.
|
|
|
|
"""
|
|
|
|
|
2021-01-06 10:13:17 +00:00
|
|
|
def __init__(self, name: str = "shield", constitution: int = 2,\
|
2021-01-06 16:57:23 +00:00
|
|
|
price: int = 16, *args, **kwargs):
|
2021-01-06 10:13:17 +00:00
|
|
|
super().__init__(name=name, constitution=constitution, *args, **kwargs)
|
2021-01-06 09:46:36 +00:00
|
|
|
|
|
|
|
class Helmet(Armor):
|
|
|
|
"""
|
|
|
|
Class of helmet items, they can be equipped on the head.
|
|
|
|
"""
|
|
|
|
|
2021-01-06 10:13:17 +00:00
|
|
|
def __init__(self, name: str = "helmet", constitution: int = 2, \
|
2021-01-06 16:57:23 +00:00
|
|
|
price: int = 18, *args, **kwargs):
|
2021-01-06 10:13:17 +00:00
|
|
|
super().__init__(name=name, constitution=constitution, *args, **kwargs)
|
2021-01-06 09:46:36 +00:00
|
|
|
|
|
|
|
class Chestplate(Armor):
|
|
|
|
"""
|
|
|
|
Class of chestplate items, they can be equipped on the body.
|
|
|
|
"""
|
|
|
|
|
2021-01-06 10:13:17 +00:00
|
|
|
def __init__(self, name: str = "chestplate", constitution: int = 4,\
|
2021-01-06 16:57:23 +00:00
|
|
|
price: int = 30, *args, **kwargs):
|
2021-01-06 10:13:17 +00:00
|
|
|
super().__init__(name=name, constitution=constitution, *args, **kwargs)
|
2020-12-07 20:22:06 +00:00
|
|
|
|
2020-12-05 13:20:58 +00:00
|
|
|
|
|
|
|
class BodySnatchPotion(Item):
|
|
|
|
"""
|
|
|
|
The body-snatch potion allows to exchange all characteristics with a random
|
|
|
|
other entity.
|
|
|
|
"""
|
|
|
|
|
2020-12-11 16:06:30 +00:00
|
|
|
def __init__(self, name: str = "body_snatch_potion", price: int = 14,
|
|
|
|
*args, **kwargs):
|
2020-12-11 15:49:17 +00:00
|
|
|
super().__init__(name=name, price=price, *args, **kwargs)
|
2020-12-05 13:20:58 +00:00
|
|
|
|
|
|
|
def use(self) -> None:
|
|
|
|
"""
|
|
|
|
Find a valid random entity, then exchange characteristics.
|
|
|
|
"""
|
|
|
|
valid_entities = self.held_by.map.find_entities(FightingEntity)
|
|
|
|
valid_entities.remove(self.held_by)
|
|
|
|
entity = choice(valid_entities)
|
|
|
|
entity_state = entity.save_state()
|
|
|
|
player_state = self.held_by.save_state()
|
|
|
|
self.held_by.__dict__.update(entity_state)
|
|
|
|
entity.__dict__.update(player_state)
|
|
|
|
self.held_by.map.currenty, self.held_by.map.currentx = self.held_by.y,\
|
|
|
|
self.held_by.x
|
|
|
|
|
2020-12-05 13:47:54 +00:00
|
|
|
self.held_by.map.logs.add_message(
|
|
|
|
_("{player} exchanged its body with {entity}.").format(
|
|
|
|
player=self.held_by.translated_name.capitalize(),
|
|
|
|
entity=entity.translated_name))
|
|
|
|
|
2020-12-05 13:48:43 +00:00
|
|
|
self.held_by.recalculate_paths()
|
|
|
|
|
2020-12-05 13:20:58 +00:00
|
|
|
self.held_by.inventory.remove(self)
|
2021-01-06 10:44:52 +00:00
|
|
|
|
|
|
|
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)
|