Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added inventory action #372

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/config/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def __update_config_values_from_current_state(self):
self.offended_npc_response = self.__definitions.get_string_value("offended_npc_response")
self.forgiven_npc_response = self.__definitions.get_string_value("forgiven_npc_response")
self.follow_npc_response = self.__definitions.get_string_value("follow_npc_response")
self.inventory_npc_response = self.__definitions.get_string_value("inventory_npc_response")

#TTS
self.tts_service = self.__definitions.get_string_value("tts_service").strip().lower()
Expand Down
8 changes: 7 additions & 1 deletion src/config/definitions/language_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ def get_forgiven_npc_response() -> ConfigValue:
def get_follow_npc_response() -> ConfigValue:
description = """The keyword used by the NPC when they are willing to become a follower.
This should match what is stated in the starting prompt."""
return ConfigValueString("follow_npc_response","NPC Response: Follow",description,"Follow", tags=[ConvigValueTag.advanced])
return ConfigValueString("follow_npc_response","NPC Response: Follow",description,"Follow", tags=[ConvigValueTag.advanced])

@staticmethod
def get_inventory_npc_response() -> ConfigValue:
description = """The keyword used by the NPC when they are willing to show their inventory.
This should match what is stated in the starting prompt."""
return ConfigValueString("inventory_npc_response","NPC Response: Inventory",description,"Inventory", tags=[ConvigValueTag.advanced])
1 change: 1 addition & 0 deletions src/config/mantella_config_value_definitions_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def get_config_values(on_value_change_callback: Callable[..., Any] | None = None
language_advanced_category.add_config_value(LanguageDefinitions.get_offended_npc_response())
language_advanced_category.add_config_value(LanguageDefinitions.get_forgiven_npc_response())
language_advanced_category.add_config_value(LanguageDefinitions.get_follow_npc_response())
language_advanced_category.add_config_value(LanguageDefinitions.get_inventory_npc_response())
result.append(language_advanced_category)

microphone_advanced_category = ConfigValueGroup("Microphone.Advanced", "Microphone advanced", "More advanced settings concerning microphone input and voice transription.", on_value_change_callback)
Expand Down
1 change: 1 addition & 0 deletions src/config/mantella_config_value_definitions_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def get_config_values(on_value_change_callback: Callable[..., Any] | None = None
language_category.add_config_value(LanguageDefinitions.get_offended_npc_response())
language_category.add_config_value(LanguageDefinitions.get_forgiven_npc_response())
language_category.add_config_value(LanguageDefinitions.get_follow_npc_response())
language_category.add_config_value(LanguageDefinitions.get_inventory_npc_response())
result.add_base_group(language_category)

prompts_category = ConfigValueGroup("Prompts", "Prompts", "Change the basic prompts used by Mantella.", on_value_change_callback)
Expand Down
3 changes: 2 additions & 1 deletion src/game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def __init__(self, game: gameable, chat_manager: ChatManager, config: ConfigLoad
self.__talk: conversation | None = None
self.__actions: list[action] = [action(comm_consts.ACTION_NPC_OFFENDED, config.offended_npc_response, f"The player offended the NPC"),
action(comm_consts.ACTION_NPC_FORGIVEN, config.forgiven_npc_response, f"The player made up with the NPC"),
action(comm_consts.ACTION_NPC_FOLLOW, config.follow_npc_response, f"The NPC is willing to follow the player")]
action(comm_consts.ACTION_NPC_FOLLOW, config.follow_npc_response, f"The NPC is willing to follow the player"),
action(comm_consts.ACTION_NPC_INVENTORY, config.inventory_npc_response, f"The NPC is willing to show their inventory to the player")]

###### react to calls from the game #######
def start_conversation(self, input_json: dict[str, Any]) -> dict[str, Any]:
Expand Down
3 changes: 2 additions & 1 deletion src/http/communication_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ class communication_constants:

ACTION_NPC_OFFENDED: str = PREFIX + "npc_offended"
ACTION_NPC_FORGIVEN: str = PREFIX + "npc_forgiven"
ACTION_NPC_FOLLOW: str = PREFIX + "npc_follow"
ACTION_NPC_FOLLOW: str = PREFIX + "npc_follow"
ACTION_NPC_INVENTORY: str = PREFIX + "npc_inventory"
6 changes: 5 additions & 1 deletion src/output_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ async def process_response(self, active_character: Character, blocking_queue: se
cumulative_sentence_bool = False
current_sentence: str = ""
actions_in_sentence: list[action] = []
show_inventory = False
while True:
try:
start_time = time.time()
Expand Down Expand Up @@ -239,6 +240,8 @@ async def process_response(self, active_character: Character, blocking_queue: se
else:
action_to_take: action | None = self.__matching_action_keyword(keyword_extraction, actions)
if action_to_take:
if keyword_extraction.lower() == 'inventory':
show_inventory = True
logging.log(28, action_to_take.info_text)
actions_in_sentence.append(action_to_take)
full_reply += f"{keyword_extraction}: "
Expand Down Expand Up @@ -286,7 +289,8 @@ async def process_response(self, active_character: Character, blocking_queue: se
# conversation has switched from radiant to multi NPC (this allows the player to "interrupt" radiant dialogue and include themselves in the conversation)
# the conversation has ended
# contains_player_character() == not radiant
if (num_sentences >= self.__config.max_response_sentences and characters.contains_player_character()):
# the NPC is opening their inventory (subsequent lines get cut off anyway when the game pauses to open the inventory menu)
if (num_sentences >= self.__config.max_response_sentences and characters.contains_player_character()) or (show_inventory):
break

break
Expand Down