/
gwendylon.c
2760 lines (2252 loc) · 104 KB
/
gwendylon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* $Id: gwendylon.c,v 1.13 2007/08/21 22:04:50 devel Exp $ (c) 2005 D.Brockhaus
*
* $Log: gwendylon.c,v $
* Revision 1.13 2007/08/21 22:04:50 devel
* B and C mushroom need a min elvel now
*
* Revision 1.12 2007/08/13 18:52:01 devel
* fixed some warnings
*
* Revision 1.11 2007/08/09 11:13:08 devel
* sttaistics
*
* Revision 1.10 2007/07/13 15:47:16 devel
* clog -> charlog
*
* Revision 1.9 2007/07/01 13:26:55 devel
* added caligar teleport
*
* Revision 1.8 2007/02/28 10:42:34 devel
* made yoakin's quest appear later in the questlog
*
* Revision 1.7 2007/02/24 14:09:54 devel
* NWO first checkin, feb 24
*
* Revision 1.6 2006/12/08 10:34:46 devel
* fixed bug in logain driver
*
* Revision 1.5 2006/09/21 11:23:48 devel
* more questlog fixes
*
* Revision 1.4 2006/09/14 09:55:22 devel
* added questlog
*
* Revision 1.3 2006/05/29 15:28:28 ssim
* made gwendylon destroy leftover items in citem
*
* Revision 1.2 2005/12/04 17:25:40 ssim
* increased EXP for werewolf quest
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "server.h"
#include "log.h"
#include "notify.h"
#include "direction.h"
#include "do.h"
#include "path.h"
#include "error.h"
#include "drdata.h"
#include "see.h"
#include "death.h"
#include "talk.h"
#include "effect.h"
#include "tool.h"
#include "date.h"
#include "map.h"
#include "create.h"
#include "drvlib.h"
#include "libload.h"
#include "quest_exp.h"
#include "item_id.h"
#include "skill.h"
#include "area1.h"
#include "consistency.h"
#include "database.h"
#include "questlog.h"
#include "statistics.h"
// library helper functions needed for init
int ch_driver(int nr,int cn,int ret,int lastact); // character driver (decides next action)
int it_driver(int nr,int in,int cn); // item driver (special cases for use)
int ch_died_driver(int nr,int cn,int co); // called when a character dies
int ch_respawn_driver(int nr,int cn); // called when an NPC is about to respawn
// EXPORTED - character/item driver
int driver(int type,int nr,int obj,int ret,int lastact)
{
switch(type) {
case CDT_DRIVER: return ch_driver(nr,obj,ret,lastact);
case CDT_ITEM: return it_driver(nr,obj,ret);
case CDT_DEAD: return ch_died_driver(nr,obj,ret);
case CDT_RESPAWN: return ch_respawn_driver(nr,obj);
default: return 0;
}
}
//-----------------------
struct qa
{
char *word[20];
char *answer;
int answer_code;
};
struct qa qa[]={
{{"how","are","you",NULL},"I'm fine!",0},
{{"hello",NULL},"Hello, %s!",0},
{{"hi",NULL},"Hi, %s!",0},
{{"greetings",NULL},"Greetings, %s!",0},
{{"hail",NULL},"And hail to you, %s!",0},
{{"what's","up",NULL},"Everything that isn't nailed down.",0},
{{"what","is","up",NULL},"Everything that isn't nailed down.",0},
{{"repeat",NULL},NULL,2},
{{"restart",NULL},NULL,2},
{{"please","repeat",NULL},NULL,2},
{{"please","restart",NULL},NULL,2},
{{"advice",NULL},NULL,3},
{{"buy","advice",NULL},NULL,4},
{{"promise",NULL},NULL,9},
{{"word",NULL},NULL,9},
{{"oath",NULL},NULL,9}
};
void lowerstrcpy(char *dst,char *src)
{
while (*src) *dst++=tolower(*src++);
*dst=0;
}
int analyse_text_driver(int cn,int type,char *text,int co)
{
char word[256];
char wordlist[20][256];
int n,w,q,name=0;
// ignore game messages
if (type==LOG_SYSTEM || type==LOG_INFO) return 0;
// ignore our own talk
if (cn==co) return 0;
if (!(ch[co].flags&CF_PLAYER)) return 0;
if (char_dist(cn,co)>12) return 0;
if (!char_see_char(cn,co)) return 0;
while (isalpha(*text)) text++;
while (isspace(*text)) text++;
while (isalpha(*text)) text++;
if (*text==':') text++;
while (isspace(*text)) text++;
if (*text=='"') text++;
n=w=0;
while (*text) {
switch (*text) {
case ' ':
case ',':
case ':':
case '?':
case '!':
case '"':
case '.': if (n) {
word[n]=0;
lowerstrcpy(wordlist[w],word);
if (strcasecmp(wordlist[w],ch[cn].name)) { if (w<20) w++; }
else name=1;
}
n=0; text++;
break;
default: word[n++]=*text++;
if (n>250) return 0;
break;
}
}
if (w) {
for (q=0; q<sizeof(qa)/sizeof(struct qa); q++) {
for (n=0; n<w && qa[q].word[n]; n++) {
//say(cn,"word = '%s'",wordlist[n]);
if (strcmp(wordlist[n],qa[q].word[n])) break;
}
if (n==w && !qa[q].word[n]) {
if (qa[q].answer) quiet_say(cn,qa[q].answer,ch[co].name,ch[cn].name);
else return qa[q].answer_code;
return 1;
}
}
}
return 0;
}
//-----------------------
struct gwendylon_driver_data
{
int last_talk;
int current_victim;
int nighttime;
int giveto;
};
void gwendylon_driver(int cn,int ret,int lastact)
{
struct gwendylon_driver_data *dat;
struct area1_ppd *ppd;
int co,in,talkdir=0,didsay=0;
struct msg *msg,*next;
dat=set_data(cn,DRD_GWENDYLONDRIVER,sizeof(struct gwendylon_driver_data));
if (!dat) return; // oops...
// loop through our messages
for (msg=ch[cn].msg; msg; msg=next) {
next=msg->next;
// did we see someone?
if (msg->type==NT_CHAR) {
co=msg->dat1;
// dont talk to other NPCs
if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }
// dont talk to players without connection
if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
// only talk every ten seconds
if (ticker<dat->last_talk+TICKS*5) { remove_message(cn,msg); continue; }
if (ticker<dat->last_talk+TICKS*10 && dat->current_victim && dat->current_victim!=co) { remove_message(cn,msg); continue; }
// dont talk to someone we cant see, and dont talk to ourself
if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }
// dont talk to someone far away
if (char_dist(cn,co)>16) { remove_message(cn,msg); continue; }
// get current status with player
ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
if (ppd) {
switch(ppd->gwendy_state) {
case 0: quiet_say(cn,"Welcome %s! I am %s the Mage.",ch[co].name,ch[cn].name);
questlog_open(co,1);
ppd->gwendy_state=1; didsay=1;
break;
case 1: quiet_say(cn,"South-east of my tower lies an old ruin. 'Tis inhabitated by skeletons, raised by some evil magic.");
ppd->gwendy_state=2; didsay=1;
break;
case 2: quiet_say(cn,"I am trying to understand this magic. But I am too old to travel there, so I couldst use thine help, %s. Wouldst thou go thither and look for magical items?",ch[co].name);
ppd->gwendy_state=3; didsay=1;
break;
case 3: quiet_say(cn,"It could be anything: An enhanced bone, an ancient jewel, even a magical spoon of doom.");
ppd->gwendy_state=4; didsay=1;
break;
case 4: quiet_say(cn,"If thou couldst find it and bring it to me, I would reward thee.");
ppd->gwendy_state=5; didsay=1;
break;
case 5: if (realtime-ppd->gwendy_seen_timer>60) {
quiet_say(cn,"Be greeted, %s! Didst thou find anything magical in the skeleton's ruin? Or dost thou want me to °c4repeat°c0 mine offer?",ch[co].name);
notify_area(ch[cn].x,ch[cn].y,NT_NPC,NTID_TUTORIAL,1,co);
didsay=1;
}
break;
case 6: if (questlog_isdone(co,2)) { ppd->gwendy_state=10; break; }
quiet_say(cn,"I have analyzed the item thou brought me. It seems there are more places with skeletons close by.");
questlog_open(co,2);
ppd->gwendy_state++; didsay=1;
break;
case 7: quiet_say(cn,"Maybe the villagers know something about it. Some of them go hunting in the forest, they might have seen something. Thou might inquire in the tavern.");
ppd->gwendy_state++; didsay=1;
break;
case 8: quiet_say(cn,"Somewhere in that place, there must be another magical item. Couldst thou bring me that one as well? I would double thine reward.");
ppd->gwendy_state++; didsay=1;
break;
case 9: if (realtime-ppd->gwendy_seen_timer>60) {
quiet_say(cn,"Be greeted, %s! Didst thou find anything magical in the other skeleton place? Or dost thou want me to °c4repeat°c0 mine offer?",ch[co].name);
didsay=1;
}
break;
case 10: if (questlog_isdone(co,3)) { ppd->gwendy_state=13; break; }
quiet_say(cn,"There must be another of these skulls, adorned with a green jewel. But I have no idea where to look for it. If I had it, I could use all three skulls to locate their maker.");
questlog_open(co,3);
ppd->gwendy_state++; didsay=1;
break;
case 11: quiet_say(cn,"Oh, if thou couldst find it, %s, I would be very grateful. Pray thee %s, locate this skull and bring it to me.",ch[co].name,ch[co].name);
ppd->gwendy_state++; didsay=1;
break;
case 12: if (realtime-ppd->gwendy_seen_timer>60) {
quiet_say(cn,"Ah, %s! Didst thou find the skull? It really is of the utmost importance. Or dost thou want me to °c4repeat°c0 mine offer?",ch[co].name);
didsay=1;
}
break;
case 13: if (questlog_isdone(co,4)) { ppd->gwendy_state=17; break; }
quiet_say(cn,"This is most disturbing. My analysis shows that the skulls were created in this very tower.");
questlog_open(co,4);
ppd->gwendy_state++; didsay=1;
break;
case 14: quiet_say(cn,"But I know every room in here. How can this be? Thou hast been most clever so far, %s. If thou couldst search the tower?",ch[co].name);
ppd->gwendy_state++; didsay=1;
break;
case 15: quiet_say(cn,"If thou dost find that foul magician, make certain thou killest him. I am certain he does have a fourth skull. Please bring it to me so I can destroy it.");
ppd->gwendy_state++; didsay=1;
break;
case 16: if (realtime-ppd->gwendy_seen_timer>60) {
quiet_say(cn,"Ah, %s! I am most concerned. Didst thou find anything? Or dost thou want me to °c4repeat°c0 what I said about it?",ch[co].name);
didsay=1;
}
break;
case 17: quiet_say(cn,"I do not have any more work for thee, %s.",ch[co].name);
ppd->gwendy_state++; didsay=1;
break;
case 18: if (realtime-ppd->gwendy_seen_timer>60) {
quiet_say(cn,"Nice to see you, %s.",ch[co].name);
if (may_add_spell(co,IDR_BLESS) && do_bless(cn,co)) {
ppd->gwendy_seen_timer=realtime;
return;
}
didsay=1;
}
break;
}
ppd->gwendy_seen_timer=realtime;
if (didsay) {
dat->last_talk=ticker;
talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
dat->current_victim=co;
}
}
}
// talk back
if (msg->type==NT_TEXT) {
co=msg->dat3;
if (ticker>dat->last_talk+TICKS*10 && dat->current_victim) dat->current_victim=0;
if (dat->current_victim && dat->current_victim!=co) { remove_message(cn,msg); continue; }
switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
case 2: ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
if (ppd && ppd->gwendy_state<=5) { dat->last_talk=0; ppd->gwendy_state=1; }
if (ppd && ppd->gwendy_state>=6 && ppd->gwendy_state<=9) { dat->last_talk=0; ppd->gwendy_state=6; }
if (ppd && ppd->gwendy_state>=10 && ppd->gwendy_state<=12) { dat->last_talk=0; ppd->gwendy_state=10; }
if (ppd && ppd->gwendy_state>=13 && ppd->gwendy_state<=16) { dat->last_talk=0; ppd->gwendy_state=13; }
if (ppd && ppd->gwendy_state>=17) { dat->last_talk=0; ppd->gwendy_state=17; }
break;
}
if (didsay) {
talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
dat->current_victim=co;
}
}
// got an item?
if (msg->type==NT_GIVE) {
co=msg->dat1;
if ((in=ch[cn].citem)) { // we still have it
ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
if (it[in].ID==IID_AREA1_SKELSKULL && ppd && ppd->gwendy_state<=5) {
int tmp;
quiet_say(cn,"Ahh, yes, that might be the thing I was looking for. Thank thee, %s.",ch[co].name);
tmp=questlog_done(co,1);
destroy_item_byID(co,IID_AREA1_SKELSKULL);
destroy_item_byID(co,IID_AREA1_SKELKEY1);
destroy_item_byID(co,IID_AREA1_SKELKEY2);
destroy_item_byID(co,IID_AREA1_SKELKEY3);
ppd->gwendy_state=6;
// let it vanish, then
destroy_item(ch[cn].citem);
ch[cn].citem=0;
if (tmp==1) {
in=create_money_item(MONEY_AREA1_SKULL1);
if (!give_char_item(co,in)) destroy_item(in);
}
} else if (it[in].ID==IID_AREA1_WOODSKULL && ppd && ppd->gwendy_state>=6 && ppd->gwendy_state<=9) {
int tmp;
quiet_say(cn,"Ahh, yes, this is the thing I was looking for. Thank thee, %s.",ch[co].name);
tmp=questlog_done(co,2);
destroy_item_byID(co,IID_AREA1_WOODSKULL);
destroy_item_byID(co,IID_AREA1_WOODKEY);
ppd->gwendy_state=10;
// let it vanish, then
destroy_item(ch[cn].citem);
ch[cn].citem=0;
if (tmp==1) {
in=create_money_item(MONEY_AREA1_SKULL2);
if (!give_char_item(co,in)) destroy_item(in);
}
} else if (it[in].ID==IID_AREA1_MAGESKULL && ppd && ppd->gwendy_state>=10 && ppd->gwendy_state<=12) {
int tmp;
quiet_say(cn,"Ahh, yes, this is the third skull. Thank thee, %s, I appreciate thine efforts.",ch[co].name);
tmp=questlog_done(co,3);
destroy_item_byID(co,IID_AREA1_MAGESKULL);
ppd->gwendy_state=13;
// let it vanish, then
destroy_item(ch[cn].citem);
ch[cn].citem=0;
if (tmp==1) {
in=create_money_item(MONEY_AREA1_SKULL3);
if (!give_char_item(co,in)) destroy_item(in);
}
} else if (it[in].ID==IID_AREA1_WARLOCKSKULL && ppd && ppd->gwendy_state>=13 && ppd->gwendy_state<=16) {
int tmp;
quiet_say(cn,"This is the last skull! The evil mage must be dead then. I thank thee, %s!",ch[co].name);
tmp=questlog_done(co,4);
ppd->gwendy_state=17;
destroy_item_byID(co,IID_AREA1_WARLOCKSKULL);
destroy_item_byID(co,IID_AREA1_WARLOCKKEY);
// let it vanish, then
destroy_item(ch[cn].citem);
ch[cn].citem=0;
if (tmp==1) {
in=create_money_item(MONEY_AREA1_SKULL4);
if (!give_char_item(co,in)) destroy_item(in);
}
} else if (it[in].ID==IID_CALIGARLETTER) {
quiet_say(cn,"Hmm, I see. Well, I can teleport you to the area but I am uncertain of what will be there waiting for you. Be prepared adventurer. I would not trust those mages as far as I could throw them!");
log_char(co,LOG_SYSTEM,0,"While you are still trying to figure out how far Gwendylon might be able to throw those mages he quickly mutters a spell and teleports you.");
if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
ch[cn].citem=0;
if (!change_area(co,36,240,10)) quiet_say(cn,"Uh-Oh. There seems to be a rift in the space-time continuum. Please come again later so we can try again.");
} else {
quiet_say(cn,"Thou hast better use for this than I do. Well, if there is use for it at all.");
if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
ch[cn].citem=0;
}
}
}
remove_message(cn,msg);
}
// do something. whenever possible, call do_idle with as high a tick count
// as reasonable when doing nothing.
if (talkdir) turn(cn,talkdir);
if (dat->last_talk+TICKS*30<ticker) {
if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;
}
if (ch[cn].citem) {
elog("gwendylon about to destroy item %d %s",ch[cn].citem,it[ch[cn].citem].name);
destroy_item(ch[cn].citem);
ch[cn].citem=0;
}
do_idle(cn,TICKS);
}
//-----------------------
struct yoakin_driver_data
{
int last_talk;
int current_victim;
int nighttime;
};
void yoakin_driver(int cn,int ret,int lastact)
{
struct yoakin_driver_data *dat;
struct area1_ppd *ppd;
int co,in,talkdir=0,didsay=0;
struct msg *msg,*next;
dat=set_data(cn,DRD_YOAKINDRIVER,sizeof(struct yoakin_driver_data));
if (!dat) return; // oops...
// loop through our messages
for (msg=ch[cn].msg; msg; msg=next) {
next=msg->next;
// did we see someone?
if (msg->type==NT_CHAR) {
co=msg->dat1;
// dont talk to other NPCs
if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }
// dont talk to players without connection
if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
//quiet_say(cn,"diff=%d, victim=%d (%s)",ticker-dat->last_talk,dat->current_victim,ch[dat->current_victim].name);
// only talk every ten seconds
if (ticker<dat->last_talk+TICKS*5) { remove_message(cn,msg); continue; }
if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }
// dont talk to someone we cant see, and dont talk to ourself
if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }
// dont talk to someone far away
if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }
// get current status with player
ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
if (ppd) {
if (realtime-ppd->yoakin_seen_timer>120 && ppd->yoakin_state && ppd->yoakin_state<4) {
ppd->yoakin_state=1;
}
switch(ppd->yoakin_state) {
case 0: quiet_say(cn,"Hail %s! I am %s, the hunter.",ch[co].name,ch[cn].name);
ppd->yoakin_state=1; didsay=1;
break;
case 1: quiet_say(cn,"Be careful in the forest around the village, %s. There are wolves and bears about which can be very aggressive.",ch[co].name);
ppd->yoakin_state=2; didsay=1;
break;
case 2: if (ppd->logain_state<6) break; // dont give out quest before mad knights is done
quiet_say(cn,"Greetings again, %s. Lately, there have been reports of a huge bear on the path to the city.",ch[co].name);
questlog_open(co,5);
ppd->yoakin_state=3; didsay=1;
break;
case 3: quiet_say(cn,"This bear has been killing several travellers, and I put a price on its head. So if thou happen to kill it, bring me its teeth as proof.");
ppd->yoakin_state=4; didsay=1;
break;
case 4: if (realtime-ppd->yoakin_seen_timer>60) {
quiet_say(cn,"Hail, %s! Didst thou find that big bear? Or dost thou want me to °c4repeat°c0 mine offer?",ch[co].name);
didsay=1;
}
break;
case 5: break;
}
ppd->yoakin_seen_timer=realtime;
if (didsay) {
dat->last_talk=ticker;
talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
dat->current_victim=co;
}
}
}
// talk back
if (msg->type==NT_TEXT) {
co=msg->dat3;
if (ticker>dat->last_talk+TICKS*10 && dat->current_victim) dat->current_victim=0;
if (dat->current_victim && dat->current_victim!=co) { remove_message(cn,msg); continue; }
switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
case 2: ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
if (ppd && ppd->yoakin_state<=4) { dat->last_talk=0; ppd->yoakin_state=2; }
break;
}
if (didsay) {
talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
dat->current_victim=co;
}
}
// got an item?
if (msg->type==NT_GIVE) {
co=msg->dat1;
if ((in=ch[cn].citem)) { // we still have it
ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
if (it[in].ID==IID_AREA1_BIGBEAR_TOOTH && ppd && ppd->yoakin_state<=4) {
int tmp;
quiet_say(cn,"Thank thee, %s. Travelling in the forest will be safer now.",ch[co].name);
tmp=questlog_done(co,5);
destroy_item_byID(co,IID_AREA1_BIGBEAR_TOOTH);
ppd->yoakin_state=5;
// let it vanish, then
destroy_item(ch[cn].citem);
ch[cn].citem=0;
if (tmp==1) {
in=create_money_item(MONEY_AREA1_BEARTOOTH);
if (!give_char_item(co,in)) destroy_item(in);
}
} else if (it[in].ID==IID_SHRIKE_TALISMAN && ppd && ppd->shrike_state==0) {
emote(cn,"turns deadly pale and starts to tremble");
quiet_say(cn,"I... I thank thee, %s. I'd have never thought... Thank thee!",ch[co].name);
if (ppd->shrike_fails) {
quiet_say(cn,"And I forgive thee trying to kill me. My wounds were almost fatal, but I survived.");
give_exp(co,min(level_value(ch[co].level)/5,143462)); // 50000
} else give_exp(co,min(level_value(ch[co].level)/5,286925)); // 100000
ppd->shrike_state=1;
// let it vanish, then
destroy_item(ch[cn].citem);
ch[cn].citem=0;
} else {
quiet_say(cn,"Thou hast better use for this than I do. Well, if there is use for it at all.");
if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
ch[cn].citem=0;
}
}
}
remove_message(cn,msg);
}
// do something. whenever possible, call do_idle with as high a tick count
// as reasonable when doing nothing.
if (ch[cn].citem) {
destroy_item(ch[cn].citem);
ch[cn].citem=0;
}
if (talkdir) turn(cn,talkdir);
if (dat->last_talk+TICKS*30<ticker) {
if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_DOWN,ret,lastact)) return;
}
do_idle(cn,TICKS);
}
//-----------------------
struct terion_driver_data
{
int last_talk;
int last_walk;
int pos;
int current_victim;
};
void terion_driver(int cn,int ret,int lastact)
{
struct terion_driver_data *dat;
struct area1_ppd *ppd;
int co,in,didsay=0,talkdir=0;
struct msg *msg,*next;
dat=set_data(cn,DRD_TERIONDRIVER,sizeof(struct terion_driver_data));
if (!dat) return; // oops...
// loop through our messages once
for (msg=ch[cn].msg; msg; msg=next) {
next=msg->next;
if (msg->type==NT_NPC && msg->dat1==NTID_DIDSAY && msg->dat2!=cn) dat->last_talk=ticker;
}
// loop through our messages twice
for (msg=ch[cn].msg; msg; msg=next) {
next=msg->next;
// did we see someone?
if (msg->type==NT_CHAR) {
co=msg->dat1;
// dont talk to other NPCs
if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }
// dont talk to players without connection
if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
// only talk every ten seconds
if (ticker<dat->last_talk+TICKS*5) { remove_message(cn,msg); continue; }
if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }
// dont talk to someone we cant see, and dont talk to ourself
if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }
// dont talk to someone far away
if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }
// get current status with player
ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
if (ppd) {
switch(ppd->terion_state) {
case 0: if (ppd->gwendy_state<6) break; // dont offer skelly stories before skull 2
if (ppd->gwendy_state>9) { // advance to second hint if player solved skull 2 already
ppd->terion_state=4;
break;
}
quiet_say(cn,"Be greeted, %s! My name is %s.",ch[co].name,ch[cn].name);
ppd->terion_state=1; didsay=1;
break;
case 1: quiet_say(cn,"I have heard some stories about skeletons walking around in the western part of the forest lately. They were close to that small path which leads west directly behind the tavern.");
ppd->terion_state=2; didsay=1;
break;
case 2: quiet_say(cn,"Some of the lads from the village went looking for them, but had no luck. Or they were lucky, depends on the way thou lookst at it I guess.");
notify_area(ch[cn].x,ch[cn].y,NT_NPC,NTID_TERION,cn,1);
ppd->terion_state=3; didsay=1;
break;
case 3: quiet_say(cn,"Anyway. They found nothing. Guess that is because they dare not go late at night.");
ppd->terion_state=4; didsay=1;
break;
case 4: if (ppd->gwendy_state>=10 && ppd->gwendy_state<=12) {
quiet_say(cn,"Be greeted again, %s. I hope this day finds thee well.",ch[co].name);
ppd->terion_state++; didsay=1;
}
break;
case 5: quiet_say(cn,"I've been thinking about the skeletons, and the skulls Gwendylon is researching. It seems these skeletons are always seen near old ruins. And I remembered that Yoakin the Hunter once told me that his house was built on top of an old ruin.");
notify_area(ch[cn].x,ch[cn].y,NT_NPC,NTID_TERION,cn,3);
ppd->terion_state++; didsay=1;
break;
case 6: if (ppd->gwendy_state>=13) {
quiet_say(cn,"Ah, %s. 'Tis good to see there are brave %s about who will fight the evil which has been invading our lives lately.",ch[co].name,(ch[co].flags&CF_MALE) ? "men" : "women");
ppd->terion_state++; didsay=1;
}
break;
case 7: quiet_say(cn,"Ever since the dark hordes attacked Aston, things have been going downhill. Some years ago, we frequently had visitors from Aston and beyond. But today no one dares to travel unless he must.");
ppd->terion_state++; didsay=1;
break;
case 8: quiet_say(cn,"And those skeletons all around... We live in hard times.");
ppd->terion_state++; didsay=1;
break;
case 9: if (ppd->reskin_state>=9) {
quiet_say(cn,"Oh, what has become of this world? The two schools gone mad beyond cure, skeletons everywhere. And I've heard rumors that things all over the land are the same.");
ppd->terion_state++; didsay=1;
}
break;
case 10: quiet_say(cn,"Undeads and strange beasts and even demons have been seen in Aston. Didst thou know that?");
ppd->terion_state++; didsay=1;
break;
case 11: quiet_say(cn,"Some years ago those monsters attacked our capital and killed our emperor. Most of his honor guard, the Seyan'Du, died in his defense, but to no avail. With the emperor dead, and the imperial palace in ruins, there was no one to organize our defenses.");
ppd->terion_state++; didsay=1;
break;
case 12: quiet_say(cn,"And so the dark hordes are spreading all over the land.");
ppd->terion_state++; didsay=1;
break;
case 13: quiet_say(cn,"Hey! Reskin! Art thou certain that thou dost not have any beer? I couldst use a drink now.");
notify_area(ch[cn].x,ch[cn].y,NT_NPC,NTID_TERION,cn,5);
ppd->terion_state++; didsay=1;
break;
}
if (didsay) {
dat->last_talk=ticker;
talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
dat->current_victim=co;
notify_area(ch[cn].x,ch[cn].y,NT_NPC,NTID_DIDSAY,cn,0);
}
}
}
// talk back
if (msg->type==NT_TEXT) {
co=msg->dat3;
ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
case 2: if (ppd && ppd->terion_state<=4) { dat->last_talk=0; ppd->terion_state=0; }
if (ppd && ppd->terion_state>=5 && ppd->terion_state<=6) { dat->last_talk=0; ppd->terion_state=4; }
if (ppd && ppd->terion_state>=7 && ppd->terion_state<=9) { dat->last_talk=0; ppd->terion_state=6; }
if (ppd && ppd->terion_state>=10 && ppd->terion_state<=14) { dat->last_talk=0; ppd->terion_state=9; }
break;
}
if (didsay) {
talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
dat->current_victim=co;
}
}
// got an item?
if (msg->type==NT_GIVE) {
co=msg->dat1;
if ((in=ch[cn].citem)) { // we still have it
quiet_say(cn,"Thou hast better use for this than I do. Well, if there is use for it at all.");
if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
ch[cn].citem=0;
}
}
remove_message(cn,msg);
}
// do something. whenever possible, call do_idle with as high a tick count
// as reasonable when doing nothing.
if (talkdir) turn(cn,talkdir);
if (dat->last_talk+TICKS*30<ticker) {
if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;
}
do_idle(cn,TICKS);
}
//-----------------------
int has_empty_inventory(int cn)
{
int n;
for (n=0; n<12; n++)
if (ch[cn].item[n]) return 0;
for (n=30; n<INVENTORYSIZE; n++)
if (ch[cn].item[n]) return 0;
return 1;
}
struct james_driver_data
{
int last_talk;
int current_victim;
int nighttime;
};
int james_raisehint(int cn,int doraise);
void james_create_eq(int cn);
void james_driver(int cn,int ret,int lastact)
{
struct james_driver_data *dat;
struct area1_ppd *ppd;
int co,in,talkdir=0,didsay=0;
struct msg *msg,*next;
dat=set_data(cn,DRD_JAMESDRIVER,sizeof(struct james_driver_data));
if (!dat) return; // oops...
// loop through our messages
for (msg=ch[cn].msg; msg; msg=next) {
next=msg->next;
// did we see someone?
if (msg->type==NT_CHAR) {
co=msg->dat1;
// dont talk to other NPCs
if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }
// dont talk to players without connection
if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
// only talk every ten seconds
if (ticker<dat->last_talk+TICKS*5) { remove_message(cn,msg); continue; }
if (ticker<dat->last_talk+TICKS*10 && dat->current_victim && dat->current_victim!=co) { remove_message(cn,msg); continue; }
// dont talk to someone we cant see, and dont talk to ourself
if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }
// dont talk to someone far away
if (char_dist(cn,co)>15) { remove_message(cn,msg); continue; }
// get current status with player
ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
if (ppd) {
if (has_empty_inventory(co) && !(ppd->flags&AF1_STORAGE_HINT)) {
quiet_say(cn,"Shouldst thou need new equipment, %s, try the chests in the western corner. If thou hast not used them yet, they should contain all thou needst.",ch[co].name);
ppd->flags|=AF1_STORAGE_HINT; didsay=1;
}
switch(ppd->james_state) {
case 0: if (ppd->lydia_state>=6) { ppd->james_state=3; break; }
quiet_say(cn,"Ah, hello there, %s. I am %s. Couldst thou do me a favor? I went to a party with Lydia last night, and I must admit that I drank too much.",ch[co].name,ch[cn].name);
ppd->james_state++; didsay=1;
questlog_open(co,0);
break;
case 1: quiet_say(cn,"I cannot remember how I came back here, and if Lydia got home safely. So couldst thou visit Lydia and give her my regards and inquire about her health?");
ppd->james_state++; didsay=1;
break;
case 2: quiet_say(cn,"She lives with her father, Gwendylon the Mage. Thou canst find her in the mage's tower, north of here, %s.",ch[co].name);
ppd->james_state++; didsay=1;
break;
case 3: if (ppd->lydia_state<6) break;
quiet_say(cn,"Ah, %s. I am glad that thou could help Lydia.",ch[co].name);
ppd->james_state++; didsay=1;
break;
case 4: quiet_say(cn,"If you ever need °c4advice°c0 on how to raise your character, I'd be happy to help you - for a small fee.");
ppd->james_state++; didsay=1;
break;
case 5: break;
}
if (didsay) {
dat->last_talk=ticker;
talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
dat->current_victim=co;
}
}
}
// talk back
if (msg->type==NT_TEXT) {
co=msg->dat3;
if (ticker>dat->last_talk+TICKS*10 && dat->current_victim) dat->current_victim=0;
if (dat->current_victim && dat->current_victim!=co) { remove_message(cn,msg); continue; }
switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
case 2: ppd=set_data(co,DRD_AREA1_PPD,sizeof(struct area1_ppd));
if (ppd && ppd->james_state>=0 && ppd->james_state<=3) { ppd->james_state=0; dat->last_talk=0; }
break;
case 3: if (ch[co].level>70) quiet_say(cn,"I'm afraid I cannot help thee, %s. Thou art much wiser than I am.",ch[co].name);
else quiet_say(cn,"I'll help thee for the small fee of %.2fG, %s. Say °c4buy advice°c0 if thou wantst it.",ch[co].level*ch[co].level*ch[co].level/100.0,ch[co].name);
break;
case 4: if (ch[co].level>70) quiet_say(cn,"I'm afraid I cannot help thee, %s. Thou art much wiser than I am.",ch[co].name);
else if (take_money(co,ch[co].level*ch[co].level*ch[co].level)) james_raisehint(co,0);
else quiet_say(cn,"Thou dost not have enough money, %s.",ch[co].name);
break;
}
if (didsay) {
talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
dat->current_victim=co;
}
}
// got an item?
if (msg->type==NT_GIVE) {
co=msg->dat1;
if ((in=ch[cn].citem)) { // we still have it
quiet_say(cn,"Thou hast better use for this than I do. Well, if there is use for it at all.");
if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
ch[cn].citem=0;
}
}
remove_message(cn,msg);
}
// do something. whenever possible, call do_idle with as high a tick count
// as reasonable when doing nothing.
if (talkdir) turn(cn,talkdir);
if (dat->last_talk+TICKS*30<ticker) {
if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHTDOWN,ret,lastact)) return;
}
do_idle(cn,TICKS);
}
struct nook_driver_data
{
int last_talk;
int current_victim;
};
void nook_driver(int cn,int ret,int lastact)
{
struct nook_driver_data *dat;
struct area1_ppd *ppd;
int co,in,talkdir=0,didsay=0;
struct msg *msg,*next;
dat=set_data(cn,DRD_NOOKDRIVER,sizeof(struct nook_driver_data));
if (!dat) return; // oops...
// loop through our messages
for (msg=ch[cn].msg; msg; msg=next) {
next=msg->next;
// did we see someone?
if (msg->type==NT_CHAR) {
co=msg->dat1;
// dont talk to other NPCs
if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }
// dont talk to players without connection
if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
// only talk every ten seconds
if (ticker<dat->last_talk+TICKS*5) { remove_message(cn,msg); continue; }
if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }