forked from steaphangreene/acidmud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_other.cpp
More file actions
5859 lines (5488 loc) · 196 KB
/
command_other.cpp
File metadata and controls
5859 lines (5488 loc) · 196 KB
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
// *************************************************************************
// This file is part of AcidMUD by Steaphan Greene
//
// Copyright 1999-2022 Steaphan Greene <steaphan@gmail.com>
//
// AcidMUD is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// AcidMUD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with AcidMUD (see the file named "COPYING");
// If not, see <http://www.gnu.org/licenses/>.
//
// *************************************************************************
#include <algorithm>
#include <string>
#include <vector>
#include "color.hpp"
#include "commands.hpp"
#include "dice.hpp"
#include "global.hpp"
#include "infile.hpp"
#include "log.hpp"
#include "mind.hpp"
#include "net.hpp"
#include "object.hpp"
#include "properties.hpp"
#include "utils.hpp"
#include "version.hpp"
#define SIT_ETHEREAL 1
#define SIT_CORPOREAL 2
#define SIT_ALIVE 4
#define SIT_CONSCIOUS 8
#define SIT_AWAKE 16
#define SIT_ALERT 32
#define SIT_LIE 64
#define SIT_SIT 128
#define SIT_STAND 256
#define SIT_USE 512
#define SIT_ACTION 4096
#define SIT_NINJAMODE 8192
#define SIT_NINJA 16384
#define SIT_SUPERNINJA 32768
#define CMD_FLAVORTEXT 65536
#define REQ_ETHEREAL (SIT_ETHEREAL)
#define REQ_CORPOREAL (SIT_CORPOREAL)
#define REQ_ALIVE (SIT_ALIVE | REQ_CORPOREAL)
#define REQ_CONSCIOUS (SIT_CONSCIOUS | REQ_ALIVE)
#define REQ_AWAKE (SIT_AWAKE | REQ_CONSCIOUS)
#define REQ_ALERT (SIT_ALERT | REQ_AWAKE)
#define REQ_LIE (SIT_LIE | REQ_CORPOREAL)
#define REQ_SIT (SIT_SIT | REQ_CORPOREAL)
#define REQ_STAND (SIT_STAND | REQ_CORPOREAL)
#define REQ_UP (SIT_STAND | SIT_USE | REQ_CORPOREAL)
#define REQ_ACTION (SIT_ACTION | REQ_CORPOREAL)
#define REQ_NINJAMODE (SIT_NINJAMODE)
#define REQ_NINJA (SIT_NINJA)
#define REQ_SUPERNINJA (SIT_SUPERNINJA | SIT_NINJA)
#define REQ_ANY (SIT_CORPOREAL | SIT_ETHEREAL)
static int count_ones(int mask) {
int ret = 0;
while (mask) {
++ret;
mask &= (mask - 1);
}
return ret;
}
// Return values: -1: Player D/Ced
// 0: Command Understood
// 1: Command NOT Understood
// 2: Command Understood - No More Actions This Round
int handle_command_other(
Object* body,
std::shared_ptr<Mind>& mind,
int cnum,
std::u8string_view args,
int stealth_t,
int stealth_s) {
std::u8string args_buf;
int ninja = 0, nmode = 0, vmode = 0;
if (mind && mind->Owner() && mind->Owner()->Is(PLAYER_SUPERNINJA)) {
ninja = 1;
} else if (mind && mind->Owner() && mind->Owner()->Is(PLAYER_NINJA)) {
ninja = 1;
}
if (mind && mind->Owner() && mind->Owner()->Is(PLAYER_NINJAMODE)) {
nmode = LOC_NINJA;
vmode |= LOC_NINJA;
}
if (body && body->Power(prhash(u8"Dark Vision"))) {
vmode |= LOC_DARK;
}
if (body && body->Power(prhash(u8"Heat Vision"))) {
vmode |= LOC_HEAT;
}
if (cnum == COM_VERSION) {
if (mind)
mind->Send(
u8"Version of this MUD is {}.{}.{}-{}-{}: {}.\n",
CurrentVersion.acidmud_version[0],
CurrentVersion.acidmud_version[1],
CurrentVersion.acidmud_version[2],
CurrentVersion.acidmud_git_revs,
CurrentVersion.acidmud_git_hash,
CurrentVersion.acidmud_datestamp);
return 0;
}
if (cnum == COM_SHUTDOWN) {
shutdn = 1;
if (mind)
mind->Send(u8"You instruct the system to shut down.\n");
return 0;
}
if (cnum == COM_RESTART) {
shutdn = 2;
if (mind)
mind->Send(u8"You instruct the system to restart.\n");
return 0;
}
if (cnum == COM_SAVEALL) {
shutdn = -1;
if (mind)
mind->Send(u8"You instruct the system to save all.\n");
return 0;
}
if (cnum == COM_SELECT) {
Object* sel = mind->Owner()->Room()->PickObject(std::u8string(args), LOC_INTERNAL | LOC_NINJA);
if (!sel) {
mind->Send(
u8"Sorry, that character doesn't exist.\n"
u8"Use the 'newcharacter' command to create a new character.\n");
return 0;
} else {
mind->Send(u8"'{}' is now selected as your currect character to work on.\n", sel->Name());
mind->Owner()->SetCreator(sel);
return 0;
}
}
if (cnum == COM_PASSWORD) {
if (args.empty()) {
if (!mind->SpecialPrompt().starts_with(u8"password")) {
mind->SetSVar(u8"change password", u8"old password");
mind->SetSpecialPrompt(u8"password");
mind->Send(u8"Changing player password.\nFirst enter old password to confirm.");
} else {
mind->SetSpecialPrompt(u8"");
mind->ClearSVar(u8"change password");
mind->Send(u8"Password has NOT been changed.");
}
} else {
auto pl = mind->Owner();
if (pl == nullptr) {
mind->SetSpecialPrompt(u8"");
mind->ClearSVar(u8"change password");
mind->ClearSVar(u8"encrypted password");
mind->Send(u8"Internal error: No Player linked to this Mind.");
} else if (!mind->IsSVar(u8"change password")) {
mind->SetSpecialPrompt(u8"");
mind->ClearSVar(u8"change password");
mind->ClearSVar(u8"encrypted password");
mind->Send(u8"Type 'password' alone to start the dialog to change your password.");
} else if (mind->SVar(u8"change password") == u8"old password") {
if (pl->AuthPass(args)) {
mind->SetSVar(u8"change password", u8"new password 1");
mind->Send(u8"Now, enter the new pasword.");
} else {
mind->SetSpecialPrompt(u8"");
mind->ClearSVar(u8"change password");
mind->ClearSVar(u8"encrypted password");
mind->Send(u8"Incorrect password. Password has NOT been changed.");
}
} else if (mind->SVar(u8"change password") == u8"new password 1") {
mind->SetSVar(u8"encrypted password", pl->EncPass(args));
mind->SetSVar(u8"change password", u8"new password 2");
mind->Send(u8"Now, enter the new pasword again, for verification.");
} else if (mind->SVar(u8"change password") == u8"new password 2") {
if (pl->AuthPass(mind->SVar(u8"encrypted password"), args)) {
mind->SetSpecialPrompt(u8"");
mind->ClearSVar(u8"change password");
pl->SetPass(mind->SVar(u8"encrypted password"));
mind->ClearSVar(u8"encrypted password");
mind->Send(u8"Password has been changed.");
} else {
mind->SetSpecialPrompt(u8"");
mind->ClearSVar(u8"change password");
mind->ClearSVar(u8"encrypted password");
mind->Send(u8"New passwords do not match. Password has NOT been changed.");
}
} else {
mind->SetSpecialPrompt(u8"");
mind->ClearSVar(u8"change password");
mind->ClearSVar(u8"encrypted password");
mind->Send(u8"Password has NOT been changed.");
}
}
return 0;
}
if (cnum == COM_NORTH) {
cnum = COM_ENTER;
args = u8"north";
}
if (cnum == COM_SOUTH) {
cnum = COM_ENTER;
args = u8"south";
}
if (cnum == COM_EAST) {
cnum = COM_ENTER;
args = u8"east";
}
if (cnum == COM_WEST) {
cnum = COM_ENTER;
args = u8"west";
}
if (cnum == COM_UP) {
cnum = COM_ENTER;
args = u8"up";
}
if (cnum == COM_DOWN) {
cnum = COM_ENTER;
args = u8"down";
}
if (cnum == COM_FLEE) {
auto dirs = body->PickObjects(u8"everywhere", vmode | LOC_NEARBY);
dirs.erase(
std::remove_if(
dirs.begin(),
dirs.end(),
[](const Object* o) { return o->Skill(prhash(u8"Open")) < 1; }),
dirs.end());
if (dirs.size() < 1) {
if (mind)
mind->Send(u8"There is nowhere go, you can't flee!\n");
return 0;
}
body->StartUsing(prhash(u8"Sprinting"));
body->ClearSkill(prhash(u8"Hidden"));
auto dir = Dice::Sample(dirs);
if (mind) {
mind->Send(u8"You try to flee {}.\n", dir->ShortDesc());
}
cnum = COM_ENTER;
args_buf = dir->ShortDesc();
args = args_buf;
}
if (cnum == COM_ENTER) {
if (!body) { // Implies that there is a u8"mind"
if (args.empty()) {
mind->Send(u8"Enter which character? Use 'enter <charname>'.\n");
return 0;
}
if (!mind->Owner()) { // The Autoninja (Initial Startup)
Object* god = new_body(Object::Universe());
god->SetDescs(u8"a metaphysical being", std::u8string(args), u8"", u8"");
god->Attach(mind);
return 0;
}
body =
mind->Owner()->Room()->PickObject(std::u8string(args), vmode | LOC_INTERNAL | LOC_NINJA);
if (!body) {
mind->Send(
u8"Sorry, that character doesn't exist.\n"
u8"Use the 'newcharacter' command to create a new character.\n");
return 0;
}
if (body->Skill(prhash(u8"Attribute Points")) > 0 ||
body->Skill(prhash(u8"Skill Points")) > 0) {
mind->Send(u8"You need to finish that character before you can use it.\n");
mind->Send(u8"'{}' is now selected as your currect character to work on.\n", body->Name());
mind->Owner()->SetCreator(body);
return 0;
}
if ((!nmode) && body->IsAct(act_t::DEAD)) { // Ninjas can autoheal
mind->Send(
u8"Sorry, that character is dead.\n"
u8"Use the 'newcharacter' command to create a new character.\n");
return 0;
}
// FIXME: Handle conversion of body->Skill(prhash(u8"Resources")).
if (mind->Owner()->Creator() == body)
mind->Owner()->SetCreator(nullptr);
body->Attach(mind);
if (!body->HasSkill(prhash(u8"Object ID"))) {
if (body->World()) {
body->ClearSkill(prhash(u8"Attribute Points"));
body->ClearSkill(prhash(u8"Skill Points"));
body->ClearSkill(prhash(u8"Invisible"));
auto obj_id = body->World()->Skill(prhash(u8"Last Object ID")) + 1;
body->World()->SetSkill(prhash(u8"Last Object ID"), obj_id);
body->SetSkill(prhash(u8"Object ID"), obj_id);
}
}
if (nmode) {
// This is ninja-healing and bypasses all healing mechanisms.
body->ClearSkill(prhash(u8"Poisoned"));
body->ClearSkill(prhash(u8"Thirsty"));
body->ClearSkill(prhash(u8"Hungry"));
body->SetStun(0);
body->SetPhys(0);
body->SetStru(0);
body->UpdateDamage();
body->Parent()->SendOut(
stealth_t,
stealth_s,
u8";s heals and repairs ;s with Ninja Powers[TM].\n",
u8"You heal ;s.\n",
body,
body);
}
if (body->IsAct(act_t::DYING)) {
mind->Send(u8"You can see nothing, you are too busy dying.\n");
} else if (body->IsAct(act_t::UNCONSCIOUS)) {
mind->Send(u8"You can see nothing, you are out cold.\n");
} else if (body->IsAct(act_t::SLEEP)) {
mind->Send(u8"You can see nothing since you are asleep.\n");
} else {
body->Parent()->SendDescSurround(mind, body);
}
mind->Send(CMAG u8"You have entered: {}\n" CNRM, body->World()->ShortDesc());
return 0;
}
Object* dest = body->PickObject(std::u8string(args), vmode | LOC_NEARBY);
Object* rdest = dest;
Object* veh = body;
if (!dest) {
if (mind)
mind->Send(u8"You want to go where?\n");
return 0;
}
if (dest->ActTarg(act_t::SPECIAL_LINKED) && dest->ActTarg(act_t::SPECIAL_LINKED)->Parent()) {
rdest = dest->ActTarg(act_t::SPECIAL_LINKED)->Parent();
}
if ((!dest->Skill(prhash(u8"Enterable"))) && (!ninja)) {
if (mind)
mind->Send(u8"It is not possible to enter that object!\n");
} else if ((!dest->Skill(prhash(u8"Enterable"))) && (!nmode)) {
if (mind)
mind->Send(u8"You need to be in ninja mode to enter that object!\n");
} else if (dest->Skill(prhash(u8"Open")) < 1 && (!nmode)) {
if (mind)
mind->Send(u8"Sorry, {} is closed!\n", dest->Noun());
} else if (
dest->Parent() != body->Parent() && dest->Parent() == body->Parent()->Parent() &&
body->Parent()->Skill(prhash(u8"Vehicle")) == 0) {
if (mind)
mind->Send(u8"You can't get {} to go there!\n", body->Parent()->Noun(1));
} else if (
dest->Parent() != body->Parent() && dest->Parent() == body->Parent()->Parent() &&
(!(body->Parent()->Skill(prhash(u8"Vehicle")) & 0xFFF0)) // No Land Travel!
&& body->Parent()->Parent()->Skill(prhash(u8"WaterDepth")) == 0 &&
rdest->Skill(prhash(u8"WaterDepth")) == 0) {
if (mind)
mind->Send(u8"You can't get {} to go there!\n", body->Parent()->Noun(1));
} else {
if (nmode) {
// Ninja-movement can't be followed!
if (body->Parent())
body->Parent()->NotifyGone(body);
}
if (dest->Parent() != body->Parent() && dest->Parent() == body->Parent()->Parent()) {
if (body->Parent()->Skill(prhash(u8"Vehicle")) == 4 &&
body->Skill(prhash(u8"Boat, Row")) == 0) {
if (mind)
mind->Send(u8"You don't know how to operate {}!\n", body->Parent()->Noun(1));
return 0;
}
veh = body->Parent();
}
if (rdest->Skill(prhash(u8"WaterDepth")) == 1 && body->Skill(prhash(u8"Swimming")) == 0) {
if (veh == body || (veh->Skill(prhash(u8"Vehicle")) & 4) == 0) { // Have boat?
if (mind)
mind->Send(u8"Sorry, but you can't swim!\n");
return 0;
}
} else if (rdest->Skill(prhash(u8"WaterDepth")) > 1) {
if (veh == body || (veh->Skill(prhash(u8"Vehicle")) & 4) == 0) { // Have boat?
if (mind)
mind->Send(u8"Sorry, you need a boat to go there!\n");
return 0;
}
}
int newworld = (body->World() != rdest->World());
if (dest->ActTarg(act_t::SPECIAL_LINKED) && dest->ActTarg(act_t::SPECIAL_LINKED)->Parent()) {
body->Parent()->SendOut(stealth_t, stealth_s, u8";s leaves ;s.\n", u8"", body, dest);
dest = dest->ActTarg(act_t::SPECIAL_LINKED)->Parent();
} else if (body->Parent()) {
body->Parent()->SendOut(stealth_t, stealth_s, u8";s enters ;s.\n", u8"", body, dest);
}
int reas = 0;
bool will_arrive =
(dest->Parent() != body->Parent() || // Not going *into* something.
(dest->Skill(prhash(u8"Transparent")) < 100 && // Or it's opague...
dest->Skill(prhash(u8"Open")) < 100)); // ...and closed.
if ((!nmode) && (reas = veh->Travel(dest))) {
if (reas < 0) { // If it's not a script-prevent (which handles alert)
body->Parent()->SendOut(
stealth_t,
stealth_s,
u8"...but ;s didn't seem to fit!\n",
u8"You could not fit!\n",
body,
nullptr);
}
} else {
if (nmode) {
body->Parent()->RemoveLink(body);
body->SetParent(dest);
}
if (will_arrive) {
body->Parent()->SendOut(stealth_t, stealth_s, u8";s arrives.\n", u8"", body, nullptr);
}
if (mind && (vmode & (LOC_NINJA | LOC_DARK)) == 0 && body->Parent()->LightLevel() < 100) {
mind->Send(u8"It's too dark, you can't see anything.\n");
} else if (mind && mind->Type() == mind_t::REMOTE) {
body->Parent()->SendDescSurround(body, body, vmode);
} else if (mind && mind->Type() == mind_t::SYSTEM) {
mind->Send(u8"You enter {}\n", std::u8string(args));
}
if (mind && newworld) {
mind->Send(CMAG u8"You have entered: {}\n" CNRM, body->World()->ShortDesc());
}
if (stealth_t > 0) {
body->SetSkill(prhash(u8"Hidden"), body->Roll(prhash(u8"Stealth"), 2) * 2);
}
if (body->Roll(prhash(u8"Running"), 2) < 1) { // FIXME: Terrain/Direction Mods?
if (mind) {
mind->Send(
CRED u8"\nYou are winded, and have to catch your breath." CNRM u8" Raise the " CMAG u8"Running" CNRM u8" skill.\n");
}
body->BusyFor(3000);
}
}
}
return 0;
}
if (cnum == COM_QUIT) {
if (!body) {
return -1; // Player Disconnected
}
// if(body) delete body;
if (mind)
body->Detach(mind);
if (mind && mind->Owner() && mind->Owner()->Room()) {
mind->Owner()->Room()->SendDesc(mind);
mind->Owner()->Room()->SendContents(mind);
} else if (mind)
mind->Send(u8"Use 'Enter' to return to the game.\n");
return 0;
}
if (cnum == COM_SAY) {
if (args.empty()) {
if (!mind->SpecialPrompt().starts_with(u8"say")) {
mind->SetSpecialPrompt(u8"say");
mind->Send(u8"Type what your character will say - exit by just hitting ENTER:");
} else {
mind->SetSpecialPrompt(u8"");
mind->Send(u8"Exiting out of say mode.");
}
return 0;
} else {
bool shouting = (args.length() >= 4 && !std::any_of(args.begin(), args.end(), ascii_islower));
if (!shouting) {
body->Parent()->SendOut(ALL, 0, u8";s says '{}'\n", u8"You say '{}'\n", body, body, args);
body->ClearSkill(prhash(u8"Hidden"));
return 0;
} else {
cnum = COM_SHOUT;
}
}
}
if (cnum == COM_SHOUT || cnum == COM_YELL || cnum == COM_CALL) {
if (mind && args.empty()) {
if (!mind->SpecialPrompt().starts_with(u8"shout")) {
mind->SetSpecialPrompt(u8"shout");
mind->Send(
u8"Type what your character will shout - exit by just hitting "
u8"ENTER:");
} else {
mind->SetSpecialPrompt(u8"");
mind->Send(u8"Exiting out of shout mode.");
}
} else {
if (args.substr(0, 4) == u8"for ") {
auto prefix = args.find_first_not_of(u8" \t\n\r", 4);
if (prefix == std::u8string::npos) {
args = u8"";
} else {
args = args.substr(prefix);
}
}
std::u8string mes = std::u8string(args);
std::transform(mes.begin(), mes.end(), mes.begin(), ascii_toupper);
body->Parent()->SendOut(
ALL, 0, u8";s shouts '{}'!!!\n", u8"You shout '{}'!!!\n", body, body, mes);
body->Parent()->Loud(body->ModAttribute(2), u8"someone shout '{}'!!!", mes);
}
body->ClearSkill(prhash(u8"Hidden"));
return 0;
}
if (cnum == COM_EMOTE) {
std::u8string dot = u8".";
if (args.back() == '.' || args.back() == '?' || args.back() == '!') {
dot = u8"";
}
body->Parent()->SendOut(
ALL, 0, u8";s {}{}\n", u8"Your character {}{}\n", body, body, args, dot);
body->ClearSkill(prhash(u8"Hidden"));
return 0;
}
if (cnum == COM_INTRODUCE) {
Object* targ = body;
if (!args.empty()) {
targ = body->PickObject(std::u8string(args), vmode | LOC_NEARBY | LOC_SELF | LOC_INTERNAL);
if (!targ) {
if (mind) {
mind->Send(u8"You don't see them here.\n");
}
return 0;
}
if ((!targ->HasName()) || (!body->Knows(targ))) {
if (mind) {
mind->Send(u8"You don't know what name to introduce them as.\n");
}
return 0;
}
}
body->Parent()->SendOut(
ALL,
0,
u8";s introduces ;s as \"{}\"\n",
u8"You introduce ;s as \"{}\".\n",
body,
targ,
targ->Name());
body->ClearSkill(prhash(u8"Hidden"));
return 0;
}
if (cnum == COM_INVENTORY) {
if (mind) {
mind->Send(u8"You ({}) are carrying:\n", body->ShortDesc());
body->SendExtendedActions(mind, LOC_TOUCH | vmode | 1);
}
return 0;
}
if (cnum == COM_EQUIPMENT) {
if (mind) {
mind->Send(u8"You ({}) are using:\n", body->ShortDesc());
body->SendExtendedActions(mind, LOC_TOUCH | vmode);
}
return 0;
}
if (cnum == COM_LOOK) {
if (!body) {
mind->Owner()->Room()->SendDesc(mind);
mind->Owner()->Room()->SendContents(mind, nullptr, vmode);
return 0;
}
if (!body->Parent()) {
return 0;
}
if (mind && (vmode & (LOC_NINJA | LOC_DARK)) == 0 && body->Parent()->LightLevel() < 100) {
if (mind)
mind->Send(u8"It's too dark, you can't see anything.\n");
return 0;
}
int within = 0;
if (args.substr(0, 3) == u8"at ") {
auto prefix = args.find_first_not_of(u8" \t\n\r", 3);
if (prefix == std::u8string::npos) {
args = u8"";
} else {
args = args.substr(prefix);
}
} else if (args.substr(0, 3) == u8"in ") {
auto prefix = args.find_first_not_of(u8" \t\n\r", 3);
if (prefix == std::u8string::npos) {
args = u8"";
} else {
args = args.substr(prefix);
}
within = 1;
}
DArr64<Object*> targs;
if (!args.empty()) {
targs = body->PickObjects(
std::u8string(args), vmode | LOC_NEARBY | LOC_ADJACENT | LOC_SELF | LOC_INTERNAL);
} else {
targs.push_back(body->Parent());
}
if (targs.size() < 1) {
if (mind)
mind->Send(u8"You don't see that here.\n");
return 0;
}
for (auto targ : targs) {
if (within && (!targ->Skill(prhash(u8"Container"))) &&
(!targ->Skill(prhash(u8"Liquid Container")))) {
if (mind)
mind->Send(u8"You can't look inside {}, it is not a container.\n", targ->Noun());
} else if (within && (targ->Skill(prhash(u8"Locked")))) {
if (mind)
mind->Send(u8"You can't look inside {}, it is locked.\n", targ->Noun());
} else {
int must_open = within;
if (within && targ->Skill(prhash(u8"Open")))
must_open = 0;
if (must_open) {
targ->SetSkill(prhash(u8"Open"), 1000);
body->Parent()->SendOut(
stealth_t, stealth_s, u8";s opens ;s.\n", u8"You open ;s.\n", body, targ);
}
if (args.empty()) {
body->Parent()->SendOut(stealth_t, stealth_s, u8";s looks around.\n", u8"", body, targ);
if (mind)
targ->SendDescSurround(mind, body, vmode);
} else if (
args == u8"north" || args == u8"south" || args == u8"east" || args == u8"west" ||
args == u8"up" || args == u8"down") {
body->Parent()->SendOut(stealth_t, stealth_s, u8";s looks ;s.\n", u8"", body, targ);
if (mind) {
targ->SendDesc(mind, body);
targ->SendExtendedActions(mind, vmode);
}
} else if (within) {
body->Parent()->SendOut(
stealth_t, stealth_s, u8";s looks inside ;s.\n", u8"", body, targ);
if (mind) {
targ->SendDesc(mind, body);
targ->SendExtendedActions(mind, vmode);
targ->SendContents(mind, nullptr, vmode);
}
} else {
body->Parent()->SendOut(stealth_t, stealth_s, u8";s looks at ;s.\n", u8"", body, targ);
if (mind) {
targ->SendDesc(mind, body);
targ->SendExtendedActions(mind, vmode);
}
}
if (must_open) {
targ->ClearSkill(prhash(u8"Open"));
body->Parent()->SendOut(
stealth_t, stealth_s, u8";s closes ;s.\n", u8"You close ;s.\n", body, targ);
}
}
}
if (targs.size() == 1 && targs.front() != body->Parent()) {
targs.front()->TryCombine();
}
return 0;
}
if (cnum == COM_SEARCH) {
if (!body->Parent())
return 0;
if (mind && (vmode & (LOC_NINJA | LOC_DARK)) == 0 && body->Parent()->LightLevel() < 100) {
if (mind)
mind->Send(u8"It's too dark, you can't see anything.\n");
return 0;
}
DArr64<Object*> targs;
if (!args.empty()) {
targs = body->PickObjects(
std::u8string(args), vmode | LOC_NEARBY | LOC_ADJACENT | LOC_SELF | LOC_INTERNAL);
if (targs.size() == 0) {
if (mind)
mind->Send(u8"You don't see that here.\n");
return 0;
}
} else {
targs.push_back(body->Parent());
}
stealth_t = 0;
stealth_s = 0;
if (body->Position() == pos_t::USE && (!body->IsUsing(prhash(u8"Perception")))) {
body->Parent()->SendOut(
stealth_t,
stealth_s,
u8";s stops {}.\n",
u8"You stop {}.\n",
body,
nullptr,
body->UsingString());
}
body->StartUsing(prhash(u8"Perception"));
body->ClearSkill(prhash(u8"Hidden"));
for (auto targ : targs) {
std::u8string denied = u8"";
for (Object* own = targ; own; own = own->Parent()) {
if (own->IsAnimate() && own != body && (!own->IsAct(act_t::SLEEP)) &&
(!own->IsAct(act_t::DEAD)) && (!own->IsAct(act_t::DYING)) &&
(!own->IsAct(act_t::UNCONSCIOUS))) {
denied = u8"You would need ";
denied += own->Noun(1);
denied += u8"'s permission to search ";
denied += targ->Noun(0, 0, nullptr, own);
denied += u8".\n";
} else if (
own->Skill(prhash(u8"Container")) && (!own->Skill(prhash(u8"Open"))) &&
own->Skill(prhash(u8"Locked"))) {
denied = own->Noun(1);
if (own == targ) {
denied += u8" is closed and locked so you can't search it.\n";
} else {
denied += u8" is closed and locked so you can't get to ";
denied += targ->Noun(1);
denied += u8".\n";
}
denied[0] = ascii_toupper(denied[0]);
}
}
if ((!nmode) && (!denied.empty())) {
if (mind)
mind->Send(denied);
continue;
}
body->Parent()->SendOut(
stealth_t, stealth_s, u8";s searches ;s.\n", u8"you search ;s.\n", body, targ);
auto objs = targ->Contents(vmode);
for (auto obj : objs) {
if (obj->Skill(prhash(u8"Hidden"))) {
if (body->Roll(prhash(u8"Perception"), obj->Skill(prhash(u8"Hidden")))) {
obj->ClearSkill(prhash(u8"Hidden"));
body->Parent()->SendOut(
stealth_t, stealth_s, u8";s reveals ;s.\n", u8"you reveal ;s.\n", body, obj);
}
}
}
if (mind) {
targ->SendExtendedActions(mind, LOC_TOUCH | vmode | 1);
targ->SendContents(mind, body, LOC_TOUCH | vmode | 1);
}
}
return 0;
}
if (cnum == COM_HIDE) {
DArr64<Object*> targs;
if (args.empty()) {
targs.push_back(body);
} else {
targs = body->PickObjects(std::u8string(args), vmode | LOC_INTERNAL | LOC_NEARBY | LOC_SELF);
}
if (targs.size() < 1) {
if (mind)
mind->Send(u8"You don't see that here.\n");
return 0;
}
for (auto targ : targs) {
std::u8string denied = u8"";
for (Object* own = targ; own; own = own->Parent()) {
if (own->IsAnimate() && own != body && (!own->IsAct(act_t::SLEEP)) &&
(!own->IsAct(act_t::DEAD)) && (!own->IsAct(act_t::DYING)) &&
(!own->IsAct(act_t::UNCONSCIOUS))) {
denied = u8"You would need ";
denied += own->Noun(1);
denied += u8"'s permission to hide ";
denied += targ->Noun(0, 0, nullptr, own);
denied += u8".\n";
} else if (
own->Skill(prhash(u8"Container")) && (!own->Skill(prhash(u8"Open"))) &&
own->Skill(prhash(u8"Locked"))) {
if (own != targ) {
denied = own->Noun(1);
denied += u8" is closed and locked so you can't get to ";
denied += targ->Noun(1);
denied += u8".\n";
denied[0] = ascii_toupper(denied[0]);
}
}
}
if ((!nmode) && (denied.empty())) {
if (mind)
mind->Send(denied);
continue;
}
if ((!nmode) && targ->Skill(prhash(u8"Obvious"))) {
if (mind)
mind->Send(u8"You could never hide {}, it's too obvious.", targ->Noun(0, 0, body));
continue;
}
if ((!nmode) && targ->Skill(prhash(u8"Open"))) {
if (targ->Skill(prhash(u8"Closeable"))) {
if (mind)
mind->Send(u8"You can't hide {} while it's open.", targ->Noun(0, 0, body));
} else {
if (mind)
mind->Send(u8"You can't hide {}. It's wide open.", targ->Noun(0, 0, body));
}
continue;
}
body->Parent()->SendOut(
stealth_t, stealth_s, u8";s hides ;s.\n", u8"you hide ;s.\n", body, targ);
targ->SetSkill(prhash(u8"Hidden"), body->Roll(prhash(u8"Stealth"), 2) * 2);
}
return 0;
}
if (cnum == COM_EXAMINE) {
Object* targ = nullptr;
if (args.empty()) {
if (mind)
mind->Send(u8"You want to examine what?\n");
return 0;
}
targ = body->PickObject(std::u8string(args), vmode | LOC_INTERNAL | LOC_NEARBY | LOC_SELF);
if (!targ) {
if (mind)
mind->Send(u8"You don't see that here.\n");
} else {
body->Parent()->SendOut(stealth_t, stealth_s, u8";s examines ;s.\n", u8"", body, targ);
if (mind)
targ->SendLongDesc(mind, body);
}
return 0;
}
if (cnum == COM_CONSIDER) {
Object* targ = nullptr;
if (args.empty()) {
if (mind)
mind->Send(u8"You want to consider what?\n");
return 0;
}
targ = body->PickObject(std::u8string(args), vmode | LOC_INTERNAL | LOC_NEARBY | LOC_SELF);
if (!targ) {
if (mind)
mind->Send(u8"You don't see that here.\n");
} else if (!targ->IsAnimate()) { // Inanimate Object (Consider Using)
body->Parent()->SendOut(
stealth_t,
stealth_s,
u8";s considers using ;s.\n",
u8"You consider using ;s.\n",
body,
targ);
if (!mind)
return 0;
int handled = 0;
// Weapons
if (targ->HasSkill(prhash(u8"WeaponType"))) {
handled = 1;
Object* base = nullptr;
for (auto loc :
{act_t::WIELD,
act_t::WEAR_RHIP,
act_t::WEAR_RSHOULDER,
act_t::WEAR_LHIP,
act_t::WEAR_LSHOULDER}) {
if (!base) {
if (body->ActTarg(loc)) {
base = body->ActTarg(loc);
}
}
}
if (base == targ) {
mind->Send(u8"{} is your current weapon!\n", base->Noun(0, 0, body));
mind->Send(u8"Consider using something else for comparison.\n");
return 0;
}
uint32_t sk = (get_weapon_skill(targ->Skill(prhash(u8"WeaponType"))));
if (!body->HasSkill(sk)) {
mind->Send(
CYEL u8"You don't know much about weapons like {}.\n" CNRM, targ->Noun(1, 1, body));
mind->Send(
CYEL u8"You would need to learn the {} skill to know more.\n" CNRM, SkillName(sk));
} else {
int diff;
mind->Send(u8"Use of this weapon would use your {} skill.\n", SkillName(sk));
if (base) {
mind->Send(u8"You would use this weapon instead of {}.\n", base->Noun(1, 1, body));
} else {
mind->Send(u8"You would use this weapon instead of your fists.\n");
}
diff = body->Skill(sk);
if (base)
diff -= body->Skill(get_weapon_skill(base->Skill(prhash(u8"WeaponType"))));
else
diff -= body->Skill(prhash(u8"Punching"));
if (diff > 0)
mind->Send(CGRN u8" ...would be a weapon you are more skilled with.\n" CNRM);
else if (diff < 0)
mind->Send(CYEL u8" ...would be a weapon you are less skilled with.\n" CNRM);
else
mind->Send(u8" ...would be a weapon you are similarly skilled with.\n");
diff = targ->Skill(prhash(u8"WeaponReach"));
if (base)
diff -= base->Skill(prhash(u8"WeaponReach"));
if (diff > 0)
mind->Send(CGRN u8" ...would give you more reach.\n" CNRM);
else if (diff < 0)
mind->Send(CYEL u8" ...would give you less reach.\n" CNRM);
else
mind->Send(u8" ...would give you similar reach.\n");
diff = targ->Skill(prhash(u8"WeaponForce"));
if (base)
diff -= base->Skill(prhash(u8"WeaponForce"));
if (diff > 0)
mind->Send(CGRN u8" ...would be more likely to do damage.\n" CNRM);
else if (diff < 0)
mind->Send(CYEL u8" ...would be less likely to do damage.\n" CNRM);
else
mind->Send(u8" ...would be about as likely to do damage.\n");
diff = targ->Skill(prhash(u8"WeaponSeverity"));
if (base)
diff -= base->Skill(prhash(u8"WeaponSeverity"));
if (diff > 0)
mind->Send(CGRN u8" ...would do more damage.\n" CNRM);
else if (diff < 0)
mind->Send(CYEL u8" ...would do less damage.\n" CNRM);
else
mind->Send(u8" ...would do similar damage.\n");
diff = two_handed(targ->Skill(prhash(u8"WeaponType")));
if (base)
diff -= two_handed(base->Skill(prhash(u8"WeaponType")));
if (diff > 0)
mind->Send(CYEL u8" ...would require both hands to use.\n" CNRM);
else if (diff < 0)
mind->Send(CGRN u8" ...would not reqire both hands to use.\n" CNRM);
}
}