Make clothing inventory command align with default inventory
This commit is contained in:
parent
3ec3e63f4f
commit
04f6eff234
4 changed files with 70 additions and 40 deletions
|
|
@ -75,10 +75,10 @@ with which to test the system:
|
|||
from collections import defaultdict
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from evennia import DefaultCharacter, DefaultObject, default_cmds
|
||||
from evennia.commands.default.muxcommand import MuxCommand
|
||||
from evennia.utils import at_search_result, evtable, inherits_from, iter_to_str, int2str
|
||||
from evennia.utils import at_search_result, crop, evtable, inherits_from, int2str, iter_to_str
|
||||
from evennia.utils.ansi import raw as raw_ansi
|
||||
|
||||
# Options start here.
|
||||
# Maximum character length of 'wear style' strings, or None for unlimited.
|
||||
|
|
@ -468,7 +468,8 @@ class CmdWear(MuxCommand):
|
|||
return
|
||||
elif len(self.rhs) > WEARSTYLE_MAXLENGTH:
|
||||
self.caller.msg(
|
||||
f"Please keep your wear style message to less than {WEARSTYLE_MAXLENGTH} characters."
|
||||
"Please keep your wear style message to less than"
|
||||
f" {WEARSTYLE_MAXLENGTH} characters."
|
||||
)
|
||||
return
|
||||
else:
|
||||
|
|
@ -652,39 +653,38 @@ class CmdInventory(MuxCommand):
|
|||
|
||||
message_list = []
|
||||
|
||||
# all our items
|
||||
items = self.caller.contents
|
||||
|
||||
carry_table = evtable.EvTable(border="header")
|
||||
wear_table = evtable.EvTable(border="header")
|
||||
|
||||
# carried items
|
||||
carried = [obj for obj in items if not obj.db.worn]
|
||||
carry_table = self.styled_table(border="header")
|
||||
|
||||
names_and_descs = [(obj.get_display_name(self.caller), obj.get_display_desc(self.caller))
|
||||
for obj in set(carried)]
|
||||
carried_sums = {tup: names_and_descs.count(tup) for tup in set(names_and_descs)}
|
||||
|
||||
worn = [obj for obj in items if obj.db.worn]
|
||||
|
||||
message_list.append("|wYou are carrying:|n")
|
||||
for (name, desc), count in carried_sums.items():
|
||||
for item in carried:
|
||||
singular, _ = item.get_numbered_name(1, self.caller)
|
||||
carry_table.add_row(
|
||||
f"{int2str(count)} {name}", desc
|
||||
f"{singular}|n",
|
||||
"{}|n".format(crop(raw_ansi(item.db.desc or ""), width=50) or ""),
|
||||
)
|
||||
message_list.extend(
|
||||
["|wYou are carrying:|n", str(carry_table) if carry_table.nrows > 0 else " Nothing."]
|
||||
)
|
||||
|
||||
if carry_table.nrows == 0:
|
||||
carry_table.add_row("Nothing.", "")
|
||||
message_list.append(str(carry_table))
|
||||
# worn items
|
||||
worn = [obj for obj in items if obj.db.worn]
|
||||
wear_table = self.styled_table(border="header")
|
||||
|
||||
message_list.append("|wYou are wearing:|n")
|
||||
for item in worn:
|
||||
item_name = item.get_display_name(self.caller)
|
||||
if item.db.covered_by:
|
||||
item_name += " (hidden)"
|
||||
wear_table.add_row(item_name, item.get_display_desc(self.caller))
|
||||
if wear_table.nrows == 0:
|
||||
wear_table.add_row("Nothing.", "")
|
||||
message_list.append(str(wear_table))
|
||||
singular, _ = item.get_numbered_name(1, self.caller)
|
||||
wear_table.add_row(
|
||||
f"{singular}|n",
|
||||
"{}|n".format(crop(raw_ansi(item.db.desc or ""), width=50) or ""),
|
||||
)
|
||||
message_list.extend(
|
||||
["You are wearing:|n", str(wear_table) if wear_table.nrows > 0 else " Nothing."]
|
||||
)
|
||||
|
||||
# return the composite message
|
||||
self.caller.msg("\n".join(message_list))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue