source: trunk/game/scripts/objects/action.py @ 287

Revision 287, 3.4 KB checked in by orlandov, 10 years ago (diff)

Ticket #74: Patch by or1andov, Integrate dialogue GUI and engine into game.

It should now be possible to engage in a conversation with NPC characters by
selecting talk from their context menu. fixes[s:trac, t:74]

Known Issues:


  • the GUI is terrible. instead of a dialog window, we could use a better looking background image and fixed position widgets
  • requires PyYAML to be installed sudo apt-get install python-yaml easy_install PyYAML
  • we have to create a simple state model for the PC can remember tasks
  • need to make NPC's be able to remember things - need a model in NPCs for this
  • no way currently to give or take items from npc's; again, more model work. this could be done by adding another callback similar to start_quest. may be necessary for npc's to have an inventory for this
  • The dialogue engine is not hooked up to specific NPC's... it currently always loads dialogue/sample.yaml - need to have the dialogue looked up from some XML attribute
  • dialogue is not broken off if the PC moves away from the NPC
  • npc image is hardcoded, it should use the image specified in the yaml file
  • Property svn:eol-style set to native
Line 
1#!/usr/bin/python
2
3#   This file is part of PARPG.
4
5#   PARPG is free software: you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation, either version 3 of the License, or
8#   (at your option) any later version.
9
10#   PARPG is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
14
15#   You should have received a copy of the GNU General Public License
16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
17
18class Action(object):
19    """Base Action class, to define the structure"""
20    def execute(self):
21        """To be overwritten"""
22        pass
23
24class ChangeMapAction(Action):
25    """A change map scheduled"""
26    def __init__(self, engine, targetmap, targetpos):
27        """@type engine: Engine reference
28           @param engine: A reference to the engine.
29           @type targetmap: String
30           @param targetmap: Target mapname.
31           @type targetpos: Tuple
32           @param targetpos: (X, Y) coordinates on the target map.
33           @return: None"""
34        self.engine = engine
35        self.targetpos = targetpos
36        self.targetmap = targetmap
37       
38    def execute(self):
39        """Executes the mapchange."""
40        self.engine.changeMap(self.targetmap, self.targetpos)
41       
42class OpenBoxAction(Action):
43    """Open a box. Needs to be more generic, but will do for now."""
44    def __init__(self, engine, boxTitle):
45        """@type engine: Engine reference
46           @param engine: A reference to the engine.
47           @type boxTitle: String
48           @param boxTitle: Box title.
49           """
50        self.engine = engine
51        self.boxTitle = boxTitle
52   
53    def execute(self):
54        """Open the box."""
55        self.engine.view.hud.createBoxGUI(self.boxTitle)
56       
57class ExamineBoxAction(Action):
58    """Examine a box. Needs to be more generic, but will do for now."""
59    def __init__(self, engine, examineName, examineDesc):
60        """@type engine: Engine reference
61           @param engine: A reference to the engine.
62           @type examineName: String
63           @param examineName: Name of the object to be examined.
64           @type examineName: String
65           @param examineName: Description of the object to be examined.
66           """
67        self.engine = engine
68        self.examineName = examineName
69        self.examineDesc = examineDesc
70       
71    def execute(self):
72        """Examine the box."""
73        self.engine.view.hud.createExamineBox(self.examineName, self.examineDesc)
74
75class TalkAction(Action):
76    """An action to represent starting a dialogue"""
77    def __init__(self, engine, npc):
78        """@type engine: Engine reference
79           @param engine: A reference to the engine.
80           @type examineName: String
81           @param examineName: Name of the object to be examined.
82           @type examineName: String
83           @param examineName: Description of the object to be examined.
84           """
85        self.engine = engine
86        self.npc = npc
87       
88    def execute(self):
89        """Examine the box."""
90        pc = self.engine.gameState.PC
91        pc.behaviour.agent.act('stand', self.npc.getLocation())
92        self.npc.talk(pc)
93        self.engine.view.hud.showDialogue(self.npc)
Note: See TracBrowser for help on using the repository browser.