Debian Codegraph @

python/maps/darcap/manor.py

raw
1 import random
2 # -*- coding: utf-8 -*-
3 # Script handling various things for Darcap Manor.
4 #
5 # It is used:
6 # - in the blue zone, to count how many kobolds are on the map
7 # - for the potion, to explode walls in the treasure room
8 # - in the brown zone, to prevent Kaptel's death or trigger the opening of the exit
9 # - in the white zone, to check if the player knows how many of a certain jewel there are
10
11 import Crossfire
12
13 def blue_count_kobolds():
14 map = Crossfire.WhoAmI().Map
15 count = 0
16 for x in range(map.Width):
17 for y in range(map.Height):
18 below = map.ObjectAt(x, y)
19 while below:
20 if below.Name == 'kobold':
21 count = count + 1
22 break
23 below = below.Above
24
25 return count
26
27 def blue_check():
28 '''Player triggered the lever, check if correct number of kobolds. '''
29
30 if blue_count_kobolds() != 4:
31 Crossfire.SetReturnValue(1)
32 Crossfire.WhoIsActivator().Message('The level will only activate if there are exactly 4 kobolds on the map')
33 return
34
35 def potion_find_wall(map, x, y, name):
36 '''Find the wall of a given archetype at the specified location.'''
37 item = map.ObjectAt(x, y)
38 while item:
39 if item.ArchName == name:
40 return item
41 item = item.Above
42
43 return None
44
45 def potion_check():
46 """Handle the Darcap Manor's potion being thrown. Check if walls to destroy in the treasure room."""
47
48 # note: duplication with /CFMove.py, should be factorised at some point
49 dir_x = [ 0, 0, 1, 1, 1, 0, -1, -1, -1 ]
50 dir_y = [ 0, -1, -1, 0, 1, 1, 1, 0, -1 ]
51
52 env = Crossfire.WhoAmI().Env
53
54 if env.Map.Path != '/darcap/darcap/manor.treasure':
55 return
56
57 x = env.X + dir_x[ env.Direction ]
58 y = env.Y + dir_y[ env.Direction ]
59
60 if y != 4 and y != 8 and y != 12:
61 return
62
63 if x != 9 and x != 10:
64 return
65
66 left = potion_find_wall(env.Map, 9, y, 'cwall_mural_1_1')
67 right = potion_find_wall(env.Map, 10, y, 'cwall_mural_1_2')
68
69 if left == None or right == None:
70 # hu?
71 return
72
73 left.Remove()
74 right.Remove()
75
76 env.Map.CreateObject('rubble', 9, y)
77 env.Map.CreateObject('rubble', 10, y)
78
79 Crossfire.WhoAmI().Remove()
80
81 env.Map.Print('The wall explodes!')
82
83 def kaptel_death():
84 '''
85 Handle Kaptel's death event. Depending on whether the player triggered the lever,
86 either prevent death or trigger the opening of the exit.
87 '''
88 who = Crossfire.WhoAmI()
89
90 floor = who.Map.ObjectAt(24, 1)
91 while floor != None and floor.Above != None:
92 floor = floor.Above
93
94 if floor.Name == 'boulder':
95 who.Say('AAAAAAAAAaaaaahhhhhhhhhhhhhh!!!!!!!!!')
96 who.Map.TriggerConnected(11, 1)
97 return
98
99 who.Map.Print("%s roars and seems to regenerate!"%(Crossfire.WhoAmI().Name))
100 who.HP = who.MaxHP / 2
101 Crossfire.SetReturnValue(1)
102
103 def challenge_correct_reply(count, msg):
104 if count == 0:
105 return msg == '0' or msg == 'none'
106 return count == int(msg)
107
108 def check_arch(map, x, y, arch):
109 below = map.ObjectAt(x, y)
110 while below:
111 if below.ArchName == arch:
112 return 1
113 below = below.Above
114
115 return 0
116
117 def white_challenge():
118 '''
119 Say handler for the final white challenge.
120 Player must know how many jewel piles of a certain kind were on the map, else failure.
121 '''
122
123 msg = Crossfire.WhatIsMessage()
124 ear = Crossfire.WhoAmI()
125 status = ear.ReadKey('challenge')
126
127 if status == 'done':
128 ear.Say('You already replied!')
129 return
130
131 if status == '':
132 if msg == 'ready':
133 ear.WriteKey('challenge', 'ready', 1)
134 ear.Say('To get the white key, reply to the following question:')
135
136 archs = [ 'gem', 'amethyst', 'emerald', 'ruby', 'sapphire', 'pearl' ]
137 names = [ 'diamonds', 'amethysts', 'emeralds', 'rubies', 'sapphires', 'pearls' ]
138 choice = random.randint(0, 5)
139
140 location = random.randint(1, 3)
141 if location == 1:
142 positions = [ [8, 2], [10, 7], [10, 9], [28, 18] ]
143 where = 'behind windows'
144 elif location == 2:
145 positions = [ [10, 7], [10, 9], [2, 23], [16, 21], [8, 2], [24, 6], [23, 7], [25, 7], [19, 26], [20, 26], [19, 28] ]
146 where = 'behind grates'
147 else:
148 positions = [ [8, 2], [10, 7], [10, 9], [2, 23], [16, 21], [8, 2], [24, 6], [23, 7], [25, 7], [28, 18], [19, 26], [20, 26], [19, 28] ]
149 where = 'in this dungeon'
150
151 count = 0
152 for pos in positions:
153 count += check_arch(ear.Map, pos[0], pos[1], archs[choice])
154
155 ear.Say('How many piles of %s did you see %s?'%(names[choice],where))
156 ear.Say('Reply with a number in digits please.')
157
158 # keep reply in the ear, easier
159 ear.WriteKey('reply', str(count), 1)
160 return
161
162 # check answer
163
164 ear.WriteKey('challenge', 'done')
165
166 count = int(ear.ReadKey('reply'))
167 if challenge_correct_reply(count, msg):
168 ear.Map.TriggerConnected(60, 1)
169 ear.Say('Correct!')
170 else:
171 ear.Say('Sorry, that is not the correct reply. Please try again later.')
172
173 if Crossfire.ScriptParameters() == 'blue':
174 blue_check()
175 elif Crossfire.ScriptParameters() == 'potion':
176 potion_check()
177 elif Crossfire.ScriptParameters() == 'kaptel':
178 kaptel_death()
179 elif Crossfire.ScriptParameters() == 'white':
180 white_challenge()