Debian Codegraph @

python/maps/witherspoon_manor/ghost.py

raw
1 '''
2 This script is part of the Witherspoon quest, that starts in /scorn/mansion/witherspoon_manor_attic.
3 Check the README file in the same directory as this file for more details.
4
5 Script for the ghost in Witherspoon manor (south-east of Scorn).
6 '''
7
8 import random
9 import Crossfire
10 from CFDialog import DialogRule, Dialog
11
12 key_angry = 'ghost_angry'
13 key_disappear = 'ghost_disappear'
14
15 def warn_player(player, ghost):
16 '''Ghost is about to become angry, warn the player so she can flee before it's too late!'''
17 if player.Level < ghost.Level:
18 player.Write('You feel a very powerful force gather around the %s! Your instinct tell you you\'d rather feel fast!'%ghost.Name)
19 else:
20 player.Write('You feel a really powerful force gather around the %s! Time to start fleeing, maybe?'%ghost.Name)
21
22 drop = ghost.Map.CreateObject('reeking_urine', player.X, player.Y)
23 player.Write('You feel so frightened you can\'t control your bladder!')
24
25 def check_body(player, rule):
26 '''Did the player already dig?'''
27 if player.ReadKey('witherspoon_tomb') != 'dig':
28 return True
29
30 return False
31
32 def start_disappear(ghost, player):
33 '''ghost should disappear, called for 2 endings.'''
34 ghost.WriteKey(key_disappear, '1', 1)
35 ghost.CreateTimer(5, 1)
36 ghost.StandStill = True
37 player.Write('The %s starts fading...'%ghost.Name)
38 if player.QuestGetState("scorn/Witherspoon-ghost") <= 50:
39 player.QuestSetState("scorn/Witherspoon-ghost", 60)
40
41 def found_body(player, rule):
42 '''Does the player have the body?'''
43 if player.ReadKey('witherspoon_tomb') != 'dig':
44 return False
45
46 player.WriteKey('witherspoon_tomb', '', 1)
47 #reset our dialog anyway - the player did dig, so quest ends (nicely or badly)
48 player.WriteKey('dialog_witherspoon_ghost', '', 1)
49
50 #try to find the body, if not found then get angry
51 body = player.CheckInventory('tortured body')
52
53 ghost = Crossfire.WhoAmI()
54
55 if body:
56 #all fine!
57 body.Remove()
58 start_disappear(ghost, player)
59 return 1
60
61 #oh oh, bad, ghost is getting angry!
62 ghost.WriteKey(key_angry, '1', 1)
63 ghost.CreateTimer(10, 1)
64 ghost.Say('You fool! You lost my body!\nPrepare to feel my wrath!')
65 warn_player(player, ghost)
66 if player.QuestGetState("scorn/Witherspoon-ghost") <= 60:
67 player.QuestSetState("scorn/Witherspoon-ghost", 70)
68
69 return False
70
71 def can_talk(player, rule):
72 '''Is the ghost angry or disappearing?
73 Used for the final catch all rule so the ghost doesn't talk when angry or disappearing.
74 '''
75 return Crossfire.WhoAmI().ReadKey(key_angry) == '' and Crossfire.WhoAmI().ReadKey(key_disappear) == ''
76
77 def do_dialog():
78 '''Main dialog routine.'''
79 if not can_talk(None, None):
80 return
81
82 whoami = Crossfire.WhoAmI()
83 pl = Crossfire.WhoIsActivator()
84 if pl.ReadKey('witherspoon_know_all') == '1':
85 # player found the real story, through Rolanda.
86 pl.WriteKey('witherspoon_know_all', '')
87 pl.WriteKey('witherspoon_know_dagger', '')
88 pl.WriteKey('witherspoon_ghost', '')
89 whoami.Say('Oh...')
90 whoami.Map.Print('The %s manages to blush.'%whoami.Name)
91 whoami.Say('Now I remember. I\'m so stupid. Poor Rolanda, will she ever forgive me...')
92 whoami.Say('Well, I guess I can go now. Many thanks for your help!')
93 whoami.WriteKey('bonus', '1', 1)
94 start_disappear(whoami, pl)
95 return
96
97 if pl.ReadKey('witherspoon_know_dagger') == '1':
98 # player talked to the priest of Devourers, and knows the dagger is special.
99 whoami.Say('Oh, please find who could be as cruel as to use such a horrible spell on me!')
100 return
101
102 # default dialog, just talk
103
104 # If you ever change this key, change the value in tomb.py too!
105 speech = Dialog(Crossfire.WhoIsActivator(), Crossfire.WhoAmI(), "witherspoon_ghost")
106
107 prer = [["token","witherspoon_ghost","0"]]
108 postr = [["settoken","witherspoon_ghost", "explain"]]
109 rmsg = ["I was killed by surprise, and ever since I'm stuck here.\n\n"
110 "If I could see my body, I could really understand I'm dead and I could rest in peace.\n\n"
111 "Could you find my body, please?"
112 ]
113 speech.addRule(DialogRule(["help","yes","how"], prer, rmsg, postr),0)
114
115 prer = [["token","witherspoon_ghost","explain"]]
116 postr = [["settoken","witherspoon_ghost", "wait"], ["quest", "scorn/Witherspoon-ghost", 10]]
117 rmsg = ["I was walking near a lake west of Scorn, so maybe my body is buried here."]
118 speech.addRule(DialogRule(["where","location"], prer, rmsg, postr),1)
119
120 prer = [["token","witherspoon_ghost","explain"]]
121 postr = [["settoken","witherspoon_ghost", "*"]]
122 rmsg = ["Please, go find my body...", "Please, I need my body to rest in peace..."]
123 speech.addRule(DialogRule(["*"], prer, rmsg, postr),2)
124
125 prer = [["token","witherspoon_ghost","wait"]]
126 postr = [["settoken","witherspoon_ghost", "*"]]
127 rmsg = ["Please, go find my body.\n\nIt should be near the lake west of Scorn...", "Did you find my body yet? No?\n\nThen please, go search for it, west of Scorn there is a lake..."]
128 rule = DialogRule(["*"], prer, rmsg, postr)
129 rule.setPreFunction(check_body)
130 speech.addRule(rule,3)
131
132 prer = [["token","witherspoon_ghost","wait"]]
133 postr = [["settoken","witherspoon_ghost", "0"]]
134 rmsg = ["Thanks, you found my body!"]
135 rule = DialogRule(["*"], prer, rmsg, postr)
136 rule.setPreFunction(found_body)
137 speech.addRule(rule,4)
138
139 prer = [["token","witherspoon_ghost","*"]]
140 postr = [["settoken","witherspoon_ghost", "*"]]
141 rmsg = ["Please help me....", "Heeeeeeeelp...", "Pleaseeeee..."]
142 rule = DialogRule(["*"], prer, rmsg, postr)
143 rule.setPreFunction(can_talk)
144 speech.addRule(rule,5)
145
146 speech.speak(Crossfire.WhatIsMessage())
147
148 def do_angry(ghost):
149 # Ghost is angry point, let's rock
150 ghost.Say('Feel my wrath!')
151 ghost.WriteKey(key_angry, '', 1)
152 ghost.Unaggressive = 0
153 ghost.NoDamage = 0
154 ghost.RandomMovement = 0
155 ghost.Speed = ghost.Speed * 2
156
157 def do_timer():
158 '''Got a timer, what for?'''
159 ghost = Crossfire.WhoAmI()
160 if ghost.ReadKey(key_angry) != '':
161 do_angry(ghost)
162 elif ghost.ReadKey(key_disappear) != '':
163 do_disappear()
164 #shouldn't get there...
165
166 def do_disappear():
167 '''Ghost is happy, all is fine.'''
168 ghost = Crossfire.WhoAmI()
169 if ghost.ReadKey(key_disappear) != '1':
170 '''Hu? Not supposed to come here in this case...'''
171 return
172
173 ghost.Say('Thanks a lot! Please take those small presents as a token of my gratitude.')
174
175 bonus = 0
176 if ghost.ReadKey('bonus') == '1':
177 bonus = 25
178
179 presents = ['gem', 'ruby', 'emerald', 'pearl', 'sapphire']
180 got = ghost.Map.CreateObject(presents[random.randint(0, len(presents) - 1)], ghost.X, ghost.Y)
181 got.Quantity = random.randint(3 + bonus, 7 + bonus)
182
183 ghost.Remove()
184
185 if Crossfire.WhatIsEvent().Subtype == Crossfire.EventType.SAY:
186 Crossfire.SetReturnValue(1)
187 do_dialog()
188 elif Crossfire.WhatIsEvent().Subtype == Crossfire.EventType.TIMER:
189 do_timer()