Ticket #121: zenbitz_dialoge.patch

File zenbitz_dialoge.patch, 15.6 KB (added by zenbitz, 10 years ago)

Patch for dialogue demo

  • scripts/dialogue.py

     
    209209                self.callbacks["complete_quest"](state, \ 
    210210                                                 command.get("complete_quest")) 
    211211 
     212            elif command.get("meet"): 
     213                self.callbacks["meet"](state, \ 
     214                                                 command.get("meet")) 
     215 
     216            elif command.get("get_stuff"): 
     217                self.callbacks["get_stuff"](state, \ 
     218                                                 command.get("get_stuff")) 
     219 
     220            elif command.get("take_stuff"): 
     221                self.callbacks["take_stuff"](state, \ 
     222                                                 command.get("take_stuff")) 
     223                 
    212224            elif command.get("dialogue"): 
    213225                command = command.get("dialogue") 
    214226                if command == "end": 
  • dialogue/fguard.yaml

     
     1#   This file is part of PARPG. 
     2 
     3#   PARPG is free software: you can redistribute it and/or modify 
     4#   it under the terms of the GNU General Public License as published by 
     5#   the Free Software Foundation, either version 3 of the License, or 
     6#   (at your option) any later version. 
     7 
     8#   PARPG is distributed in the hope that it will be useful, 
     9#   but WITHOUT ANY WARRANTY; without even the implied warranty of 
     10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     11#   GNU General Public License for more details. 
     12 
     13#   You should have received a copy of the GNU General Public License 
     14#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>. 
     15 
     16--- 
     17NPC: Janie 
     18AVATAR: gui/icons/fguard.png 
     19START: main_dialog 
     20 
     21SECTIONS: 
     22    main_dialog: 
     23        - say: "Halt, identify yourself!" 
     24        - responses: 
     25            - 
     26              - "Whoa, easy with that weapon, sister" 
     27              - first_impression 
     28              - not pc.met('janie') 
     29            -  
     30              - "I'm the beer savior, remember?" 
     31              - gratitude 
     32              - pc.hasSatisfiedQuest('beer')  
     33            -  
     34              - "It's me - don't you remember?" 
     35              - old_pals 
     36              - pc.met('janie') 
     37            # The 'end' section ends the conversation 
     38            - 
     39              - "Sorry, didn't mean to startle you. I'll just be moving along now." 
     40              - end 
     41 
     42    first_impression: 
     43        - say: "Hey Stranger.  You're new around here, I don't recognize your face..." 
     44        - meet: janie 
     45        - responses: 
     46            - 
     47              - "Yeah, just blew in with the last storm." 
     48              - elaborate_fedex 
     49              - pc.canAcceptQuest('fedex') 
     50            # above should always be true since there is no other way to get the quest   
     51            - 
     52              - "But one night with me, babe, and you'll never forget it" 
     53              - rude_comeon 
     54  
     55    elaborate_fedex: 
     56        - say: "Well, maybe you can do me a favor.   I have this package I need delivered 
     57        to Pekko.  But you gotta be casual about it.  No one can know you why you are looking for him." 
     58        - responses:  
     59            -  
     60              - "Me?  Why Me?" 
     61              - why_me 
     62            -   
     63              - "Why the secrecy?" 
     64              - why_secret 
     65            - 
     66              - "What's in it for me?" 
     67              - what_do_i_get 
     68            - 
     69              - "Whatever, I need an excuse to wander around anyway." 
     70              - quest_fedex 
     71            -  
     72              - "Find another errand boy." 
     73              - end 
     74  
     75    why_me: 
     76        - say: "No one knows you.  You're new here.  You can be expected to be wandering around being nosy." 
     77        - responses: 
     78           - 
     79             - "I'm still not convinced." 
     80             - back 
     81           -  
     82             - "Beats watching nuthin' on TV." 
     83             - quest_fedex 
     84  
     85    why_secret: 
     86        - say: "Look buddy, it's no questions asked.  You think you are the only frozen bum to come wandering in here?" 
     87        - responses: 
     88           - 
     89             - "Bum?  You don't even know who I am." 
     90             - why_me 
     91           -  
     92             - "Really.  I remain unswayed by your logic, but you are pleasing to the eye so keep talking." 
     93             - back  
     94           - 
     95             - "No need to get testy, I'll do it." 
     96             - quest_fedex 
     97  
     98    what_do_i_get: 
     99        - say:  "Everybody wants something, huh.  I suppose my undying gratitude won't cut it?  How about a beaver pelt?  They make great hats..." 
     100        - responses: 
     101           -  
     102             - "Naw, it's OK, your gratitude's enough for me." 
     103             - quest_fedex 
     104           -  
     105             - "A beaver pelt it is, then!" 
     106             - quest_fedex 
     107             # perhaps assign this agreed upon payment to the quest object? 
     108           -  
     109             - "I already gotta hat.  Deliver your own package." 
     110             - end 
     111         
     112    quest_fedex:            
     113         # Need some way of triggering the change in game state; package moving from Janie's inventory to yours] 
     114         - say:  "You should be able to find Pekko in the main compound area.  If anyone asks you why you are looking for him, 'say that he promised you something'.  Pekko's always making promises.  Oh, and don't open the box. [ Janie hands you the package ]" 
     115         - start_quest: fedex 
     116         - get_stuff: box 
     117         - responses: 
     118           -  
     119             - "Why can't I open the box?" 
     120             - why_no_open 
     121           -  
     122             - "You got it, boss." 
     123             - old_pals 
     124  
     125    why_no_open: 
     126        - say: "You are the nosiest little mailman anywhere, ain'tcha?  How about 'it's private.'?  If I wanted you to know what it was, I wouldn't have wasted a perfectly good box it, now would I?" 
     127        - responses: 
     128           - 
     129             - "I guess not." 
     130             - old_pals         
     131 
     132    old_pals: 
     133        - say: "So what can I do for you?" 
     134        - responses: 
     135           - 
     136             - "I'm trying to make beer, can you help me find some stuff?" 
     137             - help_beer 
     138             - pc.questIsCurrent("beer") 
     139           - 
     140             - "I guess I'll see if I can't find this Pekko character for you." 
     141             - end 
     142             - pc.questIsCurrent("fedex") 
     143           - 
     144             - "Uh, I opened the box." 
     145             - open_box 
     146             #- pc.questIsCurrent('fedex') and 'box' in pc.inventory and box.isOpen 
     147             - box.state == "open" 
     148           - 
     149             - "I have some bad news.  I found your friend, Pekko.  In the water tank.  Dead." 
     150             - dead_delivery_target 
     151             - pc.questIsCurrent('fedex')  
     152             # for this last conditional, we need some way of checking "partial" state of the  
     153             # quest - that the PC has found the dead Pekko, but for now we'll assume it's true 
     154 
     155    help_beer: 
     156        - say: "Well, what do you need?" 
     157        - responses: 
     158           - 
     159             - "Some kind of grain, or fruit or something." 
     160             - help_grain 
     161           - 
     162             - "I'm really looking for some brewer's yeast." 
     163             - help_yeast 
     164           - 
     165             - "I need a pot to cook the mash in." 
     166             - help_pot 
     167           - 
     168             - "It would be great if I had some bottles to put the brew in!" 
     169             - help_bottles 
     170           -  
     171             - "I think I can handle it from here." 
     172             - back 
     173 
     174    help_grain: 
     175        - say: "You could try the farm, and there should be some food in the storerooms" 
     176        - responses: 
     177           - 
     178             - "Thanks, I'll try that." 
     179             - back 
     180 
     181    help_yeast: 
     182        - say: "You got me.  I wonder if there is even any left at all." 
     183        - responses: 
     184           - 
     185             - "Someone must have some!" 
     186             - back 
     187 
     188    help_pot: 
     189        - say: "Did you try the kitchen?  Or the storerooms?" 
     190        - responses: 
     191           - 
     192             - "Uh, yeah.  I guess that was obvious." 
     193             - back 
     194 
     195    help_bottles: 
     196        - say: "All the random junk is downstairs in old parking lot.  We have our own little junkyard." 
     197        - responses: 
     198           - 
     199             - "Oooh... there is probably lots of good stuff down there." 
     200             - back 
     201 
     202    open_box: 
     203        - say: "What!  You little worm!  Why did you do that!" 
     204        - responses: 
     205           - 
     206             - "Well, I figured since Pekko was dead and all..." 
     207             - dead_delivery_target 
     208             - pc.questIsCurrent('fedex')  
     209             # pc.hasQuest("fedex") == "deadPekko" again might be tested here 
     210           - 
     211             - "I'm sorry, I was just curious." 
     212             - rewrap_box 
     213              
     214    dead_delivery_target: 
     215       - say: "He's dead?  Well, I'm too late then. I guess you can keep the boots, then." 
     216       - responses: 
     217          - 
     218            - "What boots?" 
     219            - boot_gift 
     220            - box.state == 'closed' 
     221          - 
     222            - "Yeah, I figured he wouldn't need them.  Why did you send him boots, anyway?" 
     223            - explain_boots 
     224            - box.state == 'open' or 'boots' in pc.inventory 
     225     
     226    boot_gift: 
     227       - say: "That's what was in the package. [Janie takes boots out of the package, and gives them to you]" 
     228       - get_stuff: boots 
     229       - responses: 
     230          - 
     231            - "Oh.  I must be missing something..." 
     232            - explain_boots 
     233     
     234    explain_boots: 
     235       - say: "The boots were a signal that he should leave town... that he'd gone too far this time." 
     236       - complete_quest: fedex 
     237       - responses: 
     238          - 
     239            - "You knew about this?  Who do you think killed him?" 
     240            - discuss_murder 
     241          - 
     242            - "I think I know who killed him." 
     243            - discuss_murder 
     244     
     245    discuss_murder: 
     246       - say: "Look.  Just stay out of it.  It's not really your business anyway, Stranger.  Just forget we ever talked." 
     247       - responses: 
     248          - 
     249            - "Alright, Alright.  But I don't like it." 
     250            - end 
     251                
     252    rewrap_box: 
     253       - say: "Give me that back! [Janie takes boots from PC and rewraps them].  Now, here.  And don't open it again." 
     254       - take_stuff: boots 
     255       - give_stuff: box 
     256       - responses: 
     257          - 
     258            - "OK, It will never happen again." 
     259            - old_pals 
     260            - box.close  
     261            # (always returns true) 
     262            # PC has to get a rewrapped box, and box must be set to "closed" again. 
     263 
     264    gratitude:  
     265        # if pc.hasSatisfiedQuest("beer") returns an integer representing  
     266        # quality of beer, we can add more varied responses 
     267        - say: "Well aren't you just a thick slice of awesome." 
     268        - responses: 
     269           -  
     270             - "I try, I try." 
     271             - old_pals 
     272     
     273    rude_comeon: 
     274        - say: "[fondles weapon] I hope you can take it as well as you give it..." 
     275        - responses: 
     276            - 
     277              - "Any way you want it, that's the way you need it!" 
     278              - end 
     279  
     280 No newline at end of file 
  • run.py

     
    1 #!/usr/bin/python 
     1#!/usr/bin/env python 
    22 
    33#   This program is free software: you can redistribute it and/or modify 
    44#   it under the terms of the GNU General Public License as published by 
  • dialogue-demo.py

     
    1 #!/usr/bin/python 
     1#!/usr/bin/env python 
    22 
    33#   This file is part of PARPG. 
    44 
     
    3232    def __init__(self): 
    3333        self.current_quests = set() 
    3434        self.finished_quests = set() 
     35        self.inventory = set() 
     36        self.peopleIknow = set() 
    3537 
    3638    def canAcceptQuest(self, quest): 
    3739        return     quest not in self.finished_quests \ 
    3840               and quest not in self.current_quests 
    3941 
    4042    def hasSatisfiedQuest(self, quest): 
     43        return quest in self.finished_quests 
     44     
     45    def questIsCurrent(self,quest): 
    4146        return quest in self.current_quests 
    4247 
    4348    def startQuest(self, quest): 
     
    4853    def completeQuest(self, quest): 
    4954        self.finished_quests.add(quest) 
    5055        self.current_quests.remove(quest) 
     56     
     57    def meet(self,npc): 
     58        if npc in self.peopleIknow: 
     59            raise RuntimeError("I already know %s" % npc) 
     60        self.peopleIknow.add(npc) 
     61         
     62    def met(self,npc): 
     63        return npc in self.peopleIknow 
     64         
     65class Box(object): 
     66    """ 
     67    Mock box object than can be opened or closed 
     68    This would normally be a container 
     69    """ 
     70    def __init__(self): 
     71        self.state = 'closed' 
     72         
     73    def isOpen(self): 
     74        # for some reason this callback always returns true 
     75        if self.state == 'open': 
     76            return self.state 
     77        else: 
     78            return FALSE 
     79     
     80    def isClosed(self): 
     81        # for some reason this callback always returns true 
     82        if self.state == 'closed': 
     83             return self.state 
     84        else: 
     85             return FALSE 
     86         
     87    def open(self): 
     88        self.state = 'open' 
     89        return self.state 
     90     
     91    def close(self): 
     92        self.state = 'closed' 
     93        return self.state 
     94     
     95def main(dialogue_file): 
    5196 
    52 def main(): 
    53  
    5497    # set up some closures 
    5598    def say_cb(state, text): 
    5699        print "NPC says:", text 
     
    64107        return val 
    65108 
    66109    def start_quest(state, quest): 
    67         print "You've picked up the '%s' quest!" % quest, 
     110        print "You've picked up the '%s' quest!" % quest 
    68111        state['pc'].startQuest(quest) 
    69112 
    70113    def complete_quest(state, quest): 
    71114        print "You've finished the '%s' quest" % quest 
    72115        state['pc'].completeQuest(quest) 
     116  
     117    def meet(state, npc): 
     118        print "You've met %s!" % npc 
     119        state['pc'].meet(npc) 
     120        
     121    def get_stuff(state, thing): 
     122        if thing not in state['pc'].inventory: 
     123            state['pc'].inventory.add(thing) 
     124            print "You've now have the %s" % thing 
     125     
     126    def take_stuff(state,thing): 
     127        if thing in state['pc'].inventory: 
     128            state['pc'].inventory.remove(thing) 
     129            print "You no longer have the %s" % thing 
    73130 
    74131    callbacks = { 
    75132        "say": say_cb, 
    76133        "start_quest": start_quest, 
    77         "complete_quest": complete_quest 
     134        "complete_quest": complete_quest, 
     135        "meet": meet, 
     136        "get_stuff" : get_stuff, 
     137        "take_stuff" : take_stuff 
    78138    } 
    79139 
    80140    pc = Player() 
    81  
     141    box = Box() 
     142     
    82143    state = { 
    83144        'quests': {}, 
    84         'pc': pc 
     145        'pc': pc, 
     146        'box': box 
    85147    } 
    86148 
    87     dialog = dialogue.DialogueEngine('dialogue/sample.yaml', callbacks, state) 
     149    dialog = dialogue.DialogueEngine(dialogue_file, callbacks, state) 
    88150    responses = dialog.run() 
    89151    while responses: 
    90152        choice = get_reply(responses) 
    91153        responses = dialog.reply(choice) 
    92154 
    93155if __name__ == "__main__": 
    94     main() 
     156    dialogue_file = 'dialogue/sample.yaml' 
     157    if len(sys.argv) > 1: 
     158        dialogue_file = sys.argv[1] 
     159         
     160    main(dialogue_file) 
  • run_tests.py

     
    1 #!/usr/bin/python 
     1#!/usr/bin/env python 
    22 
    33#   This program is free software: you can redistribute it and/or modify 
    44#   it under the terms of the GNU General Public License as published by