Ignore:
Timestamp:
11/01/09 21:29:41 (10 years ago)
Author:
orlandov
Message:

Ticket #104 - Patch by Vaporice and or1andov. Integrate quests into game dialogue and make it possible to persist quest state. fixes[s:trac, t:134]

  • Integrate Vaporice's quest engine implementation
  • Discontinue or1andov's sample dialogue and use Zenbitz's Drunkard
  • Reuse Zenbitz's dialogue functions and callbacks in the game PlayerCharacter? class
  • Whitespace and style tweaks
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/dialoguegui.py

    r320 r361  
    2121from scripts.dialogue import DialogueEngine 
    2222 
    23 class Player(object): 
    24     """A mock player object until we have a proper Player/Quest model""" 
    25     def __init__(self): 
    26         self.current_quests = set() 
    27         self.finished_quests = set() 
     23class DialogueGUI(object): 
     24    def __init__(self, npc, quest_engine, pc): 
     25        self.pc = pc 
    2826 
    29     def canAcceptQuest(self, quest): 
    30         return     quest not in self.finished_quests \ 
    31                and quest not in self.current_quests 
     27        # define dialogue engine callbacks 
     28        def start_quest(state, quest): 
     29            print "You've picked up the '%s' quest!" % quest 
     30            state['quest'].addQuest(quest) 
    3231 
    33     def hasSatisfiedQuest(self, quest): 
    34         return quest in self.current_quests 
     32        def complete_quest(state, quest_id): 
     33            print "You've finished the quest %s" % quest_id 
     34            state['quest'].finishQuest(quest_id) 
    3535 
    36     def startQuest(self, quest): 
    37         if quest in self.current_quests: 
    38             raise RuntimeError("Already have quest, %s" % quest) 
    39         self.current_quests.add(quest) 
     36        def delete_quest(state, quest_id): 
     37            print "You've deleted quest %s" % quest_id 
     38            state['quest'].deleteQuest(quest_id) 
    4039 
    41     def completeQuest(self, quest): 
    42         self.finished_quests.add(quest) 
    43         self.current_quests.remove(quest) 
     40        def increase_value(state, quest_id, variable, value): 
     41            print "Increased %s by %i"%(variable,value) 
     42            state['quest'][quest_id].increaseValue(variable,value) 
    4443 
    45 class DialogueGUI(object): 
    46     def __init__(self, npc): 
     44        def decrease_value(state, quest_id, variable, value): 
     45            print "Decreased %s by %i"%(variable,value) 
     46            state['quest'][quest_id].decreaseValue(variable,value) 
     47 
     48        def set_value(state,quest_id, variable, value): 
     49            print "Set %s to %i"%(variable,value) 
     50            state['quest'][quest_id].setValue(variable,value) 
     51 
     52        def meet(state, npc): 
     53            print "You've met %s!" % npc 
     54            state['pc'].meet(npc) 
     55 
     56        def get_stuff(state, thing): 
     57            if thing not in state['pc'].inventory: 
     58                state['pc'].inventory.add(thing) 
     59                print "You've now have the %s" % thing 
     60 
     61        def take_stuff(state,thing): 
     62            if thing in state['pc'].inventory: 
     63                state['pc'].inventory.remove(thing) 
     64                print "You no longer have the %s" % thing 
     65 
    4766        dialogue_callbacks = { 
     67            "complete_quest": complete_quest, 
     68            "decrease_value": decrease_value, 
     69            "delete_quest": delete_quest, 
     70            'end': self.handleEnd, 
     71            "get_stuff" : get_stuff, 
     72            "increase_value": increase_value, 
     73            "meet": meet, 
     74            'npc_avatar': self.handleAvatarImage, 
     75            'responses': self.handleResponses, 
    4876            'say': self.handleSay, 
    49             'responses': self.handleResponses, 
    50             'start_quest': self.startQuest, 
    51             'complete_quest': self.completeQuest, 
    52             'npc_avatar': self.handleAvatarImage, 
    53             'end': self.handleEnd 
     77            "set_value": set_value, 
     78            "start_quest": start_quest, 
     79            "take_stuff" : take_stuff 
    5480        } 
    5581 
    56         # For testing purposes we're just using a a dummy player object  here 
    57         # until we decide on a player/quest model. 
    58         # TODO 
    59         # link this up to the actual PC and NPC instances, so that state can 
    60         # be persistent. 
    61         pc = Player() 
    6282        self.npc = npc 
    6383        state = { 
    64             'pc': pc 
     84            'pc': self.pc, 
     85            'quest': quest_engine 
    6586        } 
    6687        self.dialogue_engine = DialogueEngine(npc.dialogue, 
    6788                                              dialogue_callbacks, state) 
    6889        self.dialogue_gui = pychan.loadXML("gui/dialogue.xml") 
    69  
    70     def startQuest(self, state, quest): 
    71         """Callback for starting a quest""" 
    72         print "You've picked up the '%s' quest!" % quest, 
    73         state['pc'].startQuest(quest) 
    74  
    75     def completeQuest(self, state, quest): 
    76         """Callback for starting a quest""" 
    77         print "You've finished the '%s' quest" % quest 
    78         state['pc'].completeQuest(quest) 
    7990 
    8091    def initiateDialogue(self): 
Note: See TracChangeset for help on using the changeset viewer.