Esempio n. 1
0
 def DoObject(self, target, game):
     object = target.value
     m, reward, result = "", 0, Response.IllegalCommand
     if target.IsObject() and\
             (type(object.placement) == InventoryPlacement or object.placement.location == game.state.location):
         m = None
         if not object.moveable:
             m = "I CAN'T CARRY THAT!"
         elif game.state.inventory.Has(object):
             m = "I ALREADY HAVE IT."
             result = Response.Success
         elif game.state.inventory.capacity == len(
                 game.state.inventory.Get(game.world)):
             m = "I CAN'T CARRY ANYMORE."
         elif object.moveable:
             if Response.HasResponse(object.responses, self):
                 m, reward, result = Response.Respond(
                     object.responses, self, game)
             game.state.inventory.Add(object)
             if m is None:
                 m = ""
             if m != "":
                 m = '\n' + m
             m = "O.K." + m
             result = Response.MightBeUseful
     else:
         m = "I DON'T SEE THAT HERE."
     return m, reward, result
Esempio n. 2
0
 def DoObject(self, target, game):
     if target.IsObject() and game.state.inventory.Remove(target.value):
         game.CreateHere(target.value)
         m = ""
         if target.IsObject() and Response.HasResponse(
                 target.value.responses, self):
             m, reward, result = Response.Respond(target.value.responses,
                                                  self, game)
         if m == "":
             return "O.K. I DROPPED IT.", 0, Response.Success
         else:
             return m, reward, result
     else:
         return "I DON'T SEEM TO BE CARRYING IT.", 0, Response.IllegalCommand
Esempio n. 3
0
 def DoObject(self, target, game):
     m, reward, result = "", 0, Response.IllegalCommand
     if target is not None and target is not '' and target.IsObject():
         object = target.value
         m = None
         if object.responses is not None:
             m, reward, result = Response.Respond(object.responses, self,
                                                  game)
         if m is None or m == "":
             m = "I SEE NOTHING OF INTEREST."
     else:
         m = "WE ARE " + game.state.location.Name() + "."
         for object in game.world.AtLocation(game.state.location):
             if object.visible:
                 if not m == "":
                     m += "\n"
                 m += "I CAN SEE " + object.name + "."
         moves = game.state.location.moves
         if moves.count(0) != len(moves):
             if not m == "":
                 m += "\n"
             m += "WE COULD EASILY GO: "
             for i in range(len(moves)):
                 if moves[i] != 0:
                     m += Direction.names[i] + "  "
         else:
             m += "\n"
         m += "\n>" + '-' * 62 + "<"
     return m, reward, Response.NotUseful
Esempio n. 4
0
 def DoObject(self, target, game):
     # The original game logic says that "BUT" always refers to the box button when it is possessed
     if target is not None and target.IsObject() and target.value.abbreviation[:3] == "BUT":
         if game.Has('BOX'):
             target = Target(game.world.objects['A BUTTON ON A BOX'])
             m, reward, result = Response.Respond(target.value.responses, self, game)
             return m, reward, result
     return super().DoObject(target, game)
Esempio n. 5
0
 def get_look_string(self, location=None):
     looks = []
     for object in self.game.world.objects:
         if self.has_conditional_look_response(object.responses):
             if location is None:
                 for response in Response.Responses(
                         object.responses, self.game.world.verbs['LOOK']):
                     looks += [response.kwargs['message']]
             elif type(
                     object.placement
             ) == LocationPlacement and object.placement.location == location:
                 message, reward, result = Response.Respond(
                     object.responses, self.game.world.verbs['LOOK'],
                     self.game)
                 if result == Response.Success:
                     looks += [
                         message,
                     ]
     return ' '.join(looks)
Esempio n. 6
0
    def DoObject(self, target, game):
        m, reward, result = "", 0, Response.IllegalCommand

        # Process responses from the verb
        if Response.HasResponse(self.responses, self):
            m, reward, result = Response.Respond(
                self.responses, self, game, target.value
                if target is not None and target.IsObject() else None)
            if m is not None and m != "":
                return m, reward, result

        # Process responses from the object
        if target is not None and target.IsObject() and Response.HasResponse(
                target.value.responses, self):
            m, reward, result = Response.Respond(target.value.responses, self,
                                                 game)
            if m is None or m == "":
                m = self.didntWorkMessage
                result = Response.IllegalCommand
        elif self.notApplicableMessage is not None:
            m = self.notApplicableMessage
            result = Response.IllegalCommand
        return m, reward, result
Esempio n. 7
0
 def Do(self, target, game):
     m, reward, result = "", 0, Response.IllegalCommand
     cant = "I CAN'T GO THAT WAY AT THE MOMENT."
     if target.IsDirection():
         move = game.state.location.moves[target.value.d]
         if move == 0:
             return cant, 0, Response.IllegalCommand
         game.state.location = game.world.locations[move]
         m = ""
         result = Response.Success
     elif target.IsObject():
         object = target.value
         if game.state.location == object.placement.location:
             if Response.HasResponse(object.responses, self):
                 m, reward, result = Response.Respond(
                     object.responses, self, game)
                 if not Response.IsSuccessfulResult(result) and (
                         m is None or m == ""):
                     return cant, 0, Response.IllegalCommand
             else:
                 return cant, 0, Response.IllegalCommand
         else:
             return "I DON'T SEE THAT HERE.", 0, Response.IllegalCommand
     return m, reward, result
Esempio n. 8
0
def VerbResponse(*args, **kwargs):
    return Response(None, None, *args, **kwargs)
Esempio n. 9
0
 def MakeResponse(self, f=None, *args, **kwargs):
     return Response(self, f, *args, **kwargs)
Esempio n. 10
0
 def has_conditional_look_response(self, responses):
     for response in Response.Responses(responses,
                                        self.game.world.verbs['LOOK']):
         if response.is_conditional_look_response():
             return True
     return False