evennia / evennia

Python MUD/MUX/MUSH/MU* development system

Home Page:http://www.evennia.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Search multi-match does not work with the ContribRPObject

bradleymarques opened this issue · comments

Describe the bug

When using the RP system contrib, multi-match fails with string Could not find <object>.

To Reproduce

Steps to reproduce the behavior:

  1. Setup the RP system contrib by following the steps here

  2. Place two objects in the same room with identical keys:

    create_object(Object, "Mushroom", location=some_room)
    create_object(Object, "Mushroom", location=some_room)
  3. As a player standing in that location, issue the command: look mushroom. As expected, the player sees:

    More than one match for 'mushroom' (please narrow target):
      Mushroom-1 []
      Mushroom-2 []
  4. Now attempt to narrow the search by issuing the command look mushroom-1. The player sees the following message:

    Could not find 'mushroom-1'.

Expected behavior

Instead of seeing the message Could not find 'mushroom-1', the player should see the first mushroom:

Mushroom
You see nothing special.

Environment, Evennia version, OS etc

  • python = "3.11.6"
  • evennia = "3.1.1"
  • Mac OS Sonoma 14.2.1 (23C71)

Additional context

Looking through the code, it seems that the search function in ContribRPObject has diverged quite a lot from that in Object.

I wrote this (failing) unit test, but couldn't solve the bug itself:

# evennia/contrib/rpg/rpsystem/tests.py


class TestRPSystem(BaseEvenniaTest):
    # ... existing tests
    
    def test_multi_match_search(self):
        mushroom1 = create_object(rpsystem.ContribRPObject, key="Mushroom", location=self.room1)
        mushroom1.db.desc = "The first mushroom is brown."
        mushroom2 = create_object(rpsystem.ContribRPObject, key="Mushroom", location=self.room1)
        mushroom2.db.desc = "The second mushroom is red."

        expected_first_call = [
            "More than one match for 'Mushroom' (please narrow target):",
            f" Mushroom({mushroom1.dbref})-1 []",
            f" Mushroom({mushroom2.dbref})-2 []",
        ]
        self.call(CmdLook(), "Mushroom", "\n".join(expected_first_call)) # PASSES

        expected_second_call = f"Mushroom({mushroom1.dbref})\nThe first mushroom is brown."
        self.call(CmdLook(), "Mushroom-1", expected_second_call) # FAILS

        expected_third_call = f"Mushroom({mushroom2.dbref})\nThe second mushroom is red."
        self.call(CmdLook(), "Mushroom-2", expected_third_call) # FAILS

See: https://github.com/evennia/evennia/pull/3410/files

Thanks for the unit test example. I have fixed this and will take the time to refactor the search method as well so there's less need for duplicate code in the contrib. 👍

Thanks so much for fixing @Griatch ! It was a bit daunting trying to do it myself :)