1;;----------------------------------------------------------------------------
2;; Constants
3;;----------------------------------------------------------------------------
4(define enchanter-start-lvl 8)
5
6;;----------------------------------------------------------------------------
7;; Schedule
8;;
9;; The schedule below is for the place "Enchanter's Tower Ground Floor"
10;;
11;; (The fact that he never visits the second floor of his own tower
12;; should serve as an incentive for us to eventually get multi-place
13;; schedules working  :-)
14;;----------------------------------------------------------------------------
15(kern-mk-sched 'sch_enchanter
16               (list 0  0  enchtwr-ench-bed        "sleeping")
17               (list 8  0  enchtwr-dining-room-2   "eating")
18               (list 9  0  enchtwr-hall            "idle")
19               (list 12 0  enchtwr-dining-room-2   "eating")
20               (list 13 0  enchtwr-hall            "idle")
21               (list 19 0  enchtwr-dining-room-2   "eating")
22               (list 20 0  enchtwr-bedroom-1       "idle")
23               )
24
25;;----------------------------------------------------------------------------
26;; Gob
27;;
28;; Quest flags, etc, go here.
29;;----------------------------------------------------------------------------
30(define (enchanter-mk)
31  (list #f
32        (mk-quest) ;; get stolen rune
33        (mk-quest) ;; learn the purpose of the runes
34        (mk-quest) ;; get all runes
35        (mk-quest) ;; open demon gate
36        ))
37(define (ench-met? gob) (car gob))
38(define (ench-first-quest gob) (cadr gob))
39(define (ench-second-quest gob) (caddr gob))
40(define (ench-quest gob n) (list-ref gob n))
41(define (ench-met! gob val) (set-car! gob val))
42
43;;----------------------------------------------------------------------------
44;; Conv
45;;
46;; The Enchanter is a powerful Mage, and one of the Wise.
47;; He lives in the Enchanter's Tower.
48;; He plays an important role in multiple stages of the main quest.
49;;----------------------------------------------------------------------------
50(define (ench-hail knpc kpc)
51  (let ((ench (gob knpc)))
52
53    ;; Fourth Quest -- open the demon gate
54    (define (check-fourth-quest)
55      (say knpc "Have you found the location of the Demon Gate?")
56      (if (yes? kpc)
57          (begin
58            (say knpc "And have you found the locks which the Rune-keys will open?")
59            (if (yes? kpc)
60                (say knpc "So you are just fooling around, wasting time. I see.")
61                (say knpc "I would expect them to appear as altars in a shrine. "
62                     "The shrine may be hidden, perhaps revealing itself with a "
63                     "password. Find and search the Accursed, "
64                     "they must have had a clue.")))
65          (say knpc "Search well the library at Absalot.")))
66
67    ;; Third Quest -- find all the Runes
68    (define (finish-third-quest)
69      (say knpc "You have found all the Runes! "
70           "Well, it couldn't have been all that hard. ")
71      (prompt-for-key)
72      (say knpc "I have one last task for you. "
73           "You must find the Demon Gate and re-open it. "
74           "Do you know where to find it?")
75      (if (yes? kpc)
76          (say knpc
77               "I don't know what you will face, "
78               "so prepare yourself well, "
79               "and take anyone foolish enough to join you. "
80               )
81          (say knpc "The Accursed must have some idea, "
82               "and the library of Absalot may yet hold some clue. "
83               "Search well.")
84          )
85      (quest-done! (ench-quest ench 3) #t)
86      (kern-char-add-experience kpc 100)
87      (quest-accepted! (ench-quest ench 4) #t)
88      )
89
90    (define (check-third-quest)
91	(define (missing-only-s-rune?)
92		(all-in-inventory? kpc
93                         (filter (lambda (ktype)
94                                   (not (eqv? ktype t_rune_s)))
95                                 rune-types)))
96	(cond
97		((missing-only-s-rune?)
98			(say knpc "You appear to have found most of the Runes now.")
99		(prompt-for-key)
100		(say knpc "Hmmm.")
101		(prompt-for-key)
102		(say knpc "I hesitated to raise this before, but it may be within your abilities after all.")
103		(prompt-for-key)
104		(say knpc "We know that the Accursed also seek the runes. We should consider ourselves fortunate if only one has fallen into their clutches.")
105		(prompt-for-key)
106		(say knpc "You will need to seek it in the very lair of our enemies: the ruins of Absalot.")
107		(quest-data-assign-once 'questentry-rune-s)
108		)
109
110		((has-all-runes? kpc)
111          (finish-third-quest)
112          (say knpc "Return when you have found all the Runes. "
113               "Consult with the other Wise, they may have clues about where to find the Runes.")
114	       ))
115	       )
116
117    ;; Second Quest -- find out what the Runes are for
118    (define (second-quest-spurned)
119      (say knpc "It is the duty of all good men to stand up to evil. I "
120           "don't have time for sluggards or cynics. Now give me my rune, "
121           "take your reward and get out!")
122      (kern-obj-remove-from-inventory kpc t_rune_k 1)
123      (kern-obj-add-to-inventory knpc t_rune_k 1)
124      (quest-accepted! (ench-second-quest ench) #f)
125      (kern-conv-end))
126
127    (define (start-second-quest)
128      (quest-accepted! (ench-second-quest ench) #t)
129      (say knpc "Good! First, keep my rune, and guard it well. ")
130      (quest-data-update 'questentry-rune-k 'entrusted-with-rune 1)
131      (prompt-for-key)
132      (say knpc "Second, find the other Wise and ask them of the RUNE. "
133           "You might start with the Alchemist near Oparine. "
134           "Although obscenely greedy, "
135           "he has devoted his life to the acquisition of secrets.")
136      (quest-data-assign-once 'questentry-runeinfo)
137      (quest-wise-subinit 'questentry-alchemist)
138      (quest-wise-init)
139      (kern-conv-end)
140      )
141
142    (define (offer-second-quest-again)
143      (say knpc "You're back. Perhaps you've had an attack of conscience. "
144           "It happens to the worst of us. "
145           "Now, are you ready to help me thwart the Accursed?")
146      (if (kern-conv-get-yes-no? kpc)
147          (begin
148            (kern-obj-remove-from-inventory knpc t_rune_k 1)
149            (kern-obj-add-to-inventory kpc t_rune_k 1)
150            (start-second-quest))
151          (begin
152            (say knpc "Like a pig to the trough, "
153                 "a fool returns to his own folly. "
154                 "Go back to filling your belly!")
155            (kern-conv-end)))
156      )
157
158    (define (finish-second-quest)
159      (say knpc "[He looks very grave] "
160           "So my Rune is one of eight keys to the Demon Gate. "
161           "Very well, you must find the rest. "
162           "The Accursed have a head start on us. "
163           "No doubt they already have some of the Runes. "
164           "When you have found all the Runes return to me.")
165      (quest-done! (ench-second-quest ench) #t)
166      (quest-data-update 'questentry-runeinfo 'abe 1)
167      (quest-data-update 'questentry-runeinfo 'keys 1)
168      (quest-data-update 'questentry-runeinfo 'gate 1)
169      (quest-data-update 'questentry-rune-k 'entrusted-with-rune 1)
170      (quest-data-update-with 'questentry-runeinfo 'done 1 (grant-party-xp-fn 30))
171      (quest-data-complete 'questentry-runeinfo)
172      ;; temporary setup- will require information gathering first when done
173      (prompt-for-key)
174      (quest-data-assign-once 'questentry-allrunes)
175      (quest-data-convert-subquest 'questentry-rune-k 'questentry-allrunes)
176      (quest-data-assign-once 'questentry-rune-k)
177      (quest-data-convert-subquest 'questentry-rune-c 'questentry-allrunes)
178      (quest-data-convert-subquest 'questentry-rune-d 'questentry-allrunes)
179      (quest-data-convert-subquest 'questentry-rune-l 'questentry-allrunes)
180      (quest-data-convert-subquest 'questentry-rune-p 'questentry-allrunes)
181      (quest-data-convert-subquest 'questentry-rune-s 'questentry-allrunes)
182      (quest-data-convert-subquest 'questentry-rune-w 'questentry-allrunes)
183      (quest-data-convert-subquest 'questentry-rune-f 'questentry-allrunes)
184      (quest-accepted! (ench-quest ench 3) #t)
185      )
186
187    (define (check-second-quest)
188      (say knpc "Have you learned what the Rune is for?")
189      (if (yes? kpc)
190          (begin
191            (say knpc "Well, what?")
192            (let ((reply (kern-conv-get-reply kpc)))
193              (if (or (equal? reply 'demo) (equal? reply 'gate) (equal? reply 'key))
194                  (finish-second-quest)
195                  (begin
196                    (say knpc "I don't think so. Have you asked all of the Wise about the ^c+mrune^c-?")
197                    (if (yes? kpc)
198                        (say knpc "Surely one of them must have given you some clue!")
199                        (say knpc "Seek them all."))))))
200          (say knpc "Ask all the Wise about the ^c+mrune^c-.")))
201
202    ;; First Quest -- find the stolen Rune
203    (define (finish-first-quest)
204      (say knpc "Ah, I see you've found my Rune at last!")
205      (kern-obj-add-gold kpc 200)
206		(quest-data-update-with 'questentry-thiefrune 'done 1 (grant-party-xp-fn 20))
207		(quest-data-complete 'questentry-thiefrune)
208      (say knpc "Perhaps your are not completely useless. "
209           "Did you encounter any... resistance?")
210      (kern-conv-get-yes-no? kpc)
211      (say knpc "The Accursed were behind this theft. "
212           "We must find out what the Rune is for. "
213           "Will you help?")
214      (quest-offered! (ench-second-quest ench) #t)
215      (if (kern-conv-get-yes-no? kpc)
216          (start-second-quest)
217          (second-quest-spurned)))
218
219    (define (check-first-quest)
220      (if (in-inventory? kpc t_rune_k)
221          (finish-first-quest)
222          (say knpc "Hmph. I see you still haven't found my item yet!"
223               " [He mutters something about Wanderers and Rogues]")
224            ))
225
226    ;; Main
227    (if (ench-met? ench)
228        (if (quest-done? (ench-quest ench 4))
229            (say knpc "Welcome, friend of the Wise")
230            (if (quest-accepted? (ench-quest ench 4))
231                (check-fourth-quest)
232                (if (quest-accepted? (ench-quest ench 3))
233                    (check-third-quest)
234                    (if (quest-offered? (ench-second-quest ench))
235                        (if (quest-accepted? (ench-second-quest ench))
236                            (check-second-quest)
237                            (offer-second-quest-again))
238                        (if (quest-accepted? (ench-first-quest ench))
239                            (check-first-quest)
240                            (say knpc "Yes, what is it this time?"))))))
241        (begin
242          (quest-data-update-with 'questentry-calltoarms 'talked 1 (quest-notify (grant-xp-fn 10)))
243          (kern-log-msg "This ageless mage looks unsurprised to see you.")
244          (say knpc "I was wondering when you would get here. "
245               "It took you long enough!")
246          (ench-met! ench #t)))))
247
248(define (ench-name knpc kpc)
249  (say knpc "I am known as the Enchanter."))
250
251(define (ench-job knpc kpc)
252  (say knpc "I help as I can in the struggle against evil."))
253
254(define (ench-default knpc kpc)
255  (say knpc "I cannot help you with that"))
256
257(define (ench-bye knpc kpc)
258  (say knpc "Beware the Accursed!"))
259
260(define (ench-join knpc kpc)
261  (say knpc "No, I belong here. Seek the Warritrix if you desire a powerful "
262       "companion."))
263
264
265(define (ench-warr knpc kpc)
266  (say knpc "The Warritrix is Wise and fierce, "
267       "and like yourself prone to Wandering. "
268       "In fact, at the moment I don't know where she is. "
269       "Try Glasdrin.")
270       (quest-wise-subinit 'questentry-warritrix)
271       (quest-data-update 'questentry-warritrix 'general-loc 1)
272       )
273
274(define (ench-wand knpc kpc)
275  (say knpc "Yes, I've met your type before. Unpredictable. "
276       "And as to whether you are good or evil, that depends upon you."))
277
278(define (ench-offer-first-quest knpc kpc)
279  (say knpc "I do not quibble over definitions of good and evil. "
280       "They are easily recognized when encountered. "
281       "Do you intend to do good while you are here?")
282  (if (kern-conv-get-yes-no? kpc)
283      ;; yes - player intends to do good
284      (begin
285        (say knpc "Then you will find me to be your ally. "
286             "But beware! Many who claim to be good are not, "
287             "or fail when put to the test. Are you ready to be tested?")
288        (if (kern-conv-get-yes-no? kpc)
289            ;; yes - player is ready to be tested
290            (begin
291              (say knpc "Very well. An item was recently stolen from me. "
292                   "I need someone to find the thief, "
293                   "recover the item and return it to me. Are you willing?")
294              (if (kern-conv-get-yes-no? kpc)
295                  ;; yes -- player is willing
296                  (begin
297                    (say knpc "Good! Rangers have tracked the thief to "
298                         "Trigrave. Go there and inquire about a ^c+mthief^c-.")
299							(quest-data-assign-once 'questentry-thiefrune)
300              		(quest-data-complete 'questentry-calltoarms)
301                  	;; if you dont read the letter, you might not get the quest till now!
302              		(quest-data-assign-once 'questentry-calltoarms)
303                  	(quest-data-update-with 'questentry-calltoarms 'done 1 (grant-xp-fn 10))
304                    (quest-accepted! (ench-first-quest (gob knpc)) #t)
305                    )
306                  ;; no -- player is not willing
307                  (say knpc "Perhaps I misjudged you.")))
308            ;; no -- player is not ready
309            (say knpc "It is not enough to speak of doing good, one cannot "
310                 "BE good without DOING good.")))
311      ;; no -- player does not intend to do good
312      (say knpc "We shall see. Evil men can do good without meaning to, "
313           "and men who would be callous find they can't ignore their "
314           "conscience.")))
315
316(define (ench-good knpc kpc)
317  (if (quest-accepted? (ench-first-quest (gob knpc)))
318      (say knpc "The wicked flee when no one pursues, but the righteous are "
319           "bold as dragons.")
320      (ench-offer-first-quest knpc kpc)))
321
322(define (ench-gate knpc kpc)
323  (say knpc "There are many gates in the land which connect to "
324       "one another and appear with the moons. "
325       "But the Shrine Gate is the only one I know of for certain that connects with "
326       "other worlds."))
327
328(define (ench-wise knpc kpc)
329  (say knpc "The Wise are the most powerful Warriors, Wizards, Wrights and "
330       "Wrogues in the land. Although they function to protect the Shard, "
331       "they are not all good."))
332
333(define (ench-accu knpc kpc)
334  (say knpc "The Accursed are an evil secret society, responsible for many "
335       "crimes and atrocities. With the destruction of Absalot I thought "
336       "they were finished. I was wrong. I fear now their number and "
337       "strength is greater than ever before."))
338
339(define (ench-moon knpc kpc)
340  (say knpc "Ask Kalcifax the Traveler of moongates. "
341       "She is quite the expert."))
342
343(define (ench-shri knpc kpc)
344  (say knpc "The Shrine Gate opens unpredictably, and only for a short time. "
345       "Those who enter never return, "
346       "and those who emerge are strangers and Wanderers like yourself."))
347
348(define (ench-rune knpc kpc)
349  (say knpc "The rune was passed to me by my master long ago. "
350       "He did not know what it was for, and for all my research I never "
351       "found its purpose, either. I decided it was an unimportant old relic. "
352       "Why else would it not be mentioned in any of the arcane tomes or "
353       "histories?"))
354
355(define (ench-wiza knpc kpc)
356  (say knpc "The Warrior, Wright and Wrogue all derive some power from their "
357       "knowledge of the physical world. But a Wizard's power comes from his "
358       "knowledge of the magical world."))
359
360(define (ench-know knpc kpc)
361  (say knpc "Just as a blind man cannot perceive colors, those without the "
362       "Inner Eye cannot perceive the forces of magic. But those who have "
363       "opened the Eye perceive causes and effects invisible to others."))
364
365(define (ench-wrog knpc kpc)
366  (say knpc "The Wisest of Wrogues is The MAN, who comes and goes as if on "
367       "the wind. If the MAN has a home, it is well-hidden. Ask around, "
368       "perhaps your inquiries will prompt a meeting.")
369       (quest-wise-subinit 'questentry-the-man)
370       (quest-data-update 'questentry-the-man 'common 1)
371       )
372
373(define (ench-wrig knpc kpc)
374  (say knpc "The Wisest Wright prefers to work in isolation. You may find him "
375       "if you are persistent, but not in any city. "
376       "Seek the mage Kalcifax, I think she knows the Engineer well.")
377       (quest-wise-subinit 'questentry-engineer)
378       (quest-data-update 'questentry-engineer 'kalcifax 1)
379       )
380
381(define (ench-necr knpc kpc)
382  (say knpc "The most depraved and wicked of all the Wise, "
383       "my nemesis the Necromancer abides somewhere in the underworld. "
384       "He is powerful, deceitful and corrupt beyond redemption.")
385       (quest-wise-subinit 'questentry-necromancer)
386       (quest-data-update 'questentry-necromancer 'general-loc 1)
387      )
388
389(define (ench-alch knpc kpc)
390  (say knpc "The Alchemist keeps a lab near Oparine. "
391       "He is greedy and very cunning, so be wary of him.")
392       (quest-wise-subinit 'questentry-alchemist)
393       (quest-data-update 'questentry-alchemist 'oparine 1)
394       )
395
396(define (ench-thie knpc kpc)
397	;;in case quest generated once in progress
398	(quest-data-assign-once 'questentry-thiefrune)
399  (if (quest-done? (ench-first-quest (gob knpc)))
400      (say knpc "Although a nuisance, he was only a middleman. "
401           "I hope you did not treat him too harshly.")
402      (say knpc "The thief who stole my item must be very clever. The rangers "
403           "lost his trail in Trigrave. Inquire among everyone there if they "
404           "have seen the ^c+mthief^c-.")))
405
406(define (ench-kalc knpc kpc)
407  (say knpc "Kalcifax? She's rather hard to keep track of I'm afraid."))
408
409(define (ench-demo knpc kpc)
410  (say knpc "The Demon Gate is a legendary gate that wizards of old used to cross into other worlds. "
411       "Then, for reasons that vary in the telling, it was lost or sealed or forgotten or destroyed. "
412       "I always thought it a fiction."))
413
414(define (ench-ench knpc kpc)
415  (say knpc "Yes?"))
416
417(define enchanter-conv
418  (ifc basic-conv
419       (method 'default ench-default)
420       (method 'hail ench-hail)
421       (method 'name ench-name)
422       (method 'bye ench-bye)
423       (method 'job ench-job)
424       (method 'join ench-join)
425
426       (method 'ench ench-ench)
427       (method 'accu ench-accu)
428       (method 'alch ench-alch)
429       (method 'evil ench-good)
430       (method 'gate ench-gate)
431       (method 'good ench-good)
432       (method 'know ench-know)
433       (method 'moon ench-moon)
434       (method 'necr ench-necr)
435       (method 'rune ench-rune)
436       (method 'shri ench-shri)
437       (method 'thie ench-thie)
438       (method 'wand ench-wand)
439       (method 'warr ench-warr)
440       (method 'wise ench-wise)
441       (method 'wiza ench-wiza)
442       (method 'wrog ench-wrog)
443       (method 'wrig ench-wrig)
444       (method 'emgi ench-wrig)
445       (method 'kalc ench-kalc)
446       (method 'demo ench-demo)
447       ))
448
449;;----------------------------------------------------------------------------
450;; First-time constructor
451;;----------------------------------------------------------------------------
452(define (mk-enchanter-first-time tag)
453  (bind
454   (kern-char-arm-self
455    (kern-mk-char
456     tag ;;..........tag
457     "Enchanter" ;;.......name
458     sp_human ;;.....species
459     oc_wizard ;;.. .occupation
460     s_old_mage ;;..sprite
461     ;;(mk-composite-sprite (list s_hum_body s_hum_belt s_hum_beard))
462     faction-men ;;..faction
463     0 ;;...........custom strength modifier
464     7 ;;...........custom intelligence modifier
465     0 ;;...........custom dexterity modifier
466     10 ;;............custom base hp modifier
467     2 ;;............custom hp multiplier (per-level)
468     20 ;;............custom base mp modifier
469     5 ;;............custom mp multiplier (per-level)
470     max-health ;;..current hit points
471     -1  ;;...........current experience points
472     max-health ;;..current magic points
473     0
474     enchanter-start-lvl  ;;..current level
475     #f ;;...........dead?
476     'enchanter-conv ;;...conversation (optional)
477     sch_enchanter ;;.....schedule (optional)
478     'townsman-ai ;;..........custom ai (optional)
479     ;;..............container (and contents)
480     (mk-inventory
481      (list
482       (list 10  t_food)
483       (list 100 t_arrow)
484       (list 1   t_bow)
485       (list 1   t_dagger)
486       (list 1   t_sword)
487       (list 1   t_leather_helm)
488       (list 1   t_armor_leather)
489       (list 5   t_torch)
490       (list 5   t_cure_potion)
491       (list 5   t_heal_potion)
492       ))
493     nil ;;.........readied arms (in addition to the container contents)
494     nil ;;..........hooks in effect
495     ))
496   (enchanter-mk)))
497