65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
class BaseMob:
|
|
"""Classe de base représentant un mob avec différentes caractéristiques."""
|
|
|
|
# Types possibles
|
|
FRIEND = 0
|
|
NEUTRAL = 1
|
|
ENEMY = 2
|
|
|
|
def __init__(self, name, max_pv, strength, protection, speed, mob_type):
|
|
"""
|
|
Initialisation d'un nouveau mob.
|
|
|
|
:param name: Nom du mob
|
|
:param max_pv: Points de vie maximum
|
|
:param strength: Force d'attaque
|
|
:param protection: Protection contre les dommages
|
|
:param speed: Vitesse d'attaque (nombre d'attaques par tour)
|
|
:param mob_type: Type de mob (0 = Ami, 1 = Neutre, 2 = Ennemi)
|
|
"""
|
|
self.name = name
|
|
self.max_pv = max_pv
|
|
self.current_pv = max_pv
|
|
self.strength = strength
|
|
self.protection = protection
|
|
self.speed = speed
|
|
self.mob_type = mob_type
|
|
|
|
def change_type(self, new_type):
|
|
"""
|
|
Change le type du mob.
|
|
|
|
:param new_type: Nouveau type (0 = Ami, 1 = Neutre, 2 = Ennemi)
|
|
"""
|
|
self.mob_type = new_type
|
|
|
|
def change_pv(self, pv_modifier):
|
|
"""
|
|
Modifie les points de vie actuels du mob.
|
|
|
|
:param pv_modifier: Valeur par laquelle modifier les PV (positive pour guérir, négative pour infliger des dégâts)
|
|
"""
|
|
if pv_modifier > 0:
|
|
# Ajout de PV (guérison)
|
|
self.current_pv = min(self.max_pv, self.current_pv + pv_modifier)
|
|
else:
|
|
# Retrait de PV (dommages)
|
|
damage = pv_modifier + self.protection
|
|
self.current_pv = max(0, self.current_pv + damage)
|
|
|
|
def perform_attack(self, target):
|
|
"""
|
|
Le mob attaque une cible.
|
|
|
|
:param target: Le mob cible de l'attaque
|
|
"""
|
|
for _ in range(self.speed):
|
|
if target.current_pv <= 0:
|
|
break
|
|
target.change_pv(-self.strength)
|
|
|
|
def __str__(self):
|
|
"""Retourne une représentation sous forme de chaîne du mob."""
|
|
return (f"{self.name} - PV: {self.current_pv}/{self.max_pv}, "
|
|
f"Force: {self.strength}, Protection: {self.protection}, "
|
|
f"Vitesse: {self.speed}") |