Friendly entities can now talk to the player, a sunflower entity was added to test this new feature. Related to issue #22
This commit is contained in:
parent
d987e60006
commit
fbd9f0045b
|
@ -112,4 +112,4 @@ class VariableMenuDisplay(MenuDisplay):
|
||||||
def values(self) -> List[str]:
|
def values(self) -> List[str]:
|
||||||
return [a[1][1] + (" : "
|
return [a[1][1] + (" : "
|
||||||
+ (a[1][0])
|
+ (a[1][0])
|
||||||
if a[1][0] else "" for a in self.menu.values]
|
if a[1][0] else "") for a in self.menu.values]
|
||||||
|
|
|
@ -54,6 +54,7 @@ TexturePack.ASCII_PACK = TexturePack(
|
||||||
BEAVER='_',
|
BEAVER='_',
|
||||||
TEDDY_BEAR='8',
|
TEDDY_BEAR='8',
|
||||||
MERCHANT='M',
|
MERCHANT='M',
|
||||||
|
SUNFLOWER='I',
|
||||||
)
|
)
|
||||||
|
|
||||||
TexturePack.SQUIRREL_PACK = TexturePack(
|
TexturePack.SQUIRREL_PACK = TexturePack(
|
||||||
|
@ -74,4 +75,5 @@ TexturePack.SQUIRREL_PACK = TexturePack(
|
||||||
BEAVER='🦫',
|
BEAVER='🦫',
|
||||||
TEDDY_BEAR='🧸',
|
TEDDY_BEAR='🧸',
|
||||||
MERCHANT='🦜',
|
MERCHANT='🦜',
|
||||||
|
SUNFLOWER='🌻',
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
from ..interfaces import FriendlyEntity, Map
|
from ..interfaces import FriendlyEntity, Map
|
||||||
|
from .player import Player
|
||||||
|
|
||||||
class Merchant(FriendlyEntity) :
|
class Merchant(FriendlyEntity) :
|
||||||
"""
|
"""
|
||||||
The class for merchants in the dungeon
|
The class for merchants in the dungeon
|
||||||
"""
|
"""
|
||||||
|
name = "Merchant"
|
||||||
inventory = list
|
inventory = list
|
||||||
|
hazel = int
|
||||||
|
|
||||||
def __init__(self, inventory : list):
|
def __init__(self, inventory : list, hazel : int = 75):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.inventory = inventory
|
self.inventory = inventory
|
||||||
|
self.hazel = hazel
|
||||||
|
|
||||||
def talk_to(self, player : Player) -> None:
|
def talk_to(self, player : Player) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -17,4 +20,14 @@ class Merchant(FriendlyEntity) :
|
||||||
and allow the player to buy/sell objects
|
and allow the player to buy/sell objects
|
||||||
"""
|
"""
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
|
class Sunflower(FriendlyEntity) :
|
||||||
|
"""
|
||||||
|
A friendly sunflower
|
||||||
|
"""
|
||||||
|
dialogue_option = ["Flower power!!", "The sun is warm today"]
|
||||||
|
|
||||||
|
def __init__(self, maxhealth: int = 15,
|
||||||
|
*args, **kwargs) -> None:
|
||||||
|
super().__init__(name="sunflower",
|
||||||
|
maxhealth=maxhealth, *args, **kwargs)
|
||||||
|
|
|
@ -80,6 +80,8 @@ class Player(FightingEntity):
|
||||||
return True
|
return True
|
||||||
elif entity.is_item():
|
elif entity.is_item():
|
||||||
entity.hold(self)
|
entity.hold(self)
|
||||||
|
elif entity.is_friendly():
|
||||||
|
self.map.logs.add_message(entity.talk_to(self))
|
||||||
return super().check_move(y, x, move_if_possible)
|
return super().check_move(y, x, move_if_possible)
|
||||||
|
|
||||||
def recalculate_paths(self, max_distance: int = 8) -> None:
|
def recalculate_paths(self, max_distance: int = 8) -> None:
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
from random import randint
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
from random import choice, randint
|
from random import choice, randint
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Any
|
||||||
|
|
||||||
from squirrelbattle.display.texturepack import TexturePack
|
from squirrelbattle.display.texturepack import TexturePack
|
||||||
|
|
||||||
|
@ -312,6 +313,12 @@ class Entity:
|
||||||
from squirrelbattle.entities.items import Item
|
from squirrelbattle.entities.items import Item
|
||||||
return isinstance(self, Item)
|
return isinstance(self, Item)
|
||||||
|
|
||||||
|
def is_friendly(self) -> bool:
|
||||||
|
"""
|
||||||
|
Is this entity a friendly entity?
|
||||||
|
"""
|
||||||
|
return isinstance(self, FriendlyEntity)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_entity_classes():
|
def get_all_entity_classes():
|
||||||
"""
|
"""
|
||||||
|
@ -320,7 +327,8 @@ class Entity:
|
||||||
from squirrelbattle.entities.items import Heart, Bomb
|
from squirrelbattle.entities.items import Heart, Bomb
|
||||||
from squirrelbattle.entities.monsters import Beaver, Hedgehog, \
|
from squirrelbattle.entities.monsters import Beaver, Hedgehog, \
|
||||||
Rabbit, TeddyBear
|
Rabbit, TeddyBear
|
||||||
return [Beaver, Bomb, Heart, Hedgehog, Rabbit, TeddyBear]
|
from squirrelbattle.entities.friendly import Merchant,Sunflower
|
||||||
|
return [Beaver, Bomb, Heart, Hedgehog, Rabbit, TeddyBear,Sunflower]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_entity_classes_in_a_dict() -> dict:
|
def get_all_entity_classes_in_a_dict() -> dict:
|
||||||
|
@ -331,6 +339,7 @@ class Entity:
|
||||||
from squirrelbattle.entities.monsters import Beaver, Hedgehog, Rabbit, \
|
from squirrelbattle.entities.monsters import Beaver, Hedgehog, Rabbit, \
|
||||||
TeddyBear
|
TeddyBear
|
||||||
from squirrelbattle.entities.items import Bomb, Heart
|
from squirrelbattle.entities.items import Bomb, Heart
|
||||||
|
from squirrelbattle.entities.friendly import Merchant,Sunflower
|
||||||
return {
|
return {
|
||||||
"Beaver": Beaver,
|
"Beaver": Beaver,
|
||||||
"Bomb": Bomb,
|
"Bomb": Bomb,
|
||||||
|
@ -339,6 +348,8 @@ class Entity:
|
||||||
"Rabbit": Rabbit,
|
"Rabbit": Rabbit,
|
||||||
"TeddyBear": TeddyBear,
|
"TeddyBear": TeddyBear,
|
||||||
"Player": Player,
|
"Player": Player,
|
||||||
|
"Merchant": Merchant,
|
||||||
|
"Sunflower": Sunflower,
|
||||||
}
|
}
|
||||||
|
|
||||||
def save_state(self) -> dict:
|
def save_state(self) -> dict:
|
||||||
|
@ -429,6 +440,7 @@ class FriendlyEntity(Entity):
|
||||||
"""
|
"""
|
||||||
maxhealth: int
|
maxhealth: int
|
||||||
health: int #Friendly entities can be killed
|
health: int #Friendly entities can be killed
|
||||||
|
dialogue_option : list
|
||||||
|
|
||||||
def __init__(self, maxhealth: int = 0, health: Optional[int] = None,
|
def __init__(self, maxhealth: int = 0, health: Optional[int] = None,
|
||||||
*args, **kwargs) -> None:
|
*args, **kwargs) -> None:
|
||||||
|
@ -436,6 +448,8 @@ class FriendlyEntity(Entity):
|
||||||
self.maxhealth = maxhealth
|
self.maxhealth = maxhealth
|
||||||
self.health = maxhealth if health is None else health
|
self.health = maxhealth if health is None else health
|
||||||
|
|
||||||
def talk_to(self, player : Player) -> None:
|
def talk_to(self, player : Any) -> str:
|
||||||
#TODO
|
a = randint(0,len(self.dialogue_option)-1)
|
||||||
|
return "The sunflower said : "+self.dialogue_option[a]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue