Merge branch 'master' into 'doc'
# Conflicts: # squirrelbattle/entities/items.py # squirrelbattle/interfaces.py
This commit is contained in:
@ -44,48 +44,17 @@ class Item(Entity):
|
||||
"""
|
||||
Indicates what should be done when the item is equipped.
|
||||
"""
|
||||
if isinstance(self, Chestplate):
|
||||
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
|
||||
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
|
||||
else:
|
||||
# Other objects are only equipped as secondary.
|
||||
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
|
||||
# Other objects are only equipped as secondary.
|
||||
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
|
||||
|
||||
def unequip(self) -> None:
|
||||
"""
|
||||
Indicates what should be done when the item is unequipped.
|
||||
"""
|
||||
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
|
||||
self.held_by.remove_from_inventory(self)
|
||||
self.held_by.add_to_inventory(self)
|
||||
|
||||
def hold(self, holder: InventoryHolder) -> None:
|
||||
@ -236,7 +205,6 @@ class Explosion(Item):
|
||||
"""
|
||||
The player can't hold an explosion.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class Weapon(Item):
|
||||
@ -261,7 +229,8 @@ class Weapon(Item):
|
||||
"""
|
||||
When a weapon is equipped, the player gains strength.
|
||||
"""
|
||||
super().equip()
|
||||
self.held_by.remove_from_inventory(self)
|
||||
self.held_by.equipped_main = self
|
||||
self.held_by.strength += self.damage
|
||||
|
||||
def unequip(self) -> None:
|
||||
@ -287,7 +256,7 @@ class Armor(Item):
|
||||
Class of items that increase the player's constitution.
|
||||
"""
|
||||
constitution: int
|
||||
|
||||
|
||||
def __init__(self, constitution: int, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.constitution = constitution
|
||||
@ -305,33 +274,45 @@ class Armor(Item):
|
||||
d["constitution"] = self.constitution
|
||||
return d
|
||||
|
||||
|
||||
class Shield(Armor):
|
||||
"""
|
||||
Class of shield items, they can be equipped in the other hand.
|
||||
"""
|
||||
|
||||
def __init__(self, name: str = "shield", constitution: int = 2,\
|
||||
def __init__(self, name: str = "shield", constitution: int = 2,
|
||||
price: int = 16, *args, **kwargs):
|
||||
super().__init__(name=name, constitution=constitution, *args, **kwargs)
|
||||
super().__init__(name=name, constitution=constitution, price=price,
|
||||
*args, **kwargs)
|
||||
|
||||
class Helmet(Armor):
|
||||
"""
|
||||
Class of helmet items, they can be equipped on the head.
|
||||
"""
|
||||
|
||||
def __init__(self, name: str = "helmet", constitution: int = 2, \
|
||||
def __init__(self, name: str = "helmet", constitution: int = 2,
|
||||
price: int = 18, *args, **kwargs):
|
||||
super().__init__(name=name, constitution=constitution, *args, **kwargs)
|
||||
super().__init__(name=name, constitution=constitution, price=price,
|
||||
*args, **kwargs)
|
||||
|
||||
def equip(self) -> None:
|
||||
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
|
||||
|
||||
class Chestplate(Armor):
|
||||
"""
|
||||
Class of chestplate items, they can be equipped on the body.
|
||||
"""
|
||||
|
||||
def __init__(self, name: str = "chestplate", constitution: int = 4,\
|
||||
def __init__(self, name: str = "chestplate", constitution: int = 4,
|
||||
price: int = 30, *args, **kwargs):
|
||||
super().__init__(name=name, constitution=constitution, *args, **kwargs)
|
||||
super().__init__(name=name, constitution=constitution, price=price,
|
||||
*args, **kwargs)
|
||||
|
||||
def equip(self) -> None:
|
||||
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
|
||||
|
||||
class BodySnatchPotion(Item):
|
||||
"""
|
||||
@ -366,6 +347,7 @@ class BodySnatchPotion(Item):
|
||||
|
||||
self.held_by.inventory.remove(self)
|
||||
|
||||
|
||||
class Ring(Item):
|
||||
"""
|
||||
A class of rings that boost the player's statistics.
|
||||
@ -379,9 +361,9 @@ class Ring(Item):
|
||||
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,\
|
||||
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
|
||||
@ -417,17 +399,26 @@ class Ring(Item):
|
||||
|
||||
def save_state(self) -> dict:
|
||||
d = super().save_state()
|
||||
d["maxhealth"] = self.maxhealth
|
||||
d["strength"] = self.strength
|
||||
d["intelligence"] = self.intelligence
|
||||
d["charisma"] = self.charisma
|
||||
d["dexterity"] = self.dexterity
|
||||
d["constitution"] = self.constitution
|
||||
d["critical"] = self.critical
|
||||
d["experience"] = self.experience
|
||||
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, \
|
||||
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, \
|
||||
super().__init__(name=name, price=price, experience=experience,
|
||||
*args, **kwargs)
|
||||
|
@ -94,9 +94,11 @@ class Rabbit(Monster):
|
||||
A rabbit monster.
|
||||
"""
|
||||
def __init__(self, name: str = "rabbit", strength: int = 1,
|
||||
maxhealth: int = 15, critical: int = 30, *args, **kwargs) -> None:
|
||||
maxhealth: int = 15, critical: int = 30,
|
||||
*args, **kwargs) -> None:
|
||||
super().__init__(name=name, strength=strength,
|
||||
maxhealth=maxhealth, critical=critical, *args, **kwargs)
|
||||
maxhealth=maxhealth, critical=critical,
|
||||
*args, **kwargs)
|
||||
|
||||
|
||||
class TeddyBear(Monster):
|
||||
@ -108,6 +110,7 @@ class TeddyBear(Monster):
|
||||
super().__init__(name=name, strength=strength,
|
||||
maxhealth=maxhealth, *args, **kwargs)
|
||||
|
||||
|
||||
class GiantSeaEagle(Monster):
|
||||
"""
|
||||
An eagle boss
|
||||
|
@ -26,10 +26,10 @@ class Player(InventoryHolder, FightingEntity):
|
||||
dexterity: int = 1, constitution: int = 1, level: int = 1,
|
||||
current_xp: int = 0, max_xp: int = 10, inventory: list = None,
|
||||
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, xp_buff: float = 1,\
|
||||
*args, **kwargs) -> None:
|
||||
equipped_armor: Optional[Item] = None, critical: int = 5,
|
||||
equipped_secondary: Optional[Item] = None,
|
||||
equipped_helmet: Optional[Item] = None, xp_buff: float = 1,
|
||||
vision: int = 5, *args, **kwargs) -> None:
|
||||
super().__init__(name=name, maxhealth=maxhealth, strength=strength,
|
||||
intelligence=intelligence, charisma=charisma,
|
||||
dexterity=dexterity, constitution=constitution,
|
||||
@ -40,18 +40,15 @@ class Player(InventoryHolder, FightingEntity):
|
||||
self.inventory = self.translate_inventory(inventory or [])
|
||||
self.paths = dict()
|
||||
self.hazel = hazel
|
||||
if isinstance(equipped_main, dict):
|
||||
equipped_main = self.dict_to_item(equipped_main)
|
||||
if isinstance(equipped_armor, dict):
|
||||
equipped_armor = self.dict_to_item(equipped_armor)
|
||||
if isinstance(equipped_secondary, dict):
|
||||
equipped_secondary = self.dict_to_item(equipped_secondary)
|
||||
if isinstance(equipped_helmet, dict):
|
||||
equipped_helmet = self.dict_to_item(equipped_helmet)
|
||||
self.equipped_main = equipped_main
|
||||
self.equipped_armor = equipped_armor
|
||||
self.equipped_secondary = equipped_secondary
|
||||
self.equipped_helmet = equipped_helmet
|
||||
self.equipped_main = self.dict_to_item(equipped_main) \
|
||||
if isinstance(equipped_main, dict) else equipped_main
|
||||
self.equipped_armor = self.dict_to_item(equipped_armor) \
|
||||
if isinstance(equipped_armor, dict) else equipped_armor
|
||||
self.equipped_secondary = self.dict_to_item(equipped_secondary) \
|
||||
if isinstance(equipped_secondary, dict) else equipped_secondary
|
||||
self.equipped_helmet = self.dict_to_item(equipped_helmet) \
|
||||
if isinstance(equipped_helmet, dict) else equipped_helmet
|
||||
self.vision = vision
|
||||
|
||||
def move(self, y: int, x: int) -> None:
|
||||
"""
|
||||
@ -62,6 +59,7 @@ class Player(InventoryHolder, FightingEntity):
|
||||
self.map.currenty = y
|
||||
self.map.currentx = x
|
||||
self.recalculate_paths()
|
||||
self.map.compute_visibility(self.y, self.x, self.vision)
|
||||
|
||||
def level_up(self) -> None:
|
||||
"""
|
||||
@ -82,7 +80,7 @@ class Player(InventoryHolder, FightingEntity):
|
||||
Adds some experience to the player.
|
||||
If the required amount is reached, the player levels up.
|
||||
"""
|
||||
self.current_xp += int(xp*self.xp_buff)
|
||||
self.current_xp += int(xp * self.xp_buff)
|
||||
self.level_up()
|
||||
|
||||
def remove_from_inventory(self, obj: Item) -> None:
|
||||
|
Reference in New Issue
Block a user