Ejemplo n.º 1
0
 def do_action(self, game: 'Game', params: list[str],
               message: discord.Message) -> str:
     width = int(get_by_index(params, 0, "11"))
     height = int(get_by_index(params, 1, "11"))
     difficulty = int(get_by_index(params, 2, "6"))
     game.init_maze(width, height, difficulty)
     return "Maze rebuilt!\n" + str(game.maze)
Ejemplo n.º 2
0
 def do_noncombat(self, game: Game, params: list[str],
                  message: discord.Message) -> str:
     from discord_objects.DiscordUser import UserUtils
     from utils.Constanats import Triggers
     source_player = UserUtils.get_character_by_username(
         str(message.author), game.discord_users)
     room = source_player.current_room
     direction = get_by_index(params, 0)
     if direction is None:
         return f"No direciton specified. Proper usage of this command is:\n {Exit.show_help()}"
     door = room.get_door(direction.lower())
     if door is None:
         return f"Invalid direction. Room has no {direction} exit."
     old_room = source_player.current_room
     game.trigger(Triggers.BeforeLeaveRoom,
                  source_player=source_player,
                  source_entity=source_player,
                  room=old_room)
     game.trigger(Triggers.BeforeEnterRoom,
                  source_player=source_player,
                  source_entity=source_player,
                  room=door)
     source_player.current_room = door
     game.trigger(Triggers.LeaveRoom,
                  source_player=source_player,
                  source_entity=source_player,
                  room=old_room)
     game.trigger(Triggers.EnterRoom,
                  source_player=source_player,
                  source_entity=source_player,
                  room=source_player.current_room)
     return source_player.current_room.describe(game)
Ejemplo n.º 3
0
 def do_noncombat(self, game: Game, params: list[str],
                  message: discord.Message) -> str:
     # look for matched item in belt then bag, calling use_effect on it
     # TODO Check if item quantity is greater than 0 before using
     # TODO check if item quantity is less than 0 after
     from discord_objects.DiscordUser import UserUtils
     from utils.ListHelpers import get_by_index
     from utils.Constanats import EquipmentSlots
     discord_user = UserUtils.get_user_by_username(str(message.author),
                                                   game.discord_users)
     player = discord_user.current_character
     item_name = get_by_index(params, 0, None)
     if item_name is None:
         return "Item name not specified. Usage is:\n" + UseItem.show_help()
     matched_item = player.inventory.get_belt_item_by_name(item_name)
     source_container = "belt"
     if matched_item is None:
         matched_item = player.inventory.get_bag_item_by_name(item_name)
         source_container = "bag"
     if matched_item is None:
         return f"{item_name} was not found on belt or in bags"
     matched_item.use_effect(game, player, params[1:])
     matched_item.quantity = matched_item.quantity - 1
     if matched_item.quantity == 0:
         if source_container == "belt":
             player.inventory.equipment[EquipmentSlots.Belt].remove(
                 matched_item)
         elif source_container == "bag":
             player.inventory.bag.remove(matched_item)
     return f"{item_name} used"
Ejemplo n.º 4
0
 def do_combat_action(self, game: Game, source_player: Character,
                      params: list[Any]) -> None:
     from utils.CommandHelpers import match_spell
     from utils.Constanats import EquipmentSlots
     target_spell = get_by_index(params, 0)
     if target_spell is None:
         game.discord_connection.send_game_chat_sync(
             f"{source_player.combat_name} attempted to cast a spell.")
         return
     matched_spell = match_spell(source_player.known_spells, params)
     if matched_spell is None and isinstance(source_player, Character):
         from game_objects.Items.Spellbook import Spellbook
         offhand_item = source_player.inventory.equipment[
             EquipmentSlots.Offhand]
         mainhand_item = source_player.inventory.equipment[
             EquipmentSlots.Mainhand]
         if offhand_item is not None and isinstance(offhand_item,
                                                    Spellbook):
             matched_spell = match_spell(offhand_item.spells, params)
         elif matched_spell is not None and mainhand_item is not None and isinstance(
                 mainhand_item, Spellbook):
             matched_spell = match_spell(mainhand_item.spells, params)
     if matched_spell is None:
         game.discord_connection.send_game_chat_sync(
             f"{source_player.combat_name} attempted to cast {target_spell} but can't remember how."
         )
         return
     if not matched_spell.usable_in_combat:
         game.discord_connection.send_game_chat_sync(
             f"{source_player.combat_name} attempted to cast {target_spell} but can't do so while in combat."
         )
         return
Ejemplo n.º 5
0
 def do_noncombat(self, game: Game, params: list[str],
                  message: discord.Message) -> str:
     from discord_objects.DiscordUser import UserUtils
     discord_user = UserUtils.get_user_by_username(str(message.author),
                                                   game.discord_users)
     player = discord_user.current_character
     room = player.current_room
     items = room.items
     target_item_name = get_by_index(params, 0, None)
     if (target_item_name is None) or (target_item_name.lower() == "all"):
         if len(items) == 0:
             return "Nothing to pick up."
         pickup_strings = []
         for item in items:
             player.inventory.add_item_to_bag(item)
             pickup_strings.append(f"Picked up {item.quantity} {item.name}")
         room.items = []
         return "\n".join(pickup_strings)
     else:
         matched_item = next(
             (x
              for x in items if x.name.lower() == target_item_name.lower()),
             None)
         # matched_item = next(filter(lambda x: x.name.lower() == target_item_name.lower(), items), None)
         if matched_item is None:
             return "Item not found"
         player.inventory.add_item_to_bag(matched_item)
         room.items.remove(matched_item)
         return f"Picked up {matched_item.quantity} {matched_item.name}"
Ejemplo n.º 6
0
 def do_action(self, game: Game, params: list[str],
               message: discord.Message) -> str:
     from discord_objects.DiscordUser import UserUtils
     discord_user = UserUtils.get_user_by_username(str(message.author),
                                                   game.discord_users)
     player = discord_user.current_character
     to_return = "\n".join([
         f"{player.name}",
         f"HP: {player.display_health}/{player.max_health}",
         f"PP: {player.display_stamina}/{player.max_stamina}",
         f"MP {player.display_mana}/{player.max_mana}"
     ])
     if get_by_index(params, 0, "").lower() == "stats":
         to_return = to_return + "\n"
         to_return = to_return + "Attack Bonuses:\n"
         to_return = to_return + f"  Hit: {player.hit_bonus}\n"
         to_return = to_return + f"  Dmg: {player.dmg_bonus}\n"
         player_resistances = player.resistances
         if len(player_resistances["hit"].keys()) > 0:
             to_return = to_return + "Hit Resistances:\n"
             for k, v in player_resistances["hit"].items():
                 to_return = to_return + f"  {k.capitalize()}: {v}\n"
         if len(player_resistances["dmg"].keys()) > 0:
             to_return = to_return + "Damage Resistances:\n"
             for k, v in player_resistances["dmg"].items():
                 to_return = to_return + f"  {k.capitalize()}: {v}\n"
     return to_return
Ejemplo n.º 7
0
 def command_valid(self, game: Game, source_player: CombatEntity,
                   params: list[Any]) -> bool:
     """Check if the command is still valid."""
     from utils.CommandHelpers import match_spell
     from utils.Constanats import EquipmentSlots
     target_spell = get_by_index(params, 0)
     if target_spell is None:
         return False
     matched_spell = match_spell(source_player.known_spells, params)
     if matched_spell is None and isinstance(source_player, Character):
         from game_objects.Items.Spellbook import Spellbook
         offhand_item = source_player.inventory.equipment[
             EquipmentSlots.Offhand]
         if offhand_item is not None and isinstance(offhand_item,
                                                    Spellbook):
             matched_spell = match_spell(
                 source_player.inventory.equipment[
                     EquipmentSlots.Offhand].spells, params)
         elif matched_spell is not None and source_player.inventory.equipment[
                 EquipmentSlots.Mainhand] is not None and isinstance(
                     source_player.inventory.equipment[
                         EquipmentSlots.Mainhand], Spellbook):
             matched_spell = match_spell(
                 source_player.inventory.equipment[
                     EquipmentSlots.Mainhand].spells, params)
     if matched_spell is None:
         return False
     if not matched_spell.usable_in_combat:
         return False
     # TODO
     # get target type from spell
     # attempt to match from target types in room
     # if all targets valid
     return True
Ejemplo n.º 8
0
 def do_action(self, game: Game, params: list[str],
               message: discord.Message) -> str:
     from discord_objects.DiscordUser import UserUtils
     discord_user = UserUtils.get_user_by_username(str(message.author),
                                                   game.discord_users)
     player = discord_user.current_character
     room = player.current_room
     object_name = get_by_index(params, 0, None)
     if object_name is None:
         return "No object specified to loot. Usage is:\n" + LootCommand.show_help(
         )
     matched_object = next((fixture for fixture in room.fixtures
                            if fixture.name.lower() == object_name.lower()
                            and hasattr(fixture, "items")), None)
     if matched_object is None:
         return f"Lootable object {object_name} not found."
     looted_items = matched_object.items
     matched_object.items = []
     if len(looted_items) == 0:
         return f"{object_name.capitalize()} was empty."
     player.inventory.bag = player.inventory.bag + looted_items
     text_described_items = [
         f"{x.quantity}x {x.name}" for x in looted_items
     ]
     return f"Picked up {enumerate_objects(text_described_items)}"
Ejemplo n.º 9
0
 def do_action(self, game: Game, params: list[str],
               message: discord.Message) -> str:
     from discord_objects.DiscordUser import UserUtils
     discord_user = UserUtils.get_user_by_username(str(message.author),
                                                   game.discord_users)
     player = discord_user.current_character
     item_name = get_by_index(params, 0, None)
     if item_name is None:
         return "Item name not specified. Usage is:\n" + Equip.show_help()
     slot = get_by_index(params, 1, None)
     if slot is None:
         return "Slot not specified. Usage is:\n" + Equip.show_help()
     matched_item = player.inventory.get_bag_item_by_name(item_name)
     if matched_item is None:
         return "Item not found"
     success, err_reason = player.inventory.equip_item(matched_item, slot)
     if success:
         return "Item equipped"
     return err_reason
Ejemplo n.º 10
0
 def do_action(self, game: Game, params: list[str],
               message: discord.Message) -> str:
     from discord_objects.DiscordUser import UserUtils
     discord_user = UserUtils.get_user_by_username(str(message.author),
                                                   game.discord_users)
     player = discord_user.current_character
     slot = get_by_index(params, 0)
     worked, response = player.inventory.unequip_item(slot)
     if worked:
         return f"Unequipped item from {slot}"
     else:
         return response
Ejemplo n.º 11
0
 def do_noncombat(self, game: Game, params: list[str],
                  message: discord.Message):
     from discord_objects.DiscordUser import UserUtils
     discord_user = UserUtils.get_user_by_username(str(message.author),
                                                   game.discord_users)
     player = discord_user.current_character
     target_item = get_by_index(params, 0)
     if target_item is None:
         return Drop.show_help()
     room = player.current_room
     player_bag = player.inventory.bag
     matched_item = player.inventory.get_bag_item_by_name(target_item)
     if matched_item is None:
         return "Item not found"
     quantity = int(get_by_index(params, 1, "1"))
     quantity = max(quantity, matched_item.quantity)
     if quantity >= matched_item.quantity:
         room.items.append(matched_item)
         player_bag.remove(matched_item)
     else:
         dropped_items = matched_item.take_count_from_stack(quantity)
         room.items.append(dropped_items)
     return f"Dropped {quantity} {matched_item.name}"
Ejemplo n.º 12
0
 def command_valid(self, game: Game, source_player: CombatEntity,
                   params: list[Any]) -> bool:
     """Check if the command is still valid."""
     from utils.CommandHelpers import match_bag_item
     target_item = get_by_index(params, 0)
     if target_item is None:
         return False
     if isinstance(source_player, Character):
         matched_item = match_bag_item(source_player, params)
     else:
         return False
     if matched_item is None:
         return False
     return True
Ejemplo n.º 13
0
 def do_action(self, game: Game, params: list[str],
               message: discord.Message) -> str:
     if len(params) == 0:
         return ShowHelp.show_help()
     from discord_objects.DiscordUser import UserUtils
     discord_user = UserUtils.get_user_by_username(str(message.author),
                                                   game.discord_users)
     if discord_user is None:
         return "You are not listed as a user in this game."
     supplied_alias = get_by_index(params, 0).lower()
     for command in discord_user.get_commands(game):
         lower_aliases = [x.lower() for x in command.aliases]
         if supplied_alias in lower_aliases:
             return command.show_help()
Ejemplo n.º 14
0
 def command_valid(self, game: Game, source_player: CombatEntity,
                   params: list[Any]) -> bool:
     # look for a matched item in belt only, calling use_effect on it
     # look for matched item in belt then bag, calling use_effect on it
     from utils.ListHelpers import get_by_index
     item_name = get_by_index(params, 0, None)
     if item_name is None:
         return False
     if isinstance(source_player, Character):
         matched_item = source_player.inventory.get_belt_item_by_name(
             item_name)
     else:
         return False
     if matched_item is None:
         return False
     return True
Ejemplo n.º 15
0
    def do_action(self, game: Game, params: list[str],
                  message: discord.Message) -> str:
        from discord_objects.DiscordUser import UserUtils
        from utils.ListHelpers import get_by_index
        from utils.Constanats import DamageTypes

        discord_user = UserUtils.get_user_by_username(str(message.author),
                                                      game.discord_users)
        enemy_name = get_by_index(params, 0, None)
        if enemy_name is None:
            return "No enemy specified. Usage is:\n" + SizeUpCommand.show_help(
            )
        player = discord_user.current_character
        room = player.current_room
        from utils.CommandHelpers import match_enemy, match_player
        enemies = [x for x in game.enemies if x.current_room == room]
        target = None
        match_enemy_result = match_enemy(enemies, params)
        if match_enemy_result is not None:
            target = match_enemy_result
        if target is None:
            return "Specified enemy not found."
        else:
            # list max health
            # for each damage type in damage-types
            # list hit resistance and damage resistance
            # grid with spacing of 15, left aligned, right pad to length of 15
            max_health = target.max_health
            hit_resistances = sum_resistances(target.natural_armor["hit"],
                                              target.armor_bonus["hit"])
            dmg_resistances = sum_resistances(target.natural_armor["dmg"],
                                              target.armor_bonus["dmg"])
            resp_strings = [
                f"You quickly thumb through your copy of Ogres and Oubliettes: A Field Guide and find the entry for {target.name}",
                f"Health: {max_health}", "Type".ljust(15) +
                "Hit Resist".ljust(15) + "Dmg Resist".ljust(15)
            ]
            for type in [
                    "slash", "pierce", "bludgeon", "electricity", "fire", "ice"
            ]:
                resp_strings.append(
                    type.capitalize().ljust(15) +
                    f"{hit_resistances.get(type,0 )}".ljust(15) +
                    f"{dmg_resistances.get(type,0)}".ljust(15))

            return resp_strings[0] + "```" + "\n".join(
                resp_strings[1:]) + "```"
Ejemplo n.º 16
0
 def do_noncombat(self, game: Game, params: list[str],
                  message: discord.Message):
     from discord_objects.DiscordUser import UserUtils
     discord_user = UserUtils.get_user_by_username(str(message.author),
                                                   game.discord_users)
     player = discord_user.current_character
     target_spell = get_by_index(params, 0)
     if target_spell is None:
         return Cast.show_help()
     # attempt to match from known spells
     # if spellbook in mainhand or offhand
     #   attempt to match from spellbook
     # if spell can be used out of combat
     #   get target type from spell
     #   attempt to match from target types in room
     #   if all targets valid
     #       do it
     return "Not Implemented"
Ejemplo n.º 17
0
 def do_action(self, game: Game, params: list[str],
               message: discord.Message) -> str:
     from discord_objects.DiscordUser import UserUtils
     player = UserUtils.get_character_by_username(str(message.author),
                                                  game.discord_users)
     current_room = player.current_room
     players = current_room.get_characters(game)
     player_name = get_by_index(params, 0, None)
     if player_name is None and len(players) == 2:
         chosen_player = players[0] if players[0] != player else players[1]
     elif player_name is None and len(players) >= 2:
         return "You're left hanging."
     else:
         chosen_player = next((x for x in players if x.name.replace(
             " ", "").lower() == player_name.replace(" ", "").lower()),
                              None)
     if chosen_player is None:
         return "Named person was not found"
     return f"You give an epic high five to {chosen_player.name}"
Ejemplo n.º 18
0
 def do_action(self, game: Game, params: list[str], message: discord.Message) -> str:
     from discord_objects.DiscordUser import UserUtils
     from game_objects.Conversation import Conversation
     player = UserUtils.get_character_by_username(str(message.author), game.discord_users)
     current_room = player.current_room
     npcs = current_room.get_npcs(game)
     npc_name = get_by_index(params, 0, None)
     if npc_name is None and len(npcs) == 1:
         chosen_npc = npcs[0]
     else:
         chosen_npc = next((npc for npc in npcs if npc.name == npc_name), None)
     if chosen_npc is None:
         return "Named person was not found"
     new_conversation = Conversation()
     new_conversation.npc = chosen_npc
     new_conversation.character = player
     new_conversation.room = current_room
     current_room.conversations.append(new_conversation)
     new_conversation.init_conversation(game, chosen_npc.dialog_tree)
Ejemplo n.º 19
0
 def do_combat_action(self, game: Game, source_player: Character,
                      params: list[Any]) -> None:
     target_item = params[0]
     room = source_player.current_room
     player_bag = source_player.inventory.bag
     matched_item = source_player.inventory.get_bag_item_by_name(
         target_item)
     if matched_item is None:
         game.discord_connection.send_game_chat_sync(
             f"{source_player.combat_name} attempted to drop an item, but could find a {target_item} in their inventory"
         )
         return
     quantity = get_by_index(params, 1, 1)
     quantity = max(quantity, matched_item.quantity)
     if quantity >= matched_item.quantity:
         room.items.append(matched_item)
         player_bag.remove(matched_item)
     else:
         dropped_items = matched_item.take_count_from_stack(quantity)
         room.items.append(dropped_items)
     game.discord_connection.send_game_chat_sync(
         f"{source_player.combat_name} dropped {quantity} {matched_item.name}"
     )
Ejemplo n.º 20
0
 def do_combat_action(self, game: Game, source_player: Character,
                      params: list[Any]) -> None:
     # look for a matched item in belt only, calling use_effect on it
     # look for matched item in belt then bag, calling use_effect on it
     from utils.ListHelpers import get_by_index
     from utils.Constanats import EquipmentSlots
     item_name = get_by_index(params, 0, None)
     if item_name is None:
         game.discord_connection.send_game_chat_sync(
             "Item name not specified. Usage is:\n" + UseItem.show_help(),
             [source_player.discord_user])
     matched_item = source_player.inventory.get_belt_item_by_name(item_name)
     if matched_item is None:
         game.discord_connection.send_game_chat_sync(
             f"{item_name} was not found on belt",
             [source_player.discord_user])
         return
     game.discord_connection.send_game_chat_sync(
         f"{source_player.name} uses {matched_item.name}.")
     matched_item.use_effect(game, source_player, params[1:])
     matched_item.quantity = matched_item.quantity - 1
     if matched_item.quantity == 0:
         source_player.inventory.equipment[EquipmentSlots.Belt].remove(
             matched_item)