source: trunk/game/scripts/agents/hero.py @ 21

Revision 21, 1.4 KB checked in by icelus_parpg, 10 years ago (diff)

Apply ActionStack? patch from tie (ticket #1).

  • queue actions for hero to perform (e.g. move to target, act)
  • unit tests for ActionStack?
  • new run_tests script
  • kick added as an always present to allow queueing to be seen.
  • Property svn:eol-style set to native
Line 
1import random
2from agent import Agent
3from settings import Setting
4
5TDS = Setting()
6
7_STATE_NONE, _STATE_IDLE, _STATE_RUN, _STATE_KICK, _STATE_TALK = xrange(5)
8
9class Hero(Agent):
10        def __init__(self, model, agentName, layer, uniqInMap=True):
11                super(Hero, self).__init__(model, agentName, layer, uniqInMap)
12                self.state = _STATE_NONE
13                self.idlecounter = 1
14
15        def onInstanceActionFinished(self, instance, action):
16                if self.action_stack and self.action_stack.run():
17                        # The stack executed something, ignore state change
18                        return
19                self.idle()
20                if action.getId() != 'stand':
21                        self.idlecounter = 1
22                else:
23                        self.idlecounter += 1
24                if self.idlecounter % 7 == 0:
25                        heroTexts = TDS.readSetting("heroTexts", type='list', text=True)
26                        txtindex = random.randint(0, len(heroTexts) - 1)
27                        instance.say(heroTexts[txtindex], 2500)
28
29        def start(self):
30                self.idle()
31
32        def idle(self):
33                self.state = _STATE_IDLE
34                self.agent.act('stand', self.agent.getFacingLocation())
35
36        def run(self, location):
37                self.state = _STATE_RUN
38                self.agent.move('run', location, 4 * float(TDS.readSetting("TestAgentSpeed")))
39
40        def kick(self, target):
41                self.state = _STATE_KICK
42                self.agent.act('kick', target)
43
44        def talk(self, target):
45                self.state = _STATE_TALK
46                self.agent.act('talk', target)
47       
48        def distance_to (self, target):
49                return self.agent.getLocationRef().getLayerDistanceTo(target.getLocationRef())
Note: See TracBrowser for help on using the repository browser.