24 key_status =
'campfire_status'
25 key_line =
'campfire_line'
26 key_story =
'campfire_story'
28 status_pause =
'pause'
31 '''Main handling class.'''
34 '''Called when the player talks to the firecamp.'''
35 w = Crossfire.WhoAmI()
37 if ( Crossfire.WhatIsMessage() ==
'story' ):
38 if w.ReadKey(key_status) ==
'':
39 w.Say(
'So you want a story, he... All right.')
40 if w.ReadKey(key_story) ==
'':
42 w.WriteKey(key_status, status_read, 1)
43 w.WriteKey(key_line,
'0', 1)
45 elif ( Crossfire.WhatIsMessage() ==
'pause' ):
46 if w.ReadKey(key_status) == status_read:
47 w.Say(
'Sure, let\'s rest some.')
48 w.WriteKey(key_status, status_pause, 1)
49 elif ( Crossfire.WhatIsMessage() ==
'resume' ):
50 if w.ReadKey(key_status) == status_pause:
51 w.Say(
'Ok, let\'s continue.')
52 w.WriteKey(key_status, status_read, 1)
53 elif ( Crossfire.WhatIsMessage() ==
'stop' ):
54 if w.ReadKey(key_status) !=
'':
55 w.WriteKey(key_status,
'', 1)
56 w.WriteKey(key_story,
'', 1)
57 w.Say(
'Hump, very well, I\'ll keep quiet from now on.')
60 '''Returns a random story from the stories directory, internal use.'''
61 story_dir = os.path.join( Crossfire.DataDirectory(),
'stories' )
62 stories = os.listdir(story_dir)
63 return stories[random.randint(0, len(stories) - 1)]
66 '''Called when the firecamp's timer expire. Sends more of the story.'''
67 w = Crossfire.WhoAmI()
68 if w.ReadKey(key_status) ==
'':
72 line =
int(
'0' + w.ReadKey(key_line))
74 if w.ReadKey(key_status) == status_pause:
78 f =
open(os.path.join( Crossfire.DataDirectory(),
'stories', w.ReadKey(key_story)),
'r')
79 c = f.read().
split(
'\n')
81 w.Say(
'End of story.')
82 w.WriteKey(key_status,
'', 1)
83 w.WriteKey(key_line,
'0', 1)
84 w.WriteKey(key_story,
'', 1)
87 w.CreateTimer(len(c[line]) / 10,1)
89 w.WriteKey(key_line,
str(line), 1)