Crossfire Server, Trunk
lursendis.py
Go to the documentation of this file.
1 # Script for Lursendis the gourmet (/wolfsburg/lursendis).
2 # Idea courtesy Yann Chachkoff.
3 #
4 # The script assumes you have:
5 # * Lursendis
6 # * a place where the player will drop the special omelet
7 #
8 # Copyright 2007 Nicolas Weeger
9 # Released as GPL
10 #
11 # This script is supposed to be called for the time event of Lursendis.
12 
13 import Crossfire
14 import CFMove
15 import random
16 from CFDialog import DialogRule, Dialog
17 
18 quest_name = "wolfsburg/Lursendis"
19 
20 key_status = 'gourmet_status'
21 st_getting = 'getting'
22 st_eating = 'eating'
23 key_eating_step = 'eating_step'
24 plate_x = 2
25 plate_y = 6
26 
27 banquet_path = '/python/items/banquet.py'
28 banquet_archetype = 'tome'
29 event_archetype = 'event_apply'
30 
31 color = Crossfire.MessageFlag.NDI_GREEN # color to display messages
32 
34  obj = whoami.Map.ObjectAt(plate_x, plate_y)
35  while obj != None:
36  if obj.NamePl == 'Farnass\'s Special Caramels' and obj.Slaying == 'Farnass\'s Special Caramel':
37  if whoami.ReadKey(key_status) == st_getting:
38  whoami.Map.Print('%s grabs a %s and starts eating with an obvious pleasure.'%(whoami.Name, obj.Name))
39  obj.Quantity = obj.Quantity - 1
40  whoami.WriteKey(key_status, st_eating, 1)
41  whoami.WriteKey(key_eating_step, str(random.randint(5, 10)), 1)
42  Crossfire.SetReturnValue(1)
43  return
44 
45  whoami.Say('Oh! Could this be...')
46  whoami.WriteKey(key_status, st_getting, 1)
47  Crossfire.SetReturnValue(1)
48  return
49 
50  obj = obj.Above
51 
52  if whoami.ReadKey(key_status) == st_getting:
53  # we were on the spot, but no more omelet...
54  whoami.WriteKey(key_status, '', 1)
55 
57  book = whoami.Map.CreateObject(banquet_archetype, whoami.X, whoami.Y)
58  book.Name = 'Unforgettable Banquet of %s'%whoami.Name
59  book.NamePl = 'Unforgettable Banquets of %s'%whoami.Name
60  event = book.CreateObject(event_archetype)
61  event.Slaying = banquet_path
62  event.Title = Crossfire.WhatIsEvent().Title
63 
65  st = whoami.ReadKey(key_status)
66  if st == st_getting:
67  move = CFMove.get_object_to(whoami, plate_x, plate_y)
68  if move == 0:
69  check_plate()
70  return
71  elif move == 2:
72  whoami.Say('Get outta my way!')
73  Crossfire.SetReturnValue(1)
74  return
75  elif st == st_eating:
76  step = int(whoami.ReadKey(key_eating_step)) - 1
77  if step == 0:
78  whoami.WriteKey(key_eating_step, '', 1)
79  whoami.WriteKey(key_status, '', 1)
80  whoami.Say('Now that\'s what I call a caramel! Thank you very much!')
81  whoami.Say('Here, take this as a token of my gratitude.')
82  create_book()
83  for pl in Crossfire.GetPlayers():
84  if pl.Map == whoami.Map and pl.QuestGetState(quest_name) == 70:
85  pl.QuestSetState(quest_name, 100)
86  return
87  whoami.WriteKey(key_eating_step, str(step), 1)
88  Crossfire.SetReturnValue(1)
89  return
90 
91  check_plate()
92 
94  pl = Crossfire.WhoIsActivator()
95  speech = Dialog(Crossfire.WhoIsActivator(), Crossfire.WhoAmI(), quest_name)
96  completed = pl.QuestWasCompleted(quest_name)
97 
98  idx = 1
99 
100  prer = [["quest",quest_name, "10"]]
101  rmsg = ["So, do you have a caramel made by Farnass? If so, please put it on the plate, I'm so hungry!"]
102  postr = []
103  speech.addRule(DialogRule(["*"], prer, rmsg, postr),idx)
104  idx = idx + 1
105 
106  prer = [["quest",quest_name, "0"], ["token", "asked", "1"]]
107  postr = [["settoken", "asked", "0"]]
108  rmsg = ["Ha well, too bad... If you ever change your mind, please tell me!"]
109  speech.addRule(DialogRule(["no"], prer, rmsg, postr),idx)
110  idx = idx + 1
111 
112  if completed:
113  next = "40"
114  else:
115  next = "10"
116 
117  prer = [["quest",quest_name, "0"], ["token", "asked", "1"]]
118  postr = [["settoken", "asked", "0"], ["quest", quest_name, next]]
119  rmsg = ["Thank you very much!"]
120  speech.addRule(DialogRule(["yes"], prer, rmsg, postr),idx)
121  idx = idx + 1
122 
123  if completed:
124  prer = [["quest",quest_name, "0"]]
125  postr = [["settoken", "asked", "1"]]
126  rmsg = ["Hum, I'm still hungry, I could use another caramel from Farnass... Could you get me another one, please?"]
127  replies = [["yes", "Sure"], ["no", "Sorry, I'm really busy now, I don't have time..."]]
128  speech.addRule(DialogRule(["*"], prer, rmsg, postr, replies),idx)
129  idx = idx + 1
130  else:
131  prer = [["quest", quest_name, "0"], ["token", "dialog", "3"]]
132  postr = [["settoken", "asked", "1"], ["settoken", "dialog", "0"]]
133  rmsg = ["Would you really be as kind as that?"]
134  replies = [["yes", "If you really need one caramel, yes, sure."], ["no", "Well, no, I was just joking."]]
135  speech.addRule(DialogRule(["bring"], prer, rmsg, postr, replies),idx)
136  idx = idx + 1
137 
138  prer = [["quest", quest_name, "0"], ["token", "dialog", "2"]]
139  postr = [["settoken", "dialog", "3"]]
140  rmsg = ["Farnass 'The Recipe Spellcrafter'. Good friend, haven't seen him in 15 years...\nI think he lived in Scorn, or some island around."]
141  replies = [["bring", "Should I get you one of his caramels, then?", 2]]
142  speech.addRule(DialogRule(["farnass"], prer, rmsg, postr, replies),idx)
143  idx = idx + 1
144 
145  prer = [["quest", quest_name, "0"], ["token", "dialog", "1"]]
146  postr = [["settoken", "dialog", "2"]]
147  rmsg = ["Yes, but I would only eat a caramel made by my friend Farnass."]
148  replies = [["farnass", "Who is Farnass?", 2]]
149  speech.addRule(DialogRule(["caramel"], prer, rmsg, postr, replies),idx)
150  idx = idx + 1
151 
152  prer = [["quest", quest_name, "0"]]
153  postr = [["settoken", "dialog", "1"]]
154  rmsg = ["I'm hungry, I could use a caramel."]
155  replies = [["caramel", "A caramel, really?", 2]]
156  speech.addRule(DialogRule(["*"], prer, rmsg, postr, replies),idx)
157  idx = idx + 1
158 
159  speech.speak(Crossfire.WhatIsMessage())
160  Crossfire.SetReturnValue(1)
161 
162 whoami = Crossfire.WhoAmI()
163 if Crossfire.WhatIsEvent().Subtype == Crossfire.EventType.TIME:
164  move_gourmet()
165 elif Crossfire.WhatIsEvent().Subtype == Crossfire.EventType.SAY:
166  talk_gourmet()
lursendis.talk_gourmet
def talk_gourmet()
Definition: lursendis.py:93
make_face_from_files.str
str
Definition: make_face_from_files.py:30
lursendis.create_book
def create_book()
Definition: lursendis.py:56
lursendis.move_gourmet
def move_gourmet()
Definition: lursendis.py:64
CFMove.get_object_to
def get_object_to(obj, x, y)
Definition: CFMove.py:24
CFDialog.DialogRule
Definition: CFDialog.py:128
lursendis.check_plate
def check_plate()
Definition: lursendis.py:33
make_face_from_files.int
int
Definition: make_face_from_files.py:32
CFDialog.Dialog
Definition: CFDialog.py:183