Beispiel #1
0
def show_vnum(player, parsed, ctx):
    """Show the vnum of a location (.) or an object/living,
    or when you provide a vnum as arg, show the object(s) with that vnum."""
    if not parsed.args:
        raise ParseError("From what should I show the vnum?")
    name = parsed.args[0]
    if name == ".":
        obj = player.location
    elif parsed.who_order:
        obj = parsed.who_order[0]
    else:
        try:
            vnum = int(parsed.args[0])
        except ValueError as x:
            raise ActionRefused(str(x))
        objects = []
        try:
            objects.append(make_item(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_location(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_mob(vnum))
        except KeyError:
            pass
        player.tell("Objects with vnum %d:" % vnum, lang.join(str(o) for o in objects))
        return
    try:
        vnum = obj.vnum
        player.tell("Vnum of %s = %d." % (obj, vnum))
    except AttributeError:
        player.tell(obj, "has no vnum.")
Beispiel #2
0
 def testJoin(self):
     self.assertEqual("", lang.join([]))
     self.assertEqual("", lang.join(x for x in []))
     self.assertEqual("a", lang.join(["a"]))
     self.assertEqual("a and b", lang.join(["a", "b"]))
     self.assertEqual("a and b", lang.join(x for x in ["a", "b"]))
     self.assertEqual("a, b, and c", lang.join(["a", "b", "c"]))
     self.assertEqual("a, b, or c", lang.join(["a", "b", "c"], conj="or"))
     self.assertEqual("c, b, or a", lang.join(["c", "b", "a"], conj="or"))
 def testJoin(self):
     self.assertEqual("", lang.join([]))
     self.assertEqual("", lang.join(x for x in []))
     self.assertEqual("a", lang.join(["a"]))
     self.assertEqual("a and b", lang.join(["a", "b"]))
     self.assertEqual("a and b", lang.join(x for x in ["a", "b"]))
     self.assertEqual("a, b, and c", lang.join(["a", "b", "c"]))
     self.assertEqual("a, b, or c", lang.join(["a", "b", "c"], conj="or"))
     self.assertEqual("c, b, or a", lang.join(["c", "b", "a"], conj="or"))
Beispiel #4
0
def show_cvnum(player: Player, parsed: ParseResult, ctx: util.Context) -> None:
    """Show the circle-vnum of a location (.) or an object/living,
    or when you provide a circle-vnum as arg, show the object(s) with that circle-vnum."""
    if not parsed.args:
        raise ParseError("From what should I show the circle-vnum?")
    name = parsed.args[0]
    obj = None  # type: Union[Location, Living, Item, Exit]
    if name == ".":
        obj = player.location
    elif parsed.who_info:
        obj = parsed.who_1
    else:
        try:
            vnum = int(parsed.args[0])
        except ValueError as x:
            raise ActionRefused(str(x))
        objects = []   # type: List[Union[Location, Living, Item, Exit]]
        try:
            objects.append(make_item(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_location(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_mob(vnum))
        except KeyError:
            pass
        player.tell("Objects with circle-vnum %d:" % vnum + " " + (lang.join(str(o) for o in objects) or "none"))
        return
    try:
        vnum = obj.circle_vnum
        player.tell("Circle-Vnum of %s = %d." % (obj, vnum))
    except AttributeError:
        player.tell(str(obj) + " has no circle-vnum.")
Beispiel #5
0
def show_vnum(player, parsed, ctx):
    """Show the vnum of a location (.) or an object/living,
    or when you provide a vnum as arg, show the object(s) with that vnum."""
    if not parsed.args:
        raise ParseError("From what should I show the vnum?")
    name = parsed.args[0]
    if name == ".":
        obj = player.location
    elif parsed.who_order:
        obj = parsed.who_order[0]
    else:
        try:
            vnum = int(parsed.args[0])
        except ValueError as x:
            raise ActionRefused(str(x))
        objects = []
        try:
            objects.append(make_item(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_location(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_mob(vnum))
        except KeyError:
            pass
        player.tell("Objects with vnum %d:" % vnum,
                    lang.join(str(o) for o in objects))
        return
    try:
        vnum = obj.vnum
        player.tell("Vnum of %s = %d." % (obj, vnum))
    except AttributeError:
        player.tell(obj, "has no vnum.")
Beispiel #6
0
 def testJoinMulti(self):
     self.assertEqual("two bikes", lang.join(["bike"] * 2))
     self.assertEqual("two bikes", lang.join(["a bike"] * 2))
     self.assertEqual("three bikes", lang.join(["a bike"] * 3))
     self.assertEqual("bike, bike, and bike",
                      lang.join(["bike"] * 3, group_multi=False))
     self.assertEqual("twelve keys", lang.join(["key"] * 12))
     self.assertEqual("twelve keys", lang.join(["a key"] * 12))
     self.assertEqual("two keys and two bikes",
                      lang.join(["key", "bike"] * 2))
     self.assertEqual("two bikes and two keys",
                      lang.join(["bike", "key"] * 2))
     self.assertEqual("two bikes and two apples",
                      lang.join(["a bike", "an apple"] * 2))
     self.assertEqual("two bikes, two keys, and two mice",
                      lang.join(["bike", "key", "mouse"] * 2))
     self.assertEqual("two bikes, two apples, and two mice",
                      lang.join(["a bike", "an apple", "the mouse"] * 2))
     self.assertEqual("two apples, bike, and two keys",
                      lang.join(["apple", "apple", "bike", "key", "key"]))
     self.assertEqual("two apples, two keys, and bike",
                      lang.join(["apple", "apple", "key", "bike", "key"]))
     self.assertEqual(
         "two apples, two keys, and a bike",
         lang.join(["an apple", "an apple", "a key", "a bike", "a key"]))
     self.assertEqual(
         "three apples, two keys, and someone",
         lang.join([
             "an apple", "an apple", "the key", "an apple", "someone",
             "the key"
         ]))
     self.assertEqual("key, bike, key, and bike",
                      lang.join(["key", "bike"] * 2, group_multi=False))
Beispiel #7
0
 def testJoinMulti(self):
     self.assertEqual("two bikes", lang.join(["bike"] * 2))
     self.assertEqual("two bikes", lang.join(["a bike"] * 2))
     self.assertEqual("three bikes", lang.join(["a bike"] * 3))
     self.assertEqual("bike, bike, and bike", lang.join(["bike"] * 3, group_multi=False))
     self.assertEqual("twelve keys", lang.join(["key"] * 12))
     self.assertEqual("twelve keys", lang.join(["a key"] * 12))
     self.assertEqual("two keys and two bikes", lang.join(["key", "bike"] * 2))
     self.assertEqual("two bikes and two keys", lang.join(["bike", "key"] * 2))
     self.assertEqual("two bikes and two apples", lang.join(["a bike", "an apple"] * 2))
     self.assertEqual("two bikes, two keys, and two mice", lang.join(["bike", "key", "mouse"] * 2))
     self.assertEqual("two bikes, two apples, and two mice", lang.join(["a bike", "an apple", "the mouse"] * 2))
     self.assertEqual("two apples, bike, and two keys", lang.join(["apple", "apple", "bike", "key", "key"]))
     self.assertEqual("two apples, two keys, and bike", lang.join(["apple", "apple", "key", "bike", "key"]))
     self.assertEqual("two apples, two keys, and a bike", lang.join(["an apple", "an apple", "a key", "a bike", "a key"]))
     self.assertEqual("three apples, two keys, and someone", lang.join(["an apple", "an apple", "the key", "an apple", "someone", "the key"]))
     self.assertEqual("key, bike, key, and bike", lang.join(["key", "bike"] * 2, group_multi=False))