Evadventure commands, some tests

This commit is contained in:
Griatch 2022-08-04 21:08:14 +02:00
parent 2848e31f4b
commit de419d94ed
4 changed files with 67 additions and 13 deletions

View file

@ -112,7 +112,11 @@ class CmdInventory(EvAdventureCommand):
aliases = ("i", "inv")
def func(self):
self.caller.msg(self.caller.equipment.display_loadout())
loadout = self.caller.equipment.display_loadout()
backpack = self.caller.equipment.display_backpack()
slot_usage = self.caller.equipment.display_slot_usage()
self.caller.msg(f"{loadout}\n{backpack}\nYou use {slot_usage} equipment slots.")
class CmdWieldOrWear(EvAdventureCommand):
@ -296,7 +300,7 @@ def node_receive(caller, raw_string, **kwargs):
{get_obj_stats(item)}
[Your inventory usage: {caller.equipment.get_slot_usage_string()}]
[Your inventory usage: {caller.equipment.display_slot_usage()}]
|wDo you want to accept the given item? Y/[N]
"""
options = ({"key": "_default", "goto": (_accept_or_reject_gift, kwargs)},)

View file

@ -83,16 +83,6 @@ class EquipmentHandler:
"""
return getattr(self.obj, Ability.CON.value, 1) + 10
def get_slot_usage_string(self):
"""
Get a slot usage/max string for display.
Returns:
str: The usage string.
"""
return f"|b{self.count_slots()}/{self.max_slots}|n"
def validate_slot_usage(self, obj):
"""
Check if obj can fit in equipment, based on its size.
@ -216,6 +206,29 @@ class EquipmentHandler:
return f"{weapon_str}{shield_str}\n{armor_str}{helmet_str}"
def display_backpack(self):
"""
Get a visual representation of the backpack's contents.
"""
backpack = self.slots[WieldLocation.BACKPACK]
if not backpack:
return "Backpack is empty."
out = []
for item in backpack:
out.append(f"{item.key} [|b{item.size}|n] slot(s)")
return "\n".join(out)
def display_slot_usage(self):
"""
Get a slot usage/max string for display.
Returns:
str: The usage string.
"""
return f"|b{self.count_slots()}/{self.max_slots}|n"
def move(self, obj):
"""
Moves item to the place it things it should be in - this makes use of the object's wield

View file

@ -18,11 +18,12 @@ rune sword (weapon+quest).
"""
from evennia import AttributeProperty, TagProperty
from evennia import AttributeProperty
from evennia.objects.objects import DefaultObject
from evennia.utils.utils import make_iter
from .enums import Ability, ObjType, WieldLocation
from .utils import get_obj_stats
class EvAdventureObject(DefaultObject):
@ -44,6 +45,12 @@ class EvAdventureObject(DefaultObject):
for obj_type in make_iter(self.obj_type):
self.tags.add(obj_type, category="obj_type")
def get_display_header(self, looker, **kwargs):
return "" # this is handled by get_obj_stats
def get_display_desc(self, looker, **kwargs):
return get_obj_stats(self, owner=looker)
def has_obj_type(self, objtype):
"""
Check if object is of a particular type.

View file

@ -0,0 +1,30 @@
"""
Test the EvAdventure commands.
"""
from unittest.mock import MagicMock, patch
from evennia.utils.test_resources import BaseEvenniaCommandTest
from .. import commands
from .mixins import EvAdventureMixin
class TestEvAdventureCommands(EvAdventureMixin, BaseEvenniaCommandTest):
def setUp(self):
super().setUp()
# needed for the .call mechanism
self.char1 = self.character
def test_inventory(self):
self.call(
commands.CmdInventory(),
"inventory",
"""
You are fighting with your bare fists and have no shield.
You wear no armor and no helmet.
Backpack is empty.
You use 0/11 equipment slots.
""".strip(),
)