Fixes issue #54, repaired the attribution of the familiars' target

This commit is contained in:
eichhornchen 2020-12-21 14:23:58 +01:00
parent ed6457e94d
commit 505e0a4efb
1 changed files with 15 additions and 5 deletions

View File

@ -55,7 +55,7 @@ class Sunflower(FriendlyEntity):
return [_("Flower power!!"), _("The sun is warm today")] return [_("Flower power!!"), _("The sun is warm today")]
class Familiar(FightingEntity): class Familiar(FriendlyEntity): #FightingEntity
""" """
A friendly familiar that helps the player defeat monsters. A friendly familiar that helps the player defeat monsters.
""" """
@ -64,6 +64,13 @@ class Familiar(FightingEntity):
super().__init__(maxhealth=maxhealth, *args, **kwargs) super().__init__(maxhealth=maxhealth, *args, **kwargs)
self.target = None self.target = None
## @property
## def dialogue_option(self) -> list:
## """
## Debug function (to see if used in the real game)
## """
## return [_("My target is"+str(self.target))]
def act(self, p: Player, m: Map) -> None: def act(self, p: Player, m: Map) -> None:
""" """
By default, the familiar tries to stay at distance at most 2 of the By default, the familiar tries to stay at distance at most 2 of the
@ -71,10 +78,16 @@ class Familiar(FightingEntity):
and attacks it. and attacks it.
""" """
if self.target is None: if self.target is None:
#If the previous target is dead(or if there was no previous target)
#the familiar tries to get closer to the player.
self.target = p
elif self.target.dead:
self.target = p self.target = p
if self.target == p: if self.target == p:
#Look for monsters around the player to kill TOFIX : if monster is out
#of range, continue targetting player.
for entity in m.entities: for entity in m.entities:
if (self.y - entity.y) ** 2 + (self.x - entity.x) ** 2 <= 9 and\ if (p.y - entity.y) ** 2 + (p.x - entity.x) ** 2 <= 9 and\
isinstance(entity, Monster): isinstance(entity, Monster):
self.target = entity self.target = entity
entity.paths = dict() # Allows the paths to be calculated. entity.paths = dict() # Allows the paths to be calculated.
@ -93,9 +106,6 @@ class Familiar(FightingEntity):
if self.distance_squared(self.target) <= 1 and \ if self.distance_squared(self.target) <= 1 and \
not isinstance(self.target, Player): not isinstance(self.target, Player):
self.map.logs.add_message(self.hit(self.target)) self.map.logs.add_message(self.hit(self.target))
if self.target.dead:
self.target.paths = None
self.target = None
break break
else: else:
# Moves in a random direction # Moves in a random direction