-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfight.cpp
executable file
·3995 lines (3481 loc) · 98.5 KB
/
fight.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. *
* ------------------------------------------------------------------------ *
* Battle & death module *
****************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "mud.h"
#include "connection.h"
#include "commands.h"
#include "World.h"
extern char lastplayercmd[MAX_INPUT_LENGTH];
extern CHAR_DATA * gch_prev;
extern CHAR_DATA * lastplayer;
/*test*/
/*
* Local functions.
*/
void parry_message (CHAR_DATA *ch, CHAR_DATA *victim, int dt, int dam_msg) ;
void dodge_message (CHAR_DATA *ch, CHAR_DATA *victim, int dt, int dam_msg) ;
void dam_message ( CHAR_DATA *ch, CHAR_DATA *victim, int dam,
int dt , int dam_msg);
void death_cry ( CHAR_DATA *ch ) ;
void group_gain ( CHAR_DATA *ch, CHAR_DATA *victim ) ;
int xp_compute ( CHAR_DATA *gch, CHAR_DATA *victim, int levelPenalty = 0 );
int align_compute ( CHAR_DATA *gch, CHAR_DATA *victim ) ;
ch_ret one_hit ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) ;
int obj_hitroll ( OBJ_DATA *obj ) ;
bool dual_flip = FALSE;
/* Ksilyan:
* A very cheat hack to make it work for now. I promise, this will
* be fixed at some point.
* The need here is to make shields NOT work when triggered by
* projectile_hit ... so we have to fool damage into thinking that
* shields are off (which it does to prevent endless shield recursions.
*/
static bool bNoShields = FALSE;
/*
* Check to see if weapon is poisoned.
*/
bool is_wielding_poisoned( CHAR_DATA *ch )
{
OBJ_DATA *obj;
if ( ( obj = get_eq_char( ch, WEAR_WIELD ) )
&& (IS_SET( obj->extra_flags, ITEM_POISONED) ) )
return TRUE;
return FALSE;
}
/*
* hunting, hating and fearing code -Thoric
*/
bool is_hunting( CHAR_DATA *ch, CHAR_DATA *victim )
{
if ( !ch->hunting || ch->hunting->who != victim )
return FALSE;
return TRUE;
}
bool is_hating( CHAR_DATA *ch, CHAR_DATA *victim )
{
if ( !ch->hating || ch->hating->who != victim )
return FALSE;
return TRUE;
}
bool is_fearing( CHAR_DATA *ch, CHAR_DATA *victim )
{
if ( !ch->fearing || ch->fearing->who != victim )
return FALSE;
return TRUE;
}
void stop_hunting( CHAR_DATA *ch )
{
if ( ch->hunting )
{
delete ch->hunting;
ch->hunting = NULL;
}
return;
}
void stop_hating( CHAR_DATA *ch )
{
if ( ch->hating )
{
delete ch->hating;
ch->hating = NULL;
}
return;
}
void stop_fearing( CHAR_DATA *ch )
{
if ( ch->fearing )
{
delete ch->fearing;
ch->fearing = NULL;
}
return;
}
void start_hunting( CHAR_DATA *ch, CHAR_DATA *victim )
{
if ( ch->hunting )
stop_hunting( ch );
ch->hunting = new HuntHateFear;
ch->hunting->name_ = victim->getName();
ch->hunting->who = victim;
return;
}
void start_hating( CHAR_DATA *ch, CHAR_DATA *victim )
{
if ( ch->hating )
stop_hating( ch );
ch->hating = new HuntHateFear;
ch->hating->name_ = victim->getName();
ch->hating->who = victim;
return;
}
void start_fearing( CHAR_DATA *ch, CHAR_DATA *victim )
{
if ( ch->fearing )
stop_fearing( ch );
ch->fearing = new HuntHateFear;
ch->fearing->name_ = victim->getName();
ch->fearing->who = victim;
return;
}
/*
* Get the current armor class for a vampire based on time of day
*/
sh_int VAMP_AC( const CHAR_DATA * ch )
{
if ( IS_VAMPIRE( ch ) || ch->isOutside() )
{
switch(weather_info.sunlight)
{
case SUN_DARK:
return -8;
case SUN_RISE:
return 5;
case SUN_LIGHT:
return 10;
case SUN_SET:
return 2;
default:
return 0;
}
}
else
return 0;
}
uint max_fight( CHAR_DATA *ch )
{
return 8;
}
/*
* Control the fights going on.
* Called periodically by update_handler.
* Many hours spent fixing bugs in here by Thoric, as noted by residual
* debugging checks. If you never get any of these error messages again
* in your logs... then you can comment out some of the checks without
* worry.
*/
void violence_update( void )
{
char buf[MAX_STRING_LENGTH];
CHAR_DATA *ch;
CHAR_DATA *lst_ch;
CHAR_DATA *victim;
CHAR_DATA *rch, *rch_next;
AFFECT_DATA *paf, *paf_next;
TIMER *timer, *timer_next;
ch_ret retcode;
int x, attacktype = 0, cnt;
SkillType *skill;
lst_ch = NULL;
for ( ch = last_char; ch; lst_ch = ch, ch = gch_prev )
{
set_cur_char( ch );
if ( ch == first_char && ch->prev )
{
bug( "ERROR: first_char->prev != NULL, fixing...", 0 );
ch->prev = NULL;
}
gch_prev = ch->prev;
if ( gch_prev && gch_prev->next != ch )
{
sprintf( buf, "FATAL: violence_update: %s->prev->next doesn't point to ch.",
ch->getName().c_str() );
bug( buf, 0 );
bug( "Short-cutting here", 0 );
ch->prev = NULL;
gch_prev = NULL;
do_shout( ch, "Tarin says, 'Prepare for the worst!'" );
}
/*
* See if we got a pointer to someone who recently died...
* if so, either the pointer is bad... or it's a player who
* "died", and is back at the healer...
* Since he/she's in the char_list, it's likely to be the latter...
* and should not already be in another fight already
*/
if ( char_died(ch) )
continue;
/*
* See if we got a pointer to some bad looking data...
*/
/* removed by Ksilyan - seems no longer relevant.
if ( !ch->GetInRoom() || !ch->name )
{
log_string( "violence_update: bad ch record! (Shortcutting.)" );
sprintf( buf, "ch: %d ch->GetInRoom(): %d ch->prev: %d ch->next: %d",
(int) ch, (int) ch->GetInRoom(), (int) ch->prev, (int) ch->next );
log_string( buf );
log_string( lastplayercmd );
if ( lst_ch )
sprintf( buf, "lst_ch: %d lst_ch->prev: %d lst_ch->next: %d",
(int) lst_ch, (int) lst_ch->prev, (int) lst_ch->next );
else
strcpy( buf, "lst_ch: NULL" );
log_string( buf );
gch_prev = NULL;
continue;
}
end of remove by Ksilyan*/
/*
* Experience gained during battle deceases as battle drags on
*/
// Removed by Ksilyan - it seems that fighting->duration is never set!
// Hmm... oh well.
#if 0
if ( ch->IsFighting() )
{
if ( (++ch->fighting->duration % 24) == 0 )
ch->fighting->xp = ((ch->fighting->xp * 9) / 10);
}
#endif
for ( timer = ch->first_timer; timer; timer = timer_next )
{
timer_next = timer->next;
if ( --timer->count <= 0 )
{
if ( timer->type == TIMER_DO_FUN )
{
int tempsub;
tempsub = ch->substate;
ch->substate = timer->value;
(timer->do_fun)( ch, "" );
if ( char_died(ch) )
break;
ch->substate = tempsub;
}
extract_timer( ch, timer );
}
}
if ( char_died(ch) )
continue;
/*
* We need spells that have shorter durations than an hour.
* So a melee round sounds good to me... -Thoric
*/
for ( paf = ch->first_affect; paf; paf = paf_next )
{
paf_next = paf->next;
if ( paf->duration > 0 )
{
paf->duration--;
}
else if ( paf->duration < 0 )
{
}
else
{
if ( !paf_next
|| paf_next->type != paf->type
|| paf_next->duration > 0 )
{
skill = get_skilltype(paf->type);
if ( paf->type > 0 && skill && skill->msgOff_.length() > 0 )
{
set_char_color( AT_WEAROFF, ch );
ch->sendText( skill->msgOff_.str() );
send_to_char( "\n\r", ch );
}
}
if (paf->type == gsn_possess)
{
ch->GetConnection()->CurrentCharId = ch->GetConnection()->OriginalCharId;
ch->GetConnection()->OriginalCharId = 0;
ch->GetConnection()->GetCharacter()->SwitchedCharId = 0;
ch->GetConnection()->GetCharacter()->SetConnection( ch->GetConnection() );
ch->SetConnection( NULL );
}
// We need to remove the spell memory from both people.
list<SpellMemory*>::iterator itor;
// Create a local copy of the list to loop through.
list<SpellMemory*> localList = ch->spellMemory_;
for (itor = localList.begin(); itor != localList.end(); itor++)
{
SpellMemory * spell = *itor;
if (spell->Spell == paf)
{
spell->Target->spellMemory_.remove(spell);
spell->Caster->spellMemory_.remove(spell);
break;
}
}
affect_remove( ch, paf );
}
}
// check for victim, and paralysis, to handle fight code
if ( ( victim = ch->GetVictim() ) == NULL
|| IS_AFFECTED( ch, AFF_PARALYSIS ) )
continue;
// Start fight code
retcode = rNONE;
if ( IS_SET(ch->GetInRoom()->room_flags, ROOM_SAFE ) )
{
sprintf( buf, "violence_update: %s fighting %s in a SAFE room.",
ch->getName().c_str(), victim->getName().c_str() );
log_string( buf );
//stop_fighting( ch, TRUE );
ch->StopAttacking();
}
else if ( IS_AWAKE(ch) && ch->GetInRoom() == victim->GetInRoom() )
retcode = multi_hit( ch, victim, TYPE_UNDEFINED );
else
ch->StopAttacking();//stop_fighting( ch, FALSE );
if ( char_died(ch) )
continue;
if ( retcode == rCHAR_DIED
|| ( victim = ch->GetVictim() ) == NULL )
continue;
/*
* Mob triggers
*/
rprog_rfight_trigger( ch );
if ( char_died(ch) )
continue;
mprog_hitprcnt_trigger( ch, victim );
if ( char_died(ch) )
continue;
mprog_fight_trigger( ch, victim );
if ( char_died(ch) )
continue;
/*
* NPC special attack flags -Thoric
*/
if ( IS_NPC(ch) )
{
cnt = 0;
if ( ch->attacks )
{
for ( ;; )
{
if ( cnt++ > 10 )
{
attacktype = 0;
break;
}
x = number_range( 7, 31 );
attacktype = 1 << x;
if ( IS_SET( ch->attacks, attacktype ) )
break;
}
}
if ( 30 + (ch->level/4) < number_percent( ) )
attacktype = 0;
switch( attacktype )
{
case ATCK_BASH:
do_bash( ch, "" );
retcode = global_retcode;
break;
case ATCK_STUN:
do_stun( ch, "" );
retcode = global_retcode;
break;
case ATCK_GOUGE:
do_gouge( ch, "" );
retcode = global_retcode;
break;
case ATCK_FEED:
do_gouge( ch, "" );
retcode = global_retcode;
break;
case ATCK_DRAIN:
retcode = spell_energy_drain( skill_lookup( "energy drain" ), ch->level, ch, victim );
break;
case ATCK_FIREBREATH:
retcode = spell_fire_breath( skill_lookup( "fire breath" ), ch->level, ch, victim );
break;
case ATCK_FROSTBREATH:
retcode = spell_frost_breath( skill_lookup( "frost breath" ), ch->level, ch, victim );
break;
case ATCK_ACIDBREATH:
retcode = spell_acid_breath( skill_lookup( "acid breath" ), ch->level, ch, victim );
break;
case ATCK_LIGHTNBREATH:
retcode = spell_lightning_breath( skill_lookup( "lightning breath" ), ch->level, ch, victim );
break;
case ATCK_GASBREATH:
retcode = spell_gas_breath( skill_lookup( "gas breath" ), ch->level, ch, victim );
break;
case ATCK_SPIRALBLAST:
retcode = spell_spiral_blast( skill_lookup( "spiral blast" ),
ch->level, ch, victim );
break;
case ATCK_POISON:
retcode = spell_poison( gsn_poison, ch->level, ch, victim );
break;
case ATCK_NASTYPOISON:
/*
retcode = spell_nasty_poison( skill_lookup( "nasty poison" ), ch->level, ch, victim );
*/
break;
case ATCK_GAZE:
/*
retcode = spell_gaze( skill_lookup( "gaze" ), ch->level, ch, victim );
*/
break;
case ATCK_BLINDNESS:
retcode = spell_blindness( gsn_blindness, ch->level, ch, victim );
break;
case ATCK_CAUSESERIOUS:
retcode = spell_cause_serious( skill_lookup( "cause serious" ), ch->level, ch, victim );
break;
case ATCK_EARTHQUAKE:
retcode = spell_earthquake( skill_lookup( "earthquake" ), ch->level, ch, victim );
break;
case ATCK_CAUSECRITICAL:
retcode = spell_cause_critical( skill_lookup( "cause critical" ), ch->level, ch, victim );
break;
case ATCK_CURSE:
retcode = spell_curse( skill_lookup( "curse" ), ch->level, ch, victim );
break;
case ATCK_FLAMESTRIKE:
retcode = spell_flamestrike( skill_lookup( "flamestrike" ), ch->level, ch, victim );
break;
case ATCK_HARM:
retcode = spell_harm( skill_lookup( "harm" ), ch->level, ch, victim );
break;
case ATCK_FIREBALL:
retcode = spell_fireball( skill_lookup( "fireball" ), ch->level, ch, victim );
break;
case ATCK_COLORSPRAY:
retcode = spell_colour_spray( skill_lookup( "colour spray" ), ch->level, ch, victim );
break;
case ATCK_WEAKEN:
retcode = spell_weaken( skill_lookup( "weaken" ), ch->level, ch, victim );
break;
}
if ( retcode == rCHAR_DIED || (char_died(ch)) )
continue;
/*
* NPC special defense flags -Thoric
*/
cnt = 0;
if ( ch->defenses )
{
for ( ;; )
{
if ( cnt++ > 10 )
{
attacktype = 0;
break;
}
x = number_range( 2, 18 );
attacktype = 1 << x;
if ( IS_SET( ch->defenses, attacktype ) )
break;
}
}
if ( 50 + (ch->level/4) < number_percent( ) )
attacktype = 0;
switch( attacktype )
{
case DFND_CURELIGHT:
act( AT_MAGIC, "$n mutters a few incantations...and looks a little better.", ch, NULL, NULL, TO_ROOM );
retcode = spell_smaug( skill_lookup( "cure light" ), ch->level, ch, ch );
break;
case DFND_CURESERIOUS:
act( AT_MAGIC, "$n mutters a few incantations...and looks a bit better.", ch, NULL, NULL, TO_ROOM );
retcode = spell_smaug( skill_lookup( "cure serious" ), ch->level, ch, ch );
break;
case DFND_CURECRITICAL:
act( AT_MAGIC, "$n mutters a few incantations...and looks a bit healthier.", ch, NULL, NULL, TO_ROOM );
retcode = spell_smaug( skill_lookup( "cure critical" ), ch->level, ch, ch );
break;
case DFND_DISPELMAGIC:
act( AT_MAGIC, "$n mutters a few incantations...and waves $s arms about.", ch, NULL, NULL, TO_ROOM );
retcode = spell_dispel_magic( skill_lookup( "dispel magic" ), ch->level, ch, victim );
break;
case DFND_DISPELEVIL:
act( AT_MAGIC, "$n mutters a few incantations...and waves $s arms about.", ch, NULL, NULL, TO_ROOM );
retcode = spell_dispel_evil( skill_lookup( "dispel evil" ), ch->level, ch, victim );
break;
case DFND_SANCTUARY:
if ( !IS_AFFECTED(victim, AFF_SANCTUARY) )
{
act( AT_MAGIC, "$n mutters a few incantations...", ch, NULL, NULL, TO_ROOM );
retcode = spell_smaug( skill_lookup( "sanctuary" ), ch->level, ch, ch );
}
else
retcode = rNONE;
break;
}
if ( retcode == rCHAR_DIED || (char_died(ch)) )
continue;
}
/*
* Fun for the whole family!
*/
for ( rch = ch->GetInRoom()->first_person; rch; rch = rch_next )
{
rch_next = rch->next_in_room;
if ( IS_AWAKE(rch) && !rch->IsAttacking() )
{
/*
* PC's auto-assist others in their group.
*/
if ( !IS_NPC(ch) || IS_AFFECTED(ch, AFF_CHARM) )
{
if ( ( !IS_NPC(rch) || IS_AFFECTED(rch, AFF_CHARM) )
&& is_same_group(ch, rch) )
multi_hit( rch, victim, TYPE_UNDEFINED );
continue;
}
// NPCs will defend their master, if they are guardians
// This also works if they are mounted...
// -Ksilyan
if ( IS_NPC(rch) && IS_SET(rch->act, ACT_GUARDIAN) )
{
gTheWorld->LogCodeString(string(rch->getName().c_str()) + " is a guardian!");
if ( rch->MasterId == ch->GetId() // ch is rch's master
|| ch->MountId == rch->GetId() ) // rch is ch's mount
{
multi_hit( rch, victim, TYPE_UNDEFINED );
continue;
}
}
/*
* NPC's assist NPC's of same type or 12.5% chance regardless.
*/
if ( IS_NPC(rch) && !IS_AFFECTED(rch, AFF_CHARM)
&& !IS_SET(rch->act, ACT_NOASSIST) )
{
if ( char_died(ch) )
break;
if ( rch->pIndexData == ch->pIndexData
|| number_bits( 3 ) == 0 )
{
CHAR_DATA *vch;
CHAR_DATA *target;
int number;
target = NULL;
number = 0;
for ( vch = ch->GetInRoom()->first_person; vch; vch = vch->next )
{
if ( can_see( rch, vch )
&& is_same_group( vch, victim )
&& number_range( 0, number ) == 0 )
{
target = vch;
number++;
}
}
if ( target )
multi_hit( rch, target, TYPE_UNDEFINED );
}
}
}
}
}
return;
}
/*
* Do one group of attacks.
*/
ch_ret multi_hit( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
int chance;
int dual_bonus;
ch_ret retcode;
/* add timer if player is attacking another player */
if ( !IS_NPC(ch) && !IS_NPC(victim) )
add_timer( ch, TIMER_RECENTFIGHT, 20, NULL, 0 );
if ( !IS_NPC(ch) && IS_SET( ch->act, PLR_NICE ) && !IS_NPC( victim ) && !in_arena(ch) )
return rNONE;
if( !IS_NPC(ch) && !IS_NPC(victim) && !in_arena(ch) && lastplayer )
{
if(ch->getName().c_str() != lastplayer->getName().c_str()
&& ch->GetVictim() != victim
&& lastplayer->getName().c_str()==victim->getName().c_str())
{
char buf[MAX_STRING_LENGTH];
sprintf(buf,"PK: %s provoked by %s's %s.\n\r"
,ch->getName().c_str(),lastplayer->getName().c_str(),lastplayercmd);
to_channel(buf,CHANNEL_MONITOR,"Monitor",0);
}
}
retcode = one_hit(ch, victim, dt);
if ( (retcode != rNONE) && (retcode != rAVOIDED) )
return retcode;
if ( ch->GetVictim() != victim || dt == gsn_backstab || dt == gsn_circle)
return rNONE;
/* Very high chance of hitting compared to chance of going berserk */
/* 40% or higher is always hit.. don't learn anything here though. */
/* -- Altrag */
chance = IS_NPC(ch) ? 100 : (ch->pcdata->learned[gsn_berserk]*5/2);
if ( IS_AFFECTED(ch, AFF_BERSERK) && number_percent() < chance )
{
if ( (retcode = one_hit( ch, victim, dt )) != rNONE || ch->GetVictim() != victim )
return retcode;
}
if ( get_eq_char( ch, WEAR_DUAL_WIELD ) )
{
dual_bonus = IS_NPC(ch) ? (ch->level / 10) : (ch->pcdata->learned[gsn_dual_wield] / 10);
chance = IS_NPC(ch) ? ch->level : ch->pcdata->learned[gsn_dual_wield];
if ( number_percent( ) < chance )
{
learn_from_success( ch, gsn_dual_wield );
retcode = one_hit( ch, victim, dt );
if ( ( (retcode != rNONE) && (retcode != rAVOIDED) ) || ( ch->GetVictim() != victim ) )
return retcode;
}
else
{
learn_from_failure( ch, gsn_dual_wield );
}
}
else
dual_bonus = 0;
if ( ch->move < 10 )
dual_bonus = -20;
/*
* NPC predetermined number of attacks -Thoric
*/
if ( IS_NPC(ch) && ch->numattacks > 0 )
{
for ( chance = 0; chance <= ch->numattacks; chance++ )
{
retcode = one_hit( ch, victim, dt );
if ( ( (retcode != rNONE) && (retcode != rAVOIDED) ) || ( ch->GetVictim() != victim ) )
return retcode;
}
return retcode;
}
{
chance = IS_NPC(ch) ? ch->level
: (int) ((ch->pcdata->learned[gsn_second_attack]+dual_bonus)/1.5);
if ( number_percent( ) < chance )
{
learn_from_success( ch, gsn_second_attack );
retcode = one_hit( ch, victim, dt );
if ( ( (retcode != rNONE) && (retcode != rAVOIDED) ) || ( ch->GetVictim() != victim ) )
return retcode;
}
else {
learn_from_failure( ch, gsn_second_attack );
}
chance = IS_NPC(ch) ? ch->level
: (int) ((ch->pcdata->learned[gsn_third_attack]+(dual_bonus*1.5))/2);
if ( number_percent( ) < chance )
{
learn_from_success( ch, gsn_third_attack );
retcode = one_hit( ch, victim, dt );
if ( ( (retcode != rNONE) && (retcode != rAVOIDED) ) || ( ch->GetVictim() != victim ) )
return retcode;
}
else
{
learn_from_failure( ch, gsn_third_attack );
}
chance = IS_NPC(ch) ? ch->level
: (int) ((ch->pcdata->learned[gsn_fourth_attack]+(dual_bonus*2))/3);
if ( number_percent( ) < chance )
{
learn_from_success( ch, gsn_fourth_attack );
retcode = one_hit( ch, victim, dt );
if ( ( (retcode != rNONE) && (retcode != rAVOIDED) ) || ( ch->GetVictim() != victim ) )
return retcode;
}
else
{
learn_from_failure( ch, gsn_fourth_attack );
}
chance = IS_NPC(ch) ? ch->level
: (int) ((ch->pcdata->learned[gsn_fifth_attack]+(dual_bonus*3))/4);
if ( number_percent( ) < chance )
{
learn_from_success( ch, gsn_fifth_attack );
retcode = one_hit( ch, victim, dt );
if ( ( (retcode != rNONE) && (retcode != rAVOIDED) ) || ( ch->GetVictim() != victim ) )
return retcode;
}
else
{
learn_from_failure( ch, gsn_fifth_attack );
}
retcode = rNONE;
chance = IS_NPC(ch) ? (int) ((ch->level+dual_bonus) / 2) : 0;
if ( number_percent( ) < chance ) {
retcode = one_hit( ch, victim, dt );
} else {
}
if ( retcode == rNONE )
{
int move;
if ( !IS_AFFECTED(ch, AFF_FLYING)
&& !IS_AFFECTED(ch, AFF_FLOATING) )
{
if ( !ch->GetInRoom() )
{
ostringstream os;
os << __FILE__ << "::" << __LINE__ << ":: null in_room!" << endl;
gTheWorld->LogString( os.str() );
return rNONE;
}
move = encumbrance( ch, movement_loss[UMIN(SECT_MAX-1, ch->GetInRoom()->sector_type)] );
}
else
move = encumbrance( ch, 1 );
if ( ch->move )
ch->move = UMAX( 0, ch->move - move );
}
}
return retcode;
}
/*
* Weapon types, haus
*/
/* move check for weapon type out of weapon_prof_bonus_check */
int get_weapon_prof_gsn(int weapon_type) {
char buf[MAX_INPUT_LENGTH];
switch(weapon_type)
{
default:
sprintf(buf, "Unknown weapon type: %d . Object vnum unavailable.", weapon_type);
bug(buf);
return -1;
break;
case WEAPON_NONE:
sprintf(buf, "Unknown weapon type: %d . Object vnum unavailable.", weapon_type);
bug(buf);
return -1;
break;
case WEAPON_PUGILISM:
return gsn_pugilism;
case WEAPON_LONGBLADE:
return gsn_long_blades;
case WEAPON_SHORTBLADE:
return gsn_short_blades;
case WEAPON_FLEXIBLE:
return gsn_flexible_arms;
case WEAPON_BLUDGEON:
return gsn_bludgeons;
case WEAPON_POLEARM:
return gsn_polearms;
case WEAPON_LONGBOW:
return gsn_long_bows;
case WEAPON_SHORTBOW:
return gsn_short_bows;
case WEAPON_CROSSBOW:
return gsn_cross_bows;
case WEAPON_SLING:
return gsn_slings;
case WEAPON_THROWINGSPEAR:
return gsn_throwing_spears;
case WEAPON_THROWINGKNIFE:
return gsn_throwing_daggers;
}
}
int weapon_prof_bonus_check( CHAR_DATA *ch, OBJ_DATA *wield, int *gsn_ptr )
{
int bonus;
bonus = 0; *gsn_ptr = -1;
if ( !IS_NPC(ch) && ch->level > 5 && wield )
{
*gsn_ptr = get_weapon_prof_gsn(wield->value[OBJECT_WEAPON_WEAPONTYPE]);
if ( *gsn_ptr != -1 )
bonus = (int) ((ch->pcdata->learned[*gsn_ptr] -50)/10);
/* Reduce weapon bonuses for misaligned clannies.
if ( IS_CLANNED(ch) )
{
bonus = bonus /
( 1 + abs( ch->alignment - ch->pcdata->clan->alignment ) / 1000 );
}*/
if ( IS_DEVOTED( ch ) )
{
bonus = bonus - abs( ch->pcdata->favor ) / -100 ;
}
}
return bonus;
}
/*
* Calculate the tohit bonus on the object and return RIS values.
* -- Altrag
*/
int obj_hitroll( OBJ_DATA *obj )
{
int tohit = 0;
AFFECT_DATA *paf;
for ( paf = obj->pIndexData->first_affect; paf; paf = paf->next )
if ( paf->location == APPLY_HITROLL )
tohit += paf->modifier;
for ( paf = obj->first_affect; paf; paf = paf->next )
if ( paf->location == APPLY_HITROLL )
tohit += paf->modifier;
return tohit;
}
/*
* Offensive shield level modifier
*/
sh_int off_shld_lvl( CHAR_DATA *ch, CHAR_DATA *victim )
{
sh_int lvl;
if ( !IS_NPC(ch) ) /* players get much less effect */
{
lvl = UMAX( 1, (ch->level - 10) / 2 );
if ( number_percent() + (victim->level - lvl) < 35 )
return lvl;
else
return 0;
}
else
{
lvl = ch->level / 2;
if ( number_percent() + (victim->level - lvl) < 70 )
return lvl;
else
return 0;
}
}
/*
* KSILYAN
* Meelee hit.
* Attempt to whack a target, see if we hit or not.
* True if hit, false if missed.
*
* The code is based on the old one_hit code.
* At some point, the hit-miss determining will be
* altogether removed from one_hit, and this function
* will be checked before one_hit is called.
*/
bool MeeleeHit( CHAR_DATA * ch, CHAR_DATA * victim, OBJ_DATA * Wielded, short HitBonus )
{
int victim_ac;
int thac0;
int thac0_00;
int thac0_32;
int temp_hr;
int diceroll;
int prof_bonus;
int prof_gsn;
/*
* Can't beat a dead char!
* Guard against weird room-leavings.
*/
if ( victim->position == POS_DEAD || ch->GetInRoom() != victim->GetInRoom() )
{
return false;
}
if ( Wielded && IS_RANGED_WEAPON_OBJ(Wielded) )
{
/* Can't whack someone with your bow! */
Wielded = NULL;
}
prof_bonus = weapon_prof_bonus_check( ch, Wielded, &prof_gsn );
/*
* Calculate to-hit-armor-class-0 versus armor.
*/
if ( IS_NPC(ch) )
{
thac0_00 = ch->mobthac0;
thac0_32 = 0;
}
else
{
thac0_00 = class_table[ch->Class]->thac0_00;
thac0_32 = class_table[ch->Class]->thac0_32;
}