Crossfire Server, Trunk
farnass.py
Go to the documentation of this file.
1 # Script for Farnass the cook (/scorn/misc/scorn_kitchen).
2 #
3 # The script assumes you have:
4 # * a cook
5 # * a recipient where the player will put the ingredients
6 # * a stove where Farnass will go to cook
7 #
8 # Copyright 2007 Nicolas Weeger
9 # Released as GPL
10 #
11 # This script is supposed to be called for the say and time events of the cook,
12 # and the close event of the recipient.
13 
14 import Crossfire
15 import random
16 import CFMove
17 from CFDialog import DialogRule, Dialog
18 
19 quest_name = "wolfsburg/Lursendis"
20 
21 key_status = 'cook_status'
22 st_getting = 'getting' # moving to recipient to get the ingredients
23 st_stove = 'stove' # moving to the stove to cook
24 st_cooking = 'cooking' # actually cooking
25 
26 key_cooking_step = 'cooking_step' # when st_cooking, what cooking step
27 
28 key_need_check = 'check_ingredients' # used to signal, after recipient was closed, to check contents
29 
30 color = Crossfire.MessageFlag.NDI_GREEN # color to display messages
31 
32 recipe_arch = 'caramel' # archetype generated when recipe is complete
33 eggs_count = 4
34 failure_chance = 15
35 recipient_x = 5 # position of the recipient to drop ingredients into
36 recipient_y = 10
37 stove_x = 6 # position of the stove the cook will use
38 stove_y = 10
39 
41  ''' Finds the ingredients in the recipient. Used when recipient is closed, and when Farnass
42  arrives on the recipient (to avoid player picking up items)'''
43  mushroom = None
44  eggs = None
45 
46 # whoami.Say('before')
47  obj = whoami.Map.ObjectAt(recipient_x, recipient_y)
48  while obj != None:
49  if obj.Type == Crossfire.Type.CONTAINER:
50 # whoami.Say('got container %s'%obj.Name)
51  inv = obj.Inventory
52  while inv != None:
53  if inv.Name == 'blue mushroom' and inv.ArchName == 'mushroom_3':
54  mushroom = inv
55  elif inv.ArchName == 'chicken_egg' and inv.NamePl == 'Combat Chicken eggs':
56  eggs = inv
57  if mushroom != None and eggs != None:
58  break
59  inv = inv.Below
60  break
61  obj = obj.Above
62  #whoami.Say('after')
63 
64  #if mushroom != None:
65  # whoami.Say('got mushroom')
66  #if eggs != None:
67  # whoami.Say('got eggs')
68 
69  if mushroom == None or eggs == None or eggs.Quantity < eggs_count:
70  if whoami.ReadKey(key_status) == st_getting:
71  whoami.Say('Haha, you tried to trick me!')
72  whoami.WriteKey(key_status, '', 1)
73  return
74 
75  if whoami.ReadKey(key_status) != st_getting:
76  whoami.Say('Oh, great, you found what I need to make my special caramel!')
77  whoami.WriteKey(key_status, st_getting, 1)
78  return
79 
80  # if called here, Farnass moved to the recipient, and can pick the ingredients
81  whoami.Map.Print('%s expertly opens the frypan with a leg, and grabs the ingredient using two sticks in his mouth!'%whoami.Name, color)
82 
83  mushroom.Quantity = mushroom.Quantity - 1
84  eggs.Quantity = eggs.Quantity - eggs_count
85 
86  Crossfire.SetReturnValue(1)
87  whoami.WriteKey(key_status, st_stove, 1)
88 
89 def end_cooking(success):
90  ''' Everything is finish, let's decide if cooking was successful or not.'''
91  whoami.WriteKey(key_status, '', 1)
92  whoami.WriteKey(key_cooking_step, '', 1)
93 
94  if success == 0:
95  return
96  if random.randint(1, 100) < failure_chance:
97  whoami.Map.Print('%s throws the ingredients in the bin.'%whoami.Name)
98  whoami.Say('I can *tell* you shook the eggs. The yellows were so badly stressed inside that this could not work, even in my own hands... err, teeth.')
99  else:
100  whoami.Say('The caramel is ready!')
101  omelet = whoami.Map.CreateObject(recipe_arch, whoami.X, whoami.Y)
102  omelet.Name = 'Farnass\'s Special Caramel'
103  omelet.NamePl = 'Farnass\'s Special Caramels'
104  omelet.Slaying = 'Farnass\'s Special Caramel'
105  omelet.Quantity = 1
106 
107  # quest advancer
108  event = omelet.CreateObject("event_pickup")
109  event.Name = "wolfsburg/Lursendis 40>70"
110  event.Title = "Python"
111  event.Slaying = "/python/quests/QuestAdvance.py"
112 
114  '''Just tell the cook to check next time.'''
115  Crossfire.GetPrivateDictionary()[key_need_check] = 'yes'
116 
118  '''Cancel next check.'''
119  d = Crossfire.GetPrivateDictionary()
120  if key_need_check in d:
121  del d[key_need_check]
122 
123 def move_cook():
124  '''Main moving routine.'''
125 
126  #whoami.Say('move')
127  status = whoami.ReadKey(key_status)
128  if status == st_getting:
129  clean_check()
130  Crossfire.SetReturnValue(1)
131  m = CFMove.get_object_to(whoami, recipient_x, recipient_y)
132  if m == 0:
134  elif m == 2:
135  whoami.Say('Get off my way! You want me to cook this caramel or what?')
136  return
137 
138  if status == st_cooking:
139  clean_check()
140  Crossfire.SetReturnValue(1)
141 
142  if whoami.X != stove_x or whoami.Y != stove_y:
143  whoami.Say('You fool! The ingredients are wasted, now!')
144  end_cooking(0)
145  return
146 
147  step = int(whoami.ReadKey(key_cooking_step)) - 1
148  if step == 0:
149  end_cooking(1)
150  return
151  elif step == 15:
152  whoami.Map.Print('%s skillfully mixes the ingredients with his left toe while controlling the fire under the boiler with his right one!'%whoami.Name, color)
153  elif step == 40:
154  whoami.Map.Print('Knife griped by the mouth, %s cuts the mushroom in small slices, and puts them in the stove!'%whoami.Name, color)
155  whoami.WriteKey(key_cooking_step, str(random.randint(25, 35)), 1)
156  elif step == 50:
157  whoami.Say('Let\'s pour the sulphur in now! Hey, wait, did I say sulphur? Ok, getting some dwarven shampoo to neutralize this!')
158  elif step == 70:
159  whoami.Map.Print('%s breaks the eggs over the stove by expertly throwing them, the shells bouncing away!'%whoami.Name, color)
160  whoami.WriteKey(key_cooking_step, str(random.randint(60, 69)), 1)
161  whoami.WriteKey(key_cooking_step, str(step), 1)
162  return
163 
164  if status == st_stove:
165  clean_check()
166  move = CFMove.get_object_to(whoami, stove_x, stove_y)
167  if move == 0:
168  whoami.WriteKey(key_cooking_step, str(random.randint(80, 100)), 1)
169  whoami.Map.Print('%s makes the stove hotter.'%whoami.Name, color)
170  whoami.WriteKey(key_status, st_cooking, 1)
171  elif move == 2:
172  whoami.Say('Get off my way, I need to get to the stove!')
173  Crossfire.SetReturnValue(1)
174  return
175 
176  d = Crossfire.GetPrivateDictionary()
177  if key_need_check in d:
178  whoami.Map.Print('You see %s look at the frypan.'%whoami.Name, color)
179  del d[key_need_check]
181  return
182 
183 def cook_talk():
184  speech = Dialog(Crossfire.WhoIsActivator(), Crossfire.WhoAmI(), "scorn/Farnass")
185 
186  idx = 1
187 
188  match = ["eggs"]
189  pre = [["quest", quest_name, "=40"]]
190  msg = ["My friend Sentrio lives somewhere in Lake Country, but I don't remember where exactly, sorry...\n\nI do know eggs from his chicken are the only ones worth my cooking skill!"]
191  post = []
192  replies = [
193  ["mushroom", "Where can I find the mushroom?", 2],
194  ["cook", "But how can you cook without arms?", 2]]
195  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
196  idx = idx + 1
197 
198  match = ["mushroom"]
199  pre = [["quest", quest_name, "=40"]]
200  msg = ["It's a blue one, I think it grows in a marsh in the west. I've heard it can be used for medicine, too."]
201  post = []
202  replies = [
203  ["eggs", "Where can I find the eggs?", 2],
204  ["cook", "But how can you cook without arms?", 2]]
205  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
206  idx = idx + 1
207 
208  match = ["cook"]
209  pre = [["quest", quest_name, "=40"]]
210  msg = ["You wonder how I cook without arms? Heh, rookie, that's what makes the difference between a cooker and me, Farnass! I told you already: I'm simply wonderful."]
211  post = []
212  replies = [
213  ["eggs", "Where can I find the eggs?", 2],
214  ["mushroom", "Where can I find the mushroom?", 2]]
215  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
216  idx = idx + 1
217 
218  match = ["*"]
219  pre = [["quest", quest_name, "=40"]]
220  msg = ["If you really want this caramel, then bring me the ingredients, please."]
221  post = []
222  replies = [
223  ["mushroom", "Where can I find the mushroom?", 2],
224  ["eggs", "Where can I find the eggs?", 2],
225  ["cook", "But how can you cook without arms?", 2]]
226  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
227  idx = idx + 1
228 
229  match = ["ingredients"]
230  pre = [["quest", quest_name, "=10"], ["token", "dialog", "4"]]
231  msg = ["You need the following:\n- 4 eggs from my friend Sentrio's chicken\n- a blue mushroom\n\nAs you can see, I've lost my both arms during the last war against the Gnolls, so would you be kind enough to put whatever you found during your travel to make the recipe in the frypan, please?"]
232  post = [["settoken", "dialog", "0"], ["quest", quest_name, "40"]]
233  replies = [
234  ["mushroom", "Where can I find the mushroom?", 2],
235  ["eggs", "What kind of eggs?", 2],
236  ["cook", "But how can you cook without arms?", 2]]
237  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
238  idx = idx + 1
239 
240  match = ["caramel"]
241  pre = [["quest", quest_name, "=10"], ["token", "dialog", "3"]]
242  msg = ["Ha, if my great friend wants a caramel, then I can only oblige!"]
243  post = [["settoken", "dialog", "4"]]
244  replies = [["ingredients", "So what would the ingredients be?", 2]]
245  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
246  idx = idx + 1
247 
248  match = ["yes"]
249  pre = [["quest", quest_name, "=10"], ["token", "dialog", "2"]]
250  msg = ["How obviously from him!\n\nSo, what will he want to eat, this time?"]
251  post = [["settoken", "dialog", "3"]]
252  replies = [["caramel", "A caramel.", 1]]
253  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
254  idx = idx + 1
255 
256  match = ["lursendis"]
257  pre = [["quest", quest_name, "=10"], ["token", "dialog", "1"]]
258  msg = ["Oh, this good friend! I should go see him someday... Let me guess, he wants to eat something, he?"]
259  post = [["settoken", "dialog", "2"]]
260  replies = [["yes", "Well, yes.", 1]]
261  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
262  idx = idx + 1
263 
264  match = ["*"]
265  pre = [["quest", quest_name, "=10"]]
266  msg = ["Please don't disturb me, I'm trying a really hard recipe."]
267  post = [["settoken", "dialog", "1"]]
268  replies = [["lursendis", "Your friend Lursendis sent me here."]]
269  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
270  idx = idx + 1
271 
272  match = ["*"]
273  pre = []
274  msg = ["Please don't disturb me, I'm trying a really hard recipe."]
275  post = []
276  replies = []
277  speech.addRule(DialogRule(match, pre, msg, post, replies),idx)
278  idx = idx + 1
279 
280  speech.speak(Crossfire.WhatIsMessage())
281  Crossfire.SetReturnValue(1)
282 
283 whoami = Crossfire.WhoAmI()
284 if Crossfire.WhatIsEvent().Subtype == Crossfire.EventType.SAY:
285  if whoami.ReadKey(key_cooking_step) != '':
286  Crossfire.NPCSay(whoami, 'Keep quiet, this recipe requires concentration!')
287  Crossfire.SetReturnValue(1)
288  else:
289  cook_talk()
290 elif Crossfire.WhatIsEvent().Subtype == Crossfire.EventType.TIME:
291  move_cook()
292 elif Crossfire.WhatIsEvent().Subtype == Crossfire.EventType.CLOSE:
293  close_boiler()
farnass.cook_talk
def cook_talk()
Definition: farnass.py:183
make_face_from_files.str
str
Definition: make_face_from_files.py:30
farnass.move_cook
def move_cook()
Definition: farnass.py:123
farnass.end_cooking
def end_cooking(success)
Definition: farnass.py:89
farnass.close_boiler
def close_boiler()
Definition: farnass.py:113
farnass.clean_check
def clean_check()
Definition: farnass.py:117
farnass.check_ingredients
def check_ingredients()
Definition: farnass.py:40
CFMove.get_object_to
def get_object_to(obj, x, y)
Definition: CFMove.py:24
CFDialog.DialogRule
Definition: CFDialog.py:128
make_face_from_files.int
int
Definition: make_face_from_files.py:32
CFDialog.Dialog
Definition: CFDialog.py:183