def __init__(self, name, owner=None): super(Room, self).__init__(name, None, owner) self.locks.insert = locks.Pass() self.locks.remove = locks.Pass() self.locks.take = locks.Fail() with locks.authority_of(locks.SYSTEM): self.type = "room"
def test_stealing_equipment_askingforit(self): with locks.authority_of(locks.SYSTEM): self.neighbor.locks.remove = locks.Pass() self.objects["monocle"].location = self.neighbor self.objects["monocle"].equipped = True self.assert_response("take monocle from playersneighbor", "You can't, it's equipped.") self.objects["monocle"].lock_attr("equipped", set_lock = locks.Pass()) self.assert_response("take monocle from playersneighbor", "You take monocle from PlayersNeighbor.")
def __init__(self, name, source, destination, owner=None, lock=None): super(Exit, self).__init__(name, source, owner) with locks.authority_of(locks.SYSTEM): self.type = 'exit' self.destination = destination if lock is None: self.locks.go = locks.Pass() else: self.locks.go = lock self.depart_message = "{player} leaves through {exit}." self.arrive_message = "{player} arrives."
def __init__(self, name, location=None, owner=None): """ Create a brand-new object and add it to the database. Args: name, location (default None), owner (defaults to current authority) as described in the class docstring """ lock = locks.AttributeLock(locks.SYSTEM, locks.Fail(), locks.Fail()) super(Object, self).__setattr__("attr_locks", {"attr_locks": lock}) if owner is not None: owner_ = owner else: if locks.authority() is not None: owner_ = locks.authority() else: raise locks.MissingAuthorityError("Object created with no " "owner and no authority.") with locks.authority_of(locks.SYSTEM): self.uid = None # This will be assigned when we call store() self.type = 'thing' self.owner = owner_ self.name = name self.lock_attr("name", set_lock=locks.Owns(self)) self.lock_attr("owner", set_lock=locks.Owns(self)) self.locks = Locks() self.lock_attr("locks", set_lock=locks.Fail()) self._location = None with locks.authority_of(self.owner): self.description = "You see nothing special." self.locks.take = locks.Pass() self.locks.drop = locks.Pass() self.locks.insert = locks.Is(self) self.locks.remove = locks.Is(self) self.locks.destroy = locks.Owns(self) if location: self.location = location
def test_stealing_askingforit(self): with locks.authority_of(locks.SYSTEM): bystander = self.new_player("Bystander") self.neighbor.locks.remove = locks.Pass() self.objects["monocle"].location = self.neighbor self.assertEqual(self.objects["monocle"].location, self.neighbor) self.assert_response("take monocle from playersneighbor", "You take monocle from PlayersNeighbor.") self.assertEqual(self.neighbor.send.call_args[0][0], "Player takes monocle from you.") self.assertEqual(bystander.send.call_args[0][0], "Player takes monocle from PlayersNeighbor.") self.assertEqual(self.objects["monocle"].location, self.player)
def test_or(self): true = locks.Pass() false = locks.Fail() self.assertTrue(locks.Or(true)(self.player)) self.assertFalse(locks.Or(false)(self.player)) self.assertTrue(locks.Or(true, true)(self.player)) self.assertTrue(locks.Or(true, false)(self.player)) self.assertTrue(locks.Or(false, true)(self.player)) self.assertFalse(locks.Or(false, false)(self.player)) self.assertTrue(locks.Or(false, false, true)(self.player)) self.assertFalse(locks.Or(false, false, false)(self.player))
def __init__(self, name, location=None, owner=None): super(Container, self).__init__(name, location, owner) self.locks.insert = locks.Pass() self.locks.remove = locks.Pass()
def test_not(self): self.assertFalse(locks.Not(locks.Pass())(self.player)) self.assertTrue(locks.Not(locks.Fail())(self.player))
def test_pass(self): lock = locks.Pass() self.assertTrue(lock(self.player)) self.assertTrue(lock(self.player2))
def test_give_succeed(self): self.neighbor.locks.insert = locks.Pass() self.assertEqual(self.objects["monocle"].location, self.player) self.assert_response("give monocle to playersneighbor", "You give monocle to PlayersNeighbor.") self.assertEqual(self.objects["monocle"].location, self.neighbor)