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]:
|
||||
return [a[1][1] + (" : "
|
||||
+ (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='_',
|
||||
TEDDY_BEAR='8',
|
||||
MERCHANT='M',
|
||||
SUNFLOWER='I',
|
||||
)
|
||||
|
||||
TexturePack.SQUIRREL_PACK = TexturePack(
|
||||
@ -74,4 +75,5 @@ TexturePack.SQUIRREL_PACK = TexturePack(
|
||||
BEAVER='🦫',
|
||||
TEDDY_BEAR='🧸',
|
||||
MERCHANT='🦜',
|
||||
SUNFLOWER='🌻',
|
||||
)
|
||||
|
@ -1,15 +1,18 @@
|
||||
from ..interfaces import FriendlyEntity, Map
|
||||
from .player import Player
|
||||
|
||||
class Merchant(FriendlyEntity) :
|
||||
"""
|
||||
The class for merchants in the dungeon
|
||||
"""
|
||||
|
||||
name = "Merchant"
|
||||
inventory = list
|
||||
hazel = int
|
||||
|
||||
def __init__(self, inventory : list):
|
||||
def __init__(self, inventory : list, hazel : int = 75):
|
||||
super().__init__()
|
||||
self.inventory = inventory
|
||||
self.hazel = hazel
|
||||
|
||||
def talk_to(self, player : Player) -> None:
|
||||
"""
|
||||
@ -17,4 +20,14 @@ class Merchant(FriendlyEntity) :
|
||||
and allow the player to buy/sell objects
|
||||
"""
|
||||
#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
|
||||
elif entity.is_item():
|
||||
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)
|
||||
|
||||
def recalculate_paths(self, max_distance: int = 8) -> None:
|
||||
|
@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
from random import randint
|
||||
from enum import Enum, auto
|
||||
from math import sqrt
|
||||
from random import choice, randint
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Any
|
||||
|
||||
from squirrelbattle.display.texturepack import TexturePack
|
||||
|
||||
@ -312,6 +313,12 @@ class Entity:
|
||||
from squirrelbattle.entities.items import Item
|
||||
return isinstance(self, Item)
|
||||
|
||||
def is_friendly(self) -> bool:
|
||||
"""
|
||||
Is this entity a friendly entity?
|
||||
"""
|
||||
return isinstance(self, FriendlyEntity)
|
||||
|
||||
@staticmethod
|
||||
def get_all_entity_classes():
|
||||
"""
|
||||
@ -320,7 +327,8 @@ class Entity:
|
||||
from squirrelbattle.entities.items import Heart, Bomb
|
||||
from squirrelbattle.entities.monsters import Beaver, Hedgehog, \
|
||||
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
|
||||
def get_all_entity_classes_in_a_dict() -> dict:
|
||||
@ -331,6 +339,7 @@ class Entity:
|
||||
from squirrelbattle.entities.monsters import Beaver, Hedgehog, Rabbit, \
|
||||
TeddyBear
|
||||
from squirrelbattle.entities.items import Bomb, Heart
|
||||
from squirrelbattle.entities.friendly import Merchant,Sunflower
|
||||
return {
|
||||
"Beaver": Beaver,
|
||||
"Bomb": Bomb,
|
||||
@ -339,6 +348,8 @@ class Entity:
|
||||
"Rabbit": Rabbit,
|
||||
"TeddyBear": TeddyBear,
|
||||
"Player": Player,
|
||||
"Merchant": Merchant,
|
||||
"Sunflower": Sunflower,
|
||||
}
|
||||
|
||||
def save_state(self) -> dict:
|
||||
@ -429,6 +440,7 @@ class FriendlyEntity(Entity):
|
||||
"""
|
||||
maxhealth: int
|
||||
health: int #Friendly entities can be killed
|
||||
dialogue_option : list
|
||||
|
||||
def __init__(self, maxhealth: int = 0, health: Optional[int] = None,
|
||||
*args, **kwargs) -> None:
|
||||
@ -436,6 +448,8 @@ class FriendlyEntity(Entity):
|
||||
self.maxhealth = maxhealth
|
||||
self.health = maxhealth if health is None else health
|
||||
|
||||
def talk_to(self, player : Player) -> None:
|
||||
#TODO
|
||||
def talk_to(self, player : Any) -> str:
|
||||
a = randint(0,len(self.dialogue_option)-1)
|
||||
return "The sunflower said : "+self.dialogue_option[a]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user