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

Revision 320, 3.8 KB checked in by orlandov, 10 years ago (diff)

Ticket #100: Patch by or1andov. Specify dialogue files for NPCs in their XML map instance attribute. fixes[s:trac, t:100]

  • 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, target_map_name, target_map_file , target_pos):
27        """Initiates a change of the position of the character
28           possibly flagging a new map to be loaded.
29           @type engine: Engine reference
30           @param engine: A reference to the engine.
31           @type target_map_name: String
32           @param target_map_name: Target map id
33           @type target_map_file: String
34           @param target_map_file: Target map filename
35           @type target_pos: Tuple
36           @param target_pos: (X, Y) coordinates on the target map.
37           @return: None"""
38        self.engine = engine
39        self.target_pos = target_pos
40        self.target_map_name = target_map_name
41        self.target_map_file = target_map_file
42
43    def execute(self):
44        """Executes the map change."""
45        self.engine.changeMap(self.target_map_name, self.target_map_file,\
46                              self.target_pos)
47       
48class OpenBoxAction(Action):
49    """Open a box. Needs to be more generic, but will do for now."""
50    def __init__(self, engine, box_title):
51        """@type engine: Engine reference
52           @param engine: A reference to the engine.
53           @type box_title: String
54           @param box_title: Box title.
55           """
56        self.engine = engine
57        self.box_title = box_title
58   
59    def execute(self):
60        """Open the box."""
61        self.engine.view.hud.createBoxGUI(self.box_title)
62       
63class ExamineBoxAction(Action):
64    """Examine a box. Needs to be more generic, but will do for now."""
65    def __init__(self, engine, examine_name, examine_desc):
66        """@type engine: Engine reference
67           @param engine: A reference to the engine.
68           @type examine_name: String
69           @param examine_name: Name of the object to be examined.
70           @type examine_name: String
71           @param examine_name: Description of the object to be examined.
72           """
73        self.engine = engine
74        self.examine_name = examine_name
75        self.examine_desc = examine_desc
76       
77    def execute(self):
78        """Examine the box."""
79        self.engine.view.hud.createExamineBox(self.examine_name, \
80                                              self.examine_desc)
81
82class TalkAction(Action):
83    """An action to represent starting a dialogue"""
84    def __init__(self, engine, npc):
85        """@type engine: Engine reference
86           @param engine: A reference to the engine.
87           @type examineName: NonPlayerCharacter
88           @param examineName: NPC to interact with.
89           """
90        self.engine = engine
91        self.npc = npc
92       
93    def execute(self):
94        """Talk with the NPC."""
95        pc = self.engine.game_state.PC
96        pc.behaviour.agent.act('stand', self.npc.getLocation())
97
98        if self.npc.dialogue is not None:
99            self.npc.talk(pc)
100            self.engine.view.hud.showDialogue(self.npc)
101        else:
102            self.npc.behaviour.agent.say("Leave me alone!", 1000)
Note: See TracBrowser for help on using the repository browser.