Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 100.check-actor-int…
Browse files Browse the repository at this point in the history
…erface-early
  • Loading branch information
exarkun committed Nov 15, 2020
2 parents 1f06e3d + 53fe250 commit 96f1775
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/imaginary/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def parseImpl(self, instring, loc, doActions=True):



orLiterals = lambda xs: pyparsing.Or(map(pyparsing.Literal, xs))



class _ActionType(type):
actions = []
def __new__(cls, name, bases, attrs):
Expand Down Expand Up @@ -575,8 +579,7 @@ def targetTaken(player, target, container=None):


class Remove(TargetAction):
expr = ((pyparsing.Literal("remove") |
pyparsing.Literal("take off")) +
expr = (orLiterals(["remove", "take off"]) +
pyparsing.White() +
targetString("target"))

Expand Down Expand Up @@ -645,7 +648,7 @@ def do(self, player, line):
class TakeFrom(ToolAction):
actionName = "take"

expr = ((pyparsing.Literal("get") ^ pyparsing.Literal("take")) +
expr = (orLiterals(["get", "take"]) +
pyparsing.White() +
targetString("target") +
pyparsing.Optional(pyparsing.White() +
Expand Down Expand Up @@ -903,14 +906,9 @@ def do(self, player, line, direction):


class Go(Action):
expr = (
(pyparsing.Literal("go") + pyparsing.White() +
targetString("direction")) |
(pyparsing.Literal("enter") + pyparsing.White() +
targetString("direction")) |
(pyparsing.Literal("exit") + pyparsing.White() +
targetString("direction")) |
DIRECTION_LITERAL)
_goVerbs = orLiterals(["go", "enter", "exit"])
_goForm = _goVerbs + pyparsing.White() + targetString("direction")
expr = _goForm | DIRECTION_LITERAL

actorInterface = iimaginary.IThing

Expand Down Expand Up @@ -952,6 +950,13 @@ def do(self, player, line, direction):
actor=player,
actorMessage=language.ExpressString(
u"There's no room for you there.")))
except eimaginary.Closed:
raise eimaginary.ActionFailure(events.ThatDoesntWork(
actor=player,
actorMessage=language.ExpressString(
u"The way is shut.",
),
))

# This is subtly incorrect: see http://divmod.org/trac/ticket/2917
lookAroundActor = iimaginary.IActor(player)
Expand Down Expand Up @@ -1003,9 +1008,7 @@ def do(self, player, line, target):


class Hit(TargetAction):
expr = ((pyparsing.Literal("hit") ^
pyparsing.Literal("attack") ^
pyparsing.Literal("kill")) +
expr = (orLiterals(["hit", "attack", "kill"]) +
pyparsing.White() +
pyparsing.restOfLine.setResultsName("target"))

Expand Down
51 changes: 51 additions & 0 deletions src/imaginary/test/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,21 @@ def test_directionalMovement(self):
""])


def test_goClosed(self):
"""
You cannot move through an exit to a "closed" location.
"""
unreachable = objects.Thing(store=self.store, name=u"unreachable")
objects.Container.createFor(unreachable, capacity=1000, closed=True)
objects.Exit.link(self.location, unreachable, u"west")

self._test(
"west",
["The way is shut."],
[],
)


def test_scrutinize(self):
"""
The scrutinize action takes a thing as a target and displays a lot of
Expand Down Expand Up @@ -889,3 +904,39 @@ def test_helpMultiword(self):
self._test("help foo bar", ["baz"], [])
finally:
Help.helpContentPath = original


def test_hit(self):
"""
The hit action removes some hitpoints from the target.
"""
self._violenceTest("hit")


def test_kill(self):
"""
The hit action has I{kill} as an alias.
"""
self._violenceTest("hit")


def test_attack(self):
"""
The hit action has I{attack} as an alias.
"""
self._violenceTest("hit")


def _violenceTest(self, verb):
fuzzy = self.world.create(u"fuzzy", proper=True)
# Flush the buffer to simplify the real assertion.
self.assertCommandOutput(
None,
["Fuzzy arrives."],
["Fuzzy arrives."],
)
self.assertCommandOutput(
verb + " fuzzy",
["You hit fuzzy for [12345] hitpoints."],
["Test Player hits fuzzy."],
)

0 comments on commit 96f1775

Please sign in to comment.