source: trunk/PARPG/scripts/agents/hero.py @ 181

Revision 181, 5.3 KB checked in by bretzel_parpg, 11 years ago (diff)

When you press the open button on a crate, it now will move you to the crate and display a dialog with
9 slots to show the contents of the crate. The dialog will interface with the inventory.

  • Property svn:eol-style set to native
Line 
1#!/usr/bin/python
2
3#   This program 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#   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
15
16import fife
17from settings import Setting
18
19TDS = Setting()
20_STATE_NONE, _STATE_IDLE, _STATE_RUN, _STATE_TALK = xrange(4)
21
22class Hero(fife.InstanceActionListener):
23    def __init__(self, agentName, layer, engine):
24        """This is the class we use for the PC character.
25           @type agentName: string
26           @param agentName: name of the agent
27           @type layer: string
28           @param layer: Layer to place agent on.
29           @type engine: scripts.engine.Engine
30           @param engine: Reference to the engine that owns this PC.
31           @return: None"""
32        # add this class for callbacks from fife itself
33        fife.InstanceActionListener.__init__(self)
34        self.agentName = agentName
35        self.agent = layer.getInstance(agentName)
36        self.agent.addActionListener(self)
37        self.state = _STATE_NONE
38        self.idlecounter = 1
39        self.speed = float(TDS.readSetting("PCSpeed"))
40        self.engine = engine
41        self.atBox = False
42       
43    def onNewMap(self, layer):
44        """Sets the agent onto the new layer.
45        """
46        self.agent = layer.getInstance(self.agentName)
47        self.agent.addActionListener(self)
48        self.state = _STATE_NONE
49        self.idlecounter = 1
50
51    def getX(self):
52        """ Get the Hero's position on the map.
53            @rtype: integer
54            @return: the x coordinate of the NPC's location"""
55        return self.agent.getLocation().getLayerCoordinates().x
56
57    def getY(self):
58        """ Get the Hero's position on the map.
59            @rtype: integer
60            @return: the y coordinate of the NPC's location"""
61        return self.agent.getLocation().getLayerCoordinates().y
62
63    def onInstanceActionFinished(self, instance, action):
64        """@type instance: ???
65           @param instance: ???
66           @type action: ???
67           @param action: ???
68           @return: None"""
69        if action.getId() == 'approachDoor':
70            # issue map change
71            self.engine.changeMap(self.targetMap, self.targetLocation)
72        if self.state == _STATE_TALK:
73            # TODO: do something
74            pass
75        if self.atBox == True:
76            self.engine.view.createBoxGUI()
77            self.atBox = False
78        self.idle()
79        if(action.getId() != 'stand'):
80            self.idlecounter = 1
81        else:
82            self.idlecounter += 1
83
84    def start(self):
85        """@return: None"""
86        self.idle()
87
88    def idle(self):
89        """@return: None"""
90        self.state = _STATE_IDLE
91        self.agent.act('stand', self.agent.getFacingLocation())
92
93    def run(self, location):
94        """@type location: ???
95           @param location: ???
96           @return: None"""
97        self.state = _STATE_RUN
98        self.agent.move('run', location, self.speed)
99
100    def approachNPC(self, npcLoc):
101        """Approaches an npc and then ???.
102           @type npcLoc: fife.Location
103           @param npcLoc: the location of the NPC to approach
104           @return: None"""
105        self.state = _STATE_TALK
106        self.agent.move('run', npcLoc, self.speed)
107
108    def approachDoor(self, doorLocation, map, targetLocation):
109        """Approach a door and then teleport to the new map.
110           @type doorLocation: list
111           @param doorLocation: list that is converted to a fife.Location
112            that tells the PC where the door is
113           @type map: ???
114           @param map: ???
115           @type targetLocation: list
116           @param targetLocation: list that is converted to a tuple
117            that tels the PC where it should appear on the target map
118           @return: None"""
119        # The casting here is HORRIBLE, but I think it is preferable to having
120        # doors behave differently than other objects, hence the change.
121        self.state = _STATE_RUN
122        targetLocation = tuple([int(float(i)) for i in targetLocation])
123        doorLocation = tuple([int(float(i)) for i in doorLocation])
124        self.targetMap = map
125        self.targetLocation = targetLocation
126        l = fife.Location(self.agent.getLocation())
127        l.setLayerCoordinates(fife.ModelCoordinate(*doorLocation))
128        self.agent.move('approachDoor', l, self.speed)
129
130    def approachBox(self, location):
131        """
132        Approach a box and then open it
133        @type location: list
134        @param locatation: list that is converted to a fife.Location
135        @return: None
136        """
137        self.state = _STATE_RUN
138        boxLocation = tuple([int(float(i)) for i in location])
139        l = fife.Location(self.agent.getLocation())
140        l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation))
141        self.agent.move('run', l, self.speed)
142        self.atBox = True
143
Note: See TracBrowser for help on using the repository browser.