-
Notifications
You must be signed in to change notification settings - Fork 0
/
shops.cpp
executable file
·1692 lines (1454 loc) · 39.9 KB
/
shops.cpp
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
/****************************************************************************
* [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame | \\._.// *
* -----------------------------------------------------------| (0...0) *
* SMAUG 1.0 (C) 1994, 1995, 1996 by Derek Snider | ).:.( *
* -----------------------------------------------------------| {o o} *
* SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus, | / ' ' \ *
* Scryn, Rennard, Swordbearer, Gorog, Grishnakh and Tricops |~'~.VxvxV.~'~*
* ------------------------------------------------------------------------ *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* ------------------------------------------------------------------------ *
* Shop and repair shop module *
****************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "mud.h"
// Forward declaration
void do_say(Character * ch, const char* argument);
/*
* Local functions
*/
#define CD CHAR_DATA
CD * find_keeper ( CHAR_DATA *ch ) ;
CD * find_fixer ( CHAR_DATA *ch ) ;
int get_cost ( CHAR_DATA *ch, CHAR_DATA *keeper,
OBJ_DATA *obj, bool fBuy );
int get_repaircost ( CHAR_DATA *keeper, OBJ_DATA *obj ) ;
#undef CD
/*
* Shopping commands.
*/
CHAR_DATA *find_keeper( CHAR_DATA *ch )
{
CHAR_DATA *keeper;
SHOP_DATA *pShop;
char buf[MAX_STRING_LENGTH];
pShop = NULL;
for ( keeper = ch->GetInRoom()->first_person;
keeper;
keeper = keeper->next_in_room )
if ( IS_NPC(keeper) && (pShop = keeper->pIndexData->pShop) != NULL )
break;
if ( !pShop )
{
return NULL;
}
/*
* Checks to see if the shop is open, tells you when to come back - Zoie
* Supports closing times after midnight
*/
if( pShop->open_hour > pShop->close_hour )
{
if( time_info.hour < pShop->open_hour && time_info.hour > pShop->close_hour )
{
if( pShop->open_hour == 12 )
do_say( keeper, "Sorry, come back at noon." );
else if( pShop->open_hour > 12 )
{
sprintf( buf, "Sorry, come back at %d pm.", ( pShop->open_hour - 12 ) );
do_say( keeper, buf );
}
else
{
sprintf( buf, "Sorry, come back at %d am.", pShop->open_hour );
do_say( keeper, buf );
}
return NULL;
}
}
else
{
if( time_info.hour < pShop->open_hour )
{
if( pShop->open_hour == 12 )
do_say( keeper, "Sorry, come back at noon." );
else if( pShop->open_hour > 12 )
{
sprintf( buf, "Sorry, come back at %d pm.", ( pShop->open_hour - 12 ) );
do_say( keeper, buf );
}
else
{
sprintf( buf, "Sorry, come back at %d am.", pShop->open_hour );
do_say( keeper, buf );
}
return NULL;
}
if( time_info.hour > pShop->close_hour )
{
if( pShop->open_hour == 0 )
do_say( keeper, "Sorry, come back at midnight." );
else if( pShop->open_hour > 12 )
{
sprintf( buf, "Sorry, come back tomorrow at %d pm.", ( pShop->open_hour - 12 ) );
do_say( keeper, buf );
}
else
{
sprintf( buf, "Sorry, come back tomorrow at %d am.", pShop->open_hour );
do_say( keeper, buf );
}
return NULL;
}
}
/*
* Invisible or hidden people.
*/
if ( !can_see( keeper, ch ) )
{
do_say( keeper, "I don't trade with folks I can't see." );
return NULL;
}
if ( !knows_language( keeper, ch->speaking, ch ) )
{
do_say( keeper, "I can't understand you." );
return NULL;
}
return keeper;
}
/*
* repair commands.
*/
CHAR_DATA *find_fixer( CHAR_DATA *ch )
{
CHAR_DATA *keeper;
REPAIR_DATA *rShop;
rShop = NULL;
for ( keeper = ch->GetInRoom()->first_person;
keeper;
keeper = keeper->next_in_room )
if ( IS_NPC(keeper) && (rShop = keeper->pIndexData->rShop) != NULL )
break;
if ( !rShop )
{
send_to_char( "You can't do that here.\n\r", ch );
return NULL;
}
/*
* Shop hours.
*/
if ( time_info.hour < rShop->open_hour )
{
do_say( keeper, "Sorry, come back later." );
return NULL;
}
if ( time_info.hour > rShop->close_hour )
{
do_say( keeper, "Sorry, come back tomorrow." );
return NULL;
}
/*
* Invisible or hidden people.
*/
if ( !can_see( keeper, ch ) )
{
do_say( keeper, "I don't trade with folks I can't see." );
return NULL;
}
if ( !knows_language( keeper, ch->speaking, ch ) )
{
do_say( keeper, "I can't understand you." );
return NULL;
}
return keeper;
}
int get_cost( CHAR_DATA *ch, CHAR_DATA *keeper, OBJ_DATA *obj, bool fBuy )
{
SHOP_DATA *pShop;
int cost;
bool richcustomer;
int profitmod;
if ( !obj || ( pShop = keeper->pIndexData->pShop ) == NULL )
return 0;
if ( ch->gold > (ch->level * ch->level * 100) )
richcustomer = TRUE;
else
richcustomer = FALSE;
if ( fBuy )
{
cost = (int) (cost * (80 + UMIN(ch->level, LEVEL_HERO_MAX))) / 100;
profitmod = 13 - ch->getCha() + (richcustomer ? 15 : 0)
+ ((URANGE(5,ch->level,LEVEL_HERO_MAX)-20)/2);
cost = (int) (obj->cost
* UMAX( (pShop->profit_sell+1), pShop->profit_buy+profitmod ) )
/ 100;
}
else
{
OBJ_DATA *obj2;
int itype;
profitmod = ch->getCha() - 13 - (richcustomer ? 15 : 0);
cost = 0;
for ( itype = 0; itype < MAX_TRADE; itype++ )
{
if ( obj->item_type == pShop->buy_type[itype] )
{
cost = (int) (obj->cost
* UMIN( (pShop->profit_buy-1),
pShop->profit_sell+profitmod) ) / 100;
break;
}
}
for ( obj2 = keeper->first_carrying; obj2; obj2 = obj2->next_content )
{
if ( obj->pIndexData == obj2->pIndexData )
{
cost = 0;
break;
}
}
}
if ( obj->item_type == ITEM_STAFF || obj->item_type == ITEM_WAND )
cost = (int) (cost * obj->value[2] / obj->value[1]);
return cost;
}
int get_repaircost( CHAR_DATA *keeper, OBJ_DATA *obj )
{
REPAIR_DATA *rShop;
int basecost;
int cost;
int itype;
bool found;
if ( !obj || ( rShop = keeper->pIndexData->rShop ) == NULL )
return 0;
cost = basecost = 0;
found = FALSE;
for ( itype = 0; itype < MAX_FIX; itype++ )
{
if ( obj->item_type == rShop->fix_type[itype] )
{
basecost = (int) (obj->cost / 75) + rShop->profit_fix;
if (basecost < 0)
basecost *= -1;
found = TRUE;
break;
}
}
if ( !found )
basecost = cost = -1;
if ( basecost == 0 )
basecost = 1;
if ( found && basecost > 0 )
{
switch (obj->item_type)
{
case ITEM_ARMOR:
case ITEM_WEAPON:
case ITEM_CONTAINER:
if (obj->condition >= obj->max_condition)
cost = -2;
else
{
int tempcondition = obj->condition;
if (tempcondition < 0)
{
cost = basecost * (-tempcondition ) * 3;
tempcondition = 0;
}
cost += basecost * (obj->max_condition - tempcondition );
}
break;
case ITEM_WAND:
case ITEM_STAFF:
if (obj->value[OBJECT_WAND_CHARGES] >= obj->value[OBJECT_WAND_MAXCHARGES])
cost = -2;
else
cost = basecost * (obj->value[OBJECT_WAND_MAXCHARGES] - obj->value[OBJECT_WAND_CHARGES]);
}
}
return cost;
}
void do_buy(CHAR_DATA *ch, const char* argument)
{
char arg[MAX_INPUT_LENGTH];
int maxgold;
int sn_haggle;
sn_haggle = skill_lookup("haggle");
argument = one_argument( argument, arg );
if ( arg[0] == '\0' )
{
send_to_char( "Buy what?\n\r", ch );
return;
}
if ( IS_SET(ch->GetInRoom()->room_flags, ROOM_PET_SHOP) )
{
char buf[MAX_STRING_LENGTH];
CHAR_DATA *pet;
ROOM_INDEX_DATA *pRoomIndexNext;
ROOM_INDEX_DATA *in_room;
if ( IS_NPC(ch) )
return;
pRoomIndexNext = get_room_index( ch->GetInRoom()->vnum + 1 );
if ( !pRoomIndexNext )
{
bug( "Do_buy: bad pet shop at vnum %s (no pet storage room at vnum+1).", vnum_to_dotted(ch->GetInRoom()->vnum));
send_to_char( "Sorry, you can't buy that here.\n\r", ch );
return;
}
in_room = ch->GetInRoom();
ch->InRoomId = pRoomIndexNext->GetId();
pet = get_char_room( ch, arg );
ch->InRoomId = in_room->GetId();
if ( pet == NULL || !IS_NPC( pet ) || !IS_SET(pet->act, ACT_PET) )
{
send_to_char( "Sorry, you can't buy that here.\n\r", ch );
return;
}
/* if ( IS_SET(ch->act, PLR_BOUGHT_PET) )
{
send_to_char( "You already bought one pet this level.\n\r", ch );
return;
}
*/
if ( ch->gold < 10 * pet->level * pet->level )
{
send_to_char( "You can't afford it.\n\r", ch );
return;
}
if ( ch->level < pet->level )
{
send_to_char( "You're not ready for this pet.\n\r", ch );
return;
}
maxgold = 10 * pet->level * pet->level;
ch->gold -= maxgold;
boost_economy( ch->GetInRoom()->area, maxgold );
pet = create_mobile( pet->pIndexData );
SET_BIT(ch->act, PLR_BOUGHT_PET);
SET_BIT(pet->act, ACT_PET);
SET_BIT(pet->affected_by, AFF_CHARM);
argument = one_argument( argument, arg );
if ( arg[0] != '\0' )
{
sprintf( buf, "%s %s", pet->getName().c_str(), arg );
pet->setName( buf );
}
sprintf( buf, "%sA neck tag says 'I belong to %s'.\n\r",
pet->description_.c_str(), ch->getShort().c_str() );
pet->description_ = buf;
char_to_room( pet, ch->GetInRoom() );
add_follower( pet, ch );
send_to_char( "Enjoy your pet.\n\r", ch );
act( AT_ACTION, "$n bought $N as a pet.", ch, NULL, pet, TO_ROOM );
return;
}
else
{
CHAR_DATA *keeper;
OBJ_DATA *obj;
int cost;
int noi = 1; /* Number of items */
sh_int mnoi = 20; /* Max number of items to be bought at once */
if ( ( keeper = find_keeper( ch ) ) == NULL )
{
send_to_char("You can't do that here.\n\r", ch);
return;
}
maxgold = keeper->level * keeper->level * 50000;
if ( is_number( arg ) )
{
noi = atoi( arg );
argument = one_argument( argument, arg );
if ( noi > mnoi )
{
act( AT_TELL, "$n tells you 'I don't sell that many items at"
" once.'", keeper, NULL, ch, TO_VICT ); return;
}
}
obj = get_obj_carry( keeper, arg );
cost = ( get_cost( ch, keeper, obj, TRUE ) * noi );
if ( cost <= 0 || !can_see_obj( ch, obj ) )
{
act( AT_TELL, "$n tells you 'I don't sell that -- try 'list'.'",
keeper, NULL, ch, TO_VICT );
return;
}
if ( obj->pIndexData->total_count >= obj->pIndexData->rare && obj->pIndexData->rare >= 1 )
{
interpret(keeper, "shake");
interpret(keeper, "say Sorry, I'm all out of stock.");
return;
}
if ( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) && ( noi > 1 ) )
{
interpret( keeper, "laugh" );
act( AT_TELL, "$n tells you 'I don't have enough of those in stock"
" to sell more than one at a time.'", keeper, NULL, ch, TO_VICT );
return;
}
if ( sn_haggle >= 0 && ch->level >= skill_table[sn_haggle]->skill_level[ch->Class] ) {
int change;
change = (cost/100) * (ch->pcdata->learned[sn_haggle]/10);
if ( number_percent() < ch->pcdata->learned[sn_haggle] ) {
learn_from_success(ch, sn_haggle);
set_char_color(AT_ACTION, ch);
send_to_char("After a bit of haggling, you manage to get the price lowered.\n", ch);
ch_printf(ch, "The original price was %d, you managed to lower it to %d.\n",
cost, cost - change);
cost -= change;
} else {
learn_from_failure(ch, sn_haggle);
set_char_color(AT_ACTION, ch);
send_to_char("The shopkeeper, angered by your attempt to manipulate him, raised the price.\n", ch);
ch_printf(ch, "The original price was %d, but the shopkeeper raised it to %d.\n",
cost, cost + change);
cost += change;
}
}
if ( ch->gold < cost )
{
act( AT_TELL, "$n tells you 'You can't afford to buy $p.'",
keeper, obj, ch, TO_VICT );
return;
}
#ifdef USE_OBJECT_LEVELS
if ( obj->level > ch->level )
{
act( AT_TELL, "$n tells you 'You can't use $p yet.'",
keeper, obj, ch, TO_VICT );
return;
}
#endif
if ( IS_SET(obj->extra_flags, ITEM_PROTOTYPE)
&& get_trust( ch ) < LEVEL_IMMORTAL )
{
act( AT_TELL, "$n tells you 'This is a only a prototype! I can't sell you that...'",
keeper, NULL, ch, TO_VICT );
return;
}
if ( ch->carry_number + get_obj_number( obj ) > can_carry_n( ch ) )
{
send_to_char( "You can't carry that many items.\n\r", ch );
return;
}
if ( ch->carry_weight + ( get_obj_weight( obj ) * noi )
+ (noi > 1 ? 2 : 0) > can_carry_w( ch ) )
{
send_to_char( "You can't carry that much weight.\n\r", ch );
return;
}
if ( noi == 1 )
{
separate_obj(obj);
act( AT_ACTION, "$n buys $p.", ch, obj, NULL, TO_ROOM );
act( AT_ACTION, "You buy $p.", ch, obj, NULL, TO_CHAR );
}
else
{
bool plural = obj->shortDesc_.c_str() [ obj->shortDesc_.length() - 1 ] == 's';
sprintf( arg, "$n buys %d $p%s.", noi,
( plural ? "" : "s" ) );
act( AT_ACTION, arg, ch, obj, NULL, TO_ROOM );
sprintf( arg, "You buy %d $p%s.", noi,
( plural ? "" : "s" ) );
act( AT_ACTION, arg, ch, obj, NULL, TO_CHAR );
act( AT_ACTION, "$N puts them into a bag and hands it to you.",
ch, NULL, keeper, TO_CHAR );
}
ch->gold -= cost;
keeper->gold += cost;
if ( keeper->gold > maxgold )
{
boost_economy( keeper->GetInRoom()->area, keeper->gold - maxgold/2 );
keeper->gold = maxgold/2;
act( AT_ACTION, "$n puts some gold into a large safe.", keeper, NULL, NULL, TO_ROOM );
}
if ( IS_OBJ_STAT( obj, ITEM_INVENTORY ) )
{
OBJ_DATA *buy_obj, *bag;
#ifdef USE_OBJECT_LEVELS
buy_obj = create_object( obj->pIndexData, obj->level );
#else
buy_obj = create_object(obj->pIndexData, 0);
#endif
REMOVE_BIT(buy_obj->extra_flags, ITEM_INVENTORY);
/*
* Due to grouped objects and carry limitations in SMAUG
* The shopkeeper gives you a bag with multiple-buy,
* and also, only one object needs be created with a count
* set to the number bought. -Thoric
*/
if ( noi > 1 )
{
bag = create_object( get_obj_index( OBJ_VNUM_SHOPPING_BAG ), 1 );
/* perfect size bag ;) */
bag->value[0] = bag->weight + (buy_obj->weight * noi);
buy_obj->count = noi;
obj->pIndexData->count += (noi - 1);
obj->pIndexData->total_count += (noi -1);
numobjsloaded += (noi - 1);
obj_to_obj( buy_obj, bag );
obj_to_char( bag, ch );
}
else
obj_to_char( buy_obj, ch );
}
else
{
obj_from_char( obj );
obj_to_char( obj, ch );
}
return;
}
}
void do_list(CHAR_DATA *ch, const char* argument)
{
if ( IS_SET(ch->GetInRoom()->room_flags, ROOM_PET_SHOP) )
{
ROOM_INDEX_DATA *pRoomIndexNext;
CHAR_DATA *pet;
bool found;
pRoomIndexNext = get_room_index( ch->GetInRoom()->vnum + 1 );
if ( !pRoomIndexNext )
{
bug( "Do_list: bad pet shop at vnum %s (no pet storage room at vnum+1).", vnum_to_dotted(ch->GetInRoom()->vnum));
send_to_char( "You can't do that here.\n\r", ch );
return;
}
found = FALSE;
for ( pet = pRoomIndexNext->first_person; pet; pet = pet->next_in_room )
{
if ( IS_SET(pet->act, ACT_PET) && IS_NPC(pet) )
{
if ( !found )
{
found = TRUE;
send_to_char( "Pets for sale:\n\r", ch );
}
ch_printf( ch, "[%2d] %8d - %s\n\r",
pet->level,
10 * pet->level * pet->level,
pet->getShort().c_str() );
}
}
if ( !found )
send_to_char( "Sorry, we're out of pets right now.\n\r", ch );
return;
}
else
{
char arg[MAX_INPUT_LENGTH];
CHAR_DATA *keeper;
OBJ_DATA *obj;
int cost, liquid;
bool found;
one_argument( argument, arg );
if ( ( keeper = find_keeper( ch ) ) == NULL )
{
send_to_char("You can't do that here.\n\r", ch);
return;
}
found = FALSE;
for ( obj = keeper->first_carrying; obj; obj = obj->next_content )
{
if ( obj->wear_loc == WEAR_NONE
&& can_see_obj( ch, obj )
&& ( cost = get_cost( ch, keeper, obj, TRUE ) ) > 0
&& ( arg[0] == '\0' || nifty_is_name( arg, obj->name_.c_str() ) ) )
{
if ( !found )
{
found = TRUE;
#ifdef USE_OBJECT_LEVELS
send_to_char( "[Lv Price] Item\n\r", ch );
#else
send_to_char("[Price] Item\n\r", ch);
#endif
}
#ifdef USE_OBJECT_LEVELS
ch_printf( ch, "[%2d %5d] %s.\n\r",
obj->level, cost, capitalize( obj->shortDesc_.c_str() ) );
#else
if( obj->item_type == ITEM_DRINK_CON )
{
if( ( liquid = obj->value[2] ) > LIQ_MAX )
liquid = 0;
if( obj->value[1] > 0 )
ch_printf( ch, "[%5d] %s (%s).\n\r", cost, capitalize(obj->shortDesc_.c_str()), liq_table[liquid].liq_name );
else
ch_printf( ch, "[%5d] %s (empty).\n\r", cost, capitalize(obj->shortDesc_.c_str()) );
}
else
ch_printf( ch, "[%5d] %s.\n\r", cost, capitalize(obj->shortDesc_.c_str()));
#endif
}
}
if ( !found )
{
if ( arg[0] == '\0' )
send_to_char( "You can't buy anything here.\n\r", ch );
else
send_to_char( "You can't buy that here.\n\r", ch );
}
return;
}
}
void do_sell(CHAR_DATA *ch, const char* argument)
{
char buf[MAX_STRING_LENGTH];
char arg[MAX_INPUT_LENGTH];
CHAR_DATA *keeper;
OBJ_DATA *obj;
int cost;
one_argument( argument, arg );
if ( arg[0] == '\0' )
{
send_to_char( "Sell what?\n\r", ch );
return;
}
if ( ( keeper = find_keeper( ch ) ) == NULL )
{
for (keeper = ch->GetInRoom()->first_person; keeper; keeper = keeper->next_in_room)
if (IS_NPC(keeper) && IS_SET(keeper->act, ACT_GEMDEALER) )
break;
}
if ( !keeper )
{
send_to_char("There is noone here to sell anything to.\n\r", ch);
return;
}
if ( ( obj = get_obj_carry( ch, arg ) ) == NULL )
{
act( AT_TELL, "$n tells you, 'You don't have that item.'", keeper, NULL, ch, TO_VICT );
return;
}
if ( !can_drop_obj( ch, obj ) )
{
send_to_char( "You can't let go of it!\n\r", ch );
return;
}
if ( obj->item_type == ITEM_GEM && IS_NPC(keeper) && IS_SET(keeper->act, ACT_GEMDEALER) )
{
int worth;
worth = GetGemWorth(obj);
separate_obj(obj);
act( AT_ACTION, "$n sells $p.", ch, obj, NULL, TO_ROOM );
sprintf( buf, "You sell $p for %d gold piece%s.", worth, worth == 1 ? "" : "s" );
act( AT_ACTION, buf, ch, obj, NULL, TO_CHAR);
extract_obj(obj, TRUE);
ch->gold += worth;
return;
}
if ( IS_SET(keeper->act, ACT_GEMDEALER) || obj->item_type == ITEM_GEM )
{
act( AT_PLAIN, "$n looks uninterested in $p.", keeper, obj, ch, TO_VICT);
return;
}
if ( obj->timer > 0 )
{
act( AT_TELL, "$n tells you, '$p is depreciating in value too quickly...'", keeper, obj, ch, TO_VICT );
return;
}
if ( ( cost = get_cost( ch, keeper, obj, FALSE ) ) <= 0 )
{
act( AT_ACTION, "$n looks uninterested in $p.", keeper, obj, ch, TO_VICT );
return;
}
if ( cost >= keeper->gold )
{
act( AT_TELL, "$n tells you, '$p is worth more than I can afford...'", keeper, obj, ch, TO_VICT );
return;
}
separate_obj( obj );
act( AT_ACTION, "$n sells $p.", ch, obj, NULL, TO_ROOM );
sprintf( buf, "You sell $p for %d gold piece%s.",
cost, cost == 1 ? "" : "s" );
act( AT_ACTION, buf, ch, obj, NULL, TO_CHAR );
ch->gold += cost;
keeper->gold -= cost;
if ( keeper->gold < 0 )
keeper->gold = 0;
if ( obj->item_type == ITEM_TRASH )
{
extract_obj( obj, TRUE );
}
else
{
obj_from_char( obj );
obj_to_char( obj, keeper );
}
return;
}
void do_value(CHAR_DATA *ch, const char* argument)
{
char buf[MAX_STRING_LENGTH];
CHAR_DATA *keeper;
OBJ_DATA *obj;
int cost;
if ( argument[0] == '\0' )
{
send_to_char( "Value what?\n\r", ch );
return;
}
if ( ( keeper = find_keeper( ch ) ) == NULL )
{
send_to_char("You can't do that here.\n\r", ch);
return;
}
if ( ( obj = get_obj_carry( ch, argument ) ) == NULL )
{
act( AT_TELL, "$n tells you 'You don't have that item.'",
keeper, NULL, ch, TO_VICT );
return;
}
if ( !can_drop_obj( ch, obj ) )
{
send_to_char( "You can't let go of it!\n\r", ch );
return;
}
if ( ( cost = get_cost( ch, keeper, obj, FALSE ) ) <= 0 )
{
act( AT_ACTION, "$n looks uninterested in $p.", keeper, obj, ch, TO_VICT );
return;
}
sprintf( buf, "$n tells you 'I'll give you %d gold coins for $p.'", cost );
act( AT_TELL, buf, keeper, obj, ch, TO_VICT );
return;
}
/*
* Repair a single object. Used when handling "repair all" - Gorog
*/
void repair_one_obj( CHAR_DATA *ch, CHAR_DATA *keeper, OBJ_DATA *obj,
const char *arg, int maxgold, const char *fixstr, const char*fixstr2 )
{
char buf[MAX_STRING_LENGTH];
int cost;
int sn_haggle = skill_lookup("haggle");
if ( !can_drop_obj( ch, obj ) )
{
ch_printf( ch, "You can't let go of %s.\n\r", obj->name_.c_str() );
return;
}
if ( obj->max_condition == 1 )
{
act( AT_TELL, "$n tells you, '$p is too weak to be repaired.'", keeper, obj, ch, TO_VICT);
return;
}
if ( ( cost = get_repaircost( keeper, obj ) ) < 0 )
{
if (cost != -2)
act( AT_TELL, "$n tells you, 'Sorry, I can't do anything with $p.'",
keeper, obj, ch, TO_VICT );
else
act( AT_TELL, "$n tells you, '$p looks fine to me!'", keeper, obj, ch, TO_VICT );
return;
}
/* "repair all" gets a 10% surcharge - Gorog */
if ( !strcmp("all", arg) ) {
cost = 11*cost/10;
}
if ( sn_haggle >= 0 && ch->level >= skill_table[sn_haggle]->skill_level[ch->Class] ) {
int change;
change = (cost/100) * (ch->pcdata->learned[sn_haggle]/10);
if ( number_percent() < ch->pcdata->learned[sn_haggle] ) {
learn_from_success(ch, sn_haggle);
set_char_color(AT_ACTION, ch);
send_to_char("After a bit of haggling, you manage to get the cost lowered.\n", ch);
ch_printf(ch, "The original cost was %d, you managed to lower it to %d.\n",
cost, cost - change);
cost -= change;
} else {
learn_from_failure(ch, sn_haggle);
set_char_color(AT_ACTION, ch);
send_to_char("The shopkeeper, angered by your attempt to manipulate him, raised the cost.\n", ch);
ch_printf(ch, "The original cost was %d, but the shopkeeper raised it to %d.\n",
cost, cost + change);
cost += change;
}
}
if ( cost > ch->gold )
{
sprintf( buf,
"$N tells you, 'It will cost %d piece%s of gold to %s %s...'", cost,
cost == 1 ? "" : "s", fixstr, obj->name_.c_str() );
act( AT_TELL, buf, ch, NULL, keeper, TO_CHAR );
act( AT_TELL, "$N tells you, 'Which I see you can't afford.'", ch,
NULL, keeper, TO_CHAR );
return;
}
sprintf( buf, "$n gives $p to $N, who quickly %s it.", fixstr2 );
act( AT_ACTION, buf, ch, obj, keeper, TO_ROOM );
sprintf( buf, "$N charges you %d gold piece%s to %s $p.",
cost, cost == 1 ? "" : "s", fixstr );
act( AT_ACTION, buf, ch, obj, keeper, TO_CHAR );
ch->gold -= cost;
keeper->gold += cost;
if ( keeper->gold < 0 )
keeper->gold = 0;
else
if ( keeper->gold > maxgold )
{
boost_economy( keeper->GetInRoom()->area, keeper->gold - maxgold/2 );
keeper->gold = maxgold/2;
act( AT_ACTION, "$n puts some gold into a large safe.", keeper,
NULL, NULL, TO_ROOM );
}
switch ( obj->item_type )
{
default:
send_to_char( "For some reason, you think you got ripped off...\n\r", ch);
break;
case ITEM_ARMOR:
case ITEM_WEAPON:
case ITEM_CONTAINER:
/* KSILYAN: new condition handling */
// don't reduce max_condition on a never-break item.
if ( !IS_SET(obj->extra_flags_2, ITEM_NEVER_BREAKS) )
obj->max_condition--;
obj->condition = obj->max_condition;
break;
case ITEM_WAND:
case ITEM_STAFF:
obj->value[OBJECT_WAND_CHARGES] = obj->value[OBJECT_WAND_MAXCHARGES];
break;
}
oprog_repair_trigger( ch, obj );
}
void do_repair(CHAR_DATA *ch, const char* argument)
{
CHAR_DATA *keeper;
OBJ_DATA *obj;
const char *fixstr;
const char *fixstr2;
int maxgold;
if ( argument[0] == '\0' )
{
send_to_char( "Repair what?\n\r", ch );
return;
}
if ( ( keeper = find_fixer( ch ) ) == NULL )
return;
maxgold = keeper->level * keeper->level * 100000;
switch( keeper->pIndexData->rShop->shop_type )
{
default:
case SHOP_FIX:
fixstr = "repair";
fixstr2 = "repairs";
break;
case SHOP_RECHARGE:
fixstr = "recharge";
fixstr2 = "recharges";
break;
}
if ( !strcmp( argument, "all" ) )
{
for ( obj = ch->first_carrying; obj ; obj = obj->next_content )
{
if ( obj->wear_loc == WEAR_NONE
&& can_see_obj( ch, obj )
&& ( obj->item_type == ITEM_ARMOR
|| obj->item_type == ITEM_WEAPON
|| obj->item_type == ITEM_CONTAINER
|| obj->item_type == ITEM_WAND