📄 fight.c
字号:
/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "merc.h"
/*
* Local functions.
*/
bool check_dodge args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void check_killer args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
bool check_parry args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void dam_message args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dam,
int dt ) );
void death_cry args( ( CHAR_DATA *ch ) );
void group_gain args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
int xp_compute args( ( CHAR_DATA *gch, CHAR_DATA *victim ) );
bool is_safe args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void make_corpse args( ( CHAR_DATA *ch ) );
void one_hit args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
void raw_kill args( ( CHAR_DATA *victim ) );
void set_fighting args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void disarm args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void trip args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
/*
* Control the fights going on.
* Called periodically by update_handler.
*/
void violence_update( void )
{
CHAR_DATA *ch;
// CHAR_DATA *ch_next;
CHAR_DATA *victim;
CHAR_DATA *rch;
CHAR_DATA *rch_next;
for ( ch = char_list; ch != NULL; ch = ch->next )
{
// ch_next = ch->next;
if ( ( victim = ch->fighting ) == NULL || ch->in_room == NULL )
continue;
if ( IS_AWAKE(ch) && ch->in_room == victim->in_room )
multi_hit( ch, victim, TYPE_UNDEFINED );
else
stop_fighting( ch, FALSE );
if ( ( victim = ch->fighting ) == NULL )
continue;
mprog_hitprcnt_trigger( ch, victim );
mprog_fight_trigger( ch, victim );
/*
* Fun for the whole family!
*/
for ( rch = ch->in_room->people; rch != NULL; rch = rch_next )
{
rch_next = rch->next_in_room;
if ( IS_AWAKE(rch) && rch->fighting == NULL )
{
/*
* 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;
}
/*
* NPC's assist NPC's of same type or 12.5% chance regardless.
*/
if ( IS_NPC(rch) && !IS_AFFECTED(rch, AFF_CHARM) )
{
if ( rch->pIndexData == ch->pIndexData
|| number_bits( 3 ) == 0 )
{
CHAR_DATA *vch;
CHAR_DATA *target;
int number;
target = NULL;
number = 0;
for ( vch = ch->in_room->people; vch; vch = vch->next )
{
if ( can_see( rch, vch )
&& is_same_group( vch, victim )
&& number_range( 0, number ) == 0 )
{
target = vch;
number++;
}
}
if ( target != NULL )
{
if ( ( ( ( target->level - rch->level <= 4 )
&& ( target->level - rch->level >= -4 ) )
&& !( IS_GOOD ( rch ) && IS_GOOD ( target ) ) )
|| ( IS_EVIL ( rch ) || IS_EVIL ( target ) ) )
multi_hit( rch, target, TYPE_UNDEFINED );
}
}
}
}
}
}
return;
}
/*
* Do one group of attacks.
*/
void multi_hit( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
int chance;
one_hit( ch, victim, dt );
if ( ch->fighting != victim || dt == gsn_backstab )
return;
chance = IS_NPC(ch) ? ch->level : ch->pcdata->learned[gsn_second_attack]/2;
if ( number_percent( ) < chance )
{
one_hit( ch, victim, dt );
if ( ch->fighting != victim )
return;
}
chance = IS_NPC(ch) ? ch->level : ch->pcdata->learned[gsn_third_attack]/4;
if ( number_percent( ) < chance )
{
one_hit( ch, victim, dt );
if ( ch->fighting != victim )
return;
}
chance = IS_NPC(ch) ? ch->level / 2 : 0;
if ( number_percent( ) < chance )
one_hit( ch, victim, dt );
return;
}
/*
* Hit one guy once.
*/
void one_hit( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
OBJ_DATA *wield;
int victim_ac;
int thac0;
int thac0_00;
int thac0_32;
int dam;
int diceroll;
/*
* Can't beat a dead char!
* Guard against weird room-leavings.
*/
if ( victim->position == POS_DEAD || ch->in_room != victim->in_room )
return;
/*
* Figure out the type of damage message.
*/
wield = get_eq_char( ch, WEAR_WIELD );
if ( dt == TYPE_UNDEFINED )
{
dt = TYPE_HIT;
if ( wield != NULL && wield->item_type == ITEM_WEAPON )
dt += wield->value[3];
}
/*
* Calculate to-hit-armor-class-0 versus armor.
*/
if ( IS_NPC(ch) )
{
thac0_00 = 20;
thac0_32 = 0;
}
else
{
thac0_00 = class_table[ch->class].thac0_00;
thac0_32 = class_table[ch->class].thac0_32;
}
thac0 = interpolate( ch->level, thac0_00, thac0_32 ) - GET_HITROLL(ch);
victim_ac = UMAX( -15, GET_AC(victim) / 10 );
if ( !can_see( ch, victim ) )
victim_ac -= 4;
/*
* The moment of excitement!
*/
while ( ( diceroll = number_bits( 5 ) ) >= 20 )
;
if ( diceroll == 0
|| ( diceroll != 19 && diceroll < thac0 - victim_ac ) )
{
/* Miss. */
damage( ch, victim, 0, dt );
tail_chain( );
return;
}
/*
* Hit.
* Calc damage.
*/
if ( IS_NPC(ch) )
{
dam = number_range( ch->level / 2, ch->level * 3 / 2 );
if ( wield != NULL )
dam += dam / 2;
}
else
{
if ( wield != NULL )
dam = number_range( wield->value[1], wield->value[2] );
else
dam = number_range( 1, 4 );
}
/*
* Bonuses.
*/
dam += GET_DAMROLL(ch);
if ( !IS_NPC(ch) && ch->pcdata->learned[gsn_enhanced_damage] > 0 )
dam += dam * ch->pcdata->learned[gsn_enhanced_damage] / 150;
if ( !IS_AWAKE(victim) )
dam *= 2;
if ( dt == gsn_backstab )
dam *= 2 + ch->level / 8;
if ( dam <= 0 )
dam = 1;
damage( ch, victim, dam, dt );
tail_chain( );
return;
}
/*
* Inflict damage from a hit.
*/
void damage( CHAR_DATA *ch, CHAR_DATA *victim, int dam, int dt )
{
if ( victim->position == POS_DEAD )
return;
/*
* Stop up any residual loopholes.
*/
if ( dam > 1000 )
{
bug( "Damage: %d: more than 1000 points!", dam );
dam = 1000;
}
if ( victim != ch )
{
/*
* Certain attacks are forbidden.
* Most other attacks are returned.
*/
if ( is_safe( ch, victim ) )
return;
check_killer( ch, victim );
if ( victim->position > POS_STUNNED )
{
if ( victim->fighting == NULL )
set_fighting( victim, ch );
victim->position = POS_FIGHTING;
}
if ( victim->position > POS_STUNNED )
{
if ( ch->fighting == NULL )
set_fighting( ch, victim );
/*
* If victim is charmed, ch might attack victim's master.
*/
if ( IS_NPC(ch)
&& IS_NPC(victim)
&& IS_AFFECTED(victim, AFF_CHARM)
&& victim->master != NULL
&& victim->master->in_room == ch->in_room
&& number_bits( 3 ) == 0 )
{
stop_fighting( ch, FALSE );
multi_hit( ch, victim->master, TYPE_UNDEFINED );
return;
}
}
/*
* More charm stuff.
*/
if ( victim->master == ch )
stop_follower( victim );
/*
* Inviso attacks ... not.
*/
if ( IS_AFFECTED(ch, AFF_INVISIBLE) )
{
affect_strip( ch, gsn_invis );
affect_strip( ch, gsn_mass_invis );
REMOVE_BIT( ch->affected_by, AFF_INVISIBLE );
act( "$n fades into existence.", ch, NULL, NULL, TO_ROOM );
}
/*
* Damage modifiers.
*/
if ( IS_AFFECTED(victim, AFF_SANCTUARY) )
dam /= 2;
if ( IS_AFFECTED(victim, AFF_PROTECT) && IS_EVIL(ch) )
dam -= dam / 4;
if ( dam < 0 )
dam = 0;
/*
* Check for disarm, trip, parry, and dodge.
*/
if ( dt >= TYPE_HIT )
{
if ( IS_NPC(ch) && number_percent( ) < ch->level / 2 )
disarm( ch, victim );
if ( IS_NPC(ch) && number_percent( ) < ch->level / 2 )
trip( ch, victim );
if ( check_parry( ch, victim ) )
return;
if ( check_dodge( ch, victim ) )
return;
}
dam_message( ch, victim, dam, dt );
}
/*
* Hurt the victim.
* Inform the victim of his new state.
*/
victim->hit -= dam;
if ( !IS_NPC(victim)
&& victim->level >= LEVEL_IMMORTAL
&& victim->hit < 1 )
victim->hit = 1;
update_pos( victim );
switch( victim->position )
{
case POS_MORTAL:
act( "$n is mortally wounded, and will die soon, if not aided.",
victim, NULL, NULL, TO_ROOM );
send_to_char(
"You are mortally wounded, and will die soon, if not aided.\n\r",
victim );
break;
case POS_INCAP:
act( "$n is incapacitated and will slowly die, if not aided.",
victim, NULL, NULL, TO_ROOM );
send_to_char(
"You are incapacitated and will slowly die, if not aided.\n\r",
victim );
break;
case POS_STUNNED:
act( "$n is stunned, but will probably recover.",
victim, NULL, NULL, TO_ROOM );
send_to_char("You are stunned, but will probably recover.\n\r",
victim );
break;
case POS_DEAD:
act( "$n is DEAD!!", victim, 0, 0, TO_ROOM );
send_to_char( "You have been KILLED!!\n\r\n\r", victim );
break;
default:
if ( dam > victim->max_hit / 4 )
send_to_char( "That really did HURT!\n\r", victim );
if ( victim->hit < victim->max_hit / 4 )
send_to_char( "You sure are BLEEDING!\n\r", victim );
break;
}
/*
* Sleep spells and extremely wounded folks.
*/
if ( !IS_AWAKE(victim) )
stop_fighting( victim, FALSE );
/*
* Payoff for killing things.
*/
if ( victim->position == POS_DEAD )
{
group_gain( ch, victim );
if ( !IS_NPC(victim) )
{
sprintf( log_buf, "%s killed by %s at %d",
victim->name,
(IS_NPC(ch) ? ch->short_descr : ch->name),
victim->in_room->vnum );
log_string( log_buf );
/*
* Dying penalty:
* 1/2 way back to previous level.
*/
if ( victim->exp > 1000 * victim->level )
gain_exp( victim, (1000 * victim->level - victim->exp)/2 );
}
raw_kill( victim );
if ( !IS_NPC(ch) && IS_NPC(victim) )
{
if ( IS_SET(ch->act, PLR_AUTOLOOT) )
do_get( ch, "all corpse" );
else
do_look( ch, "in corpse" );
if ( IS_SET(ch->act, PLR_AUTOSAC) )
do_sacrifice( ch, "corpse" );
}
return;
}
if ( victim == ch )
return;
/*
* Take care of link dead people.
*/
if ( !IS_NPC(victim) && victim->desc == NULL )
{
if ( number_range( 0, victim->wait ) == 0 )
{
do_recall( victim, "" );
return;
}
}
/*
* Wimp out?
*/
if ( IS_NPC(victim) && dam > 0 )
{
if ( ( IS_SET(victim->act, ACT_WIMPY) && number_bits( 1 ) == 0
&& victim->hit < victim->max_hit / 2 )
|| ( IS_AFFECTED(victim, AFF_CHARM) && victim->master != NULL
&& victim->master->in_room != victim->in_room ) )
do_flee( victim, "" );
}
if ( !IS_NPC(victim)
&& victim->hit > 0
&& victim->hit <= victim->wimpy
&& victim->wait == 0 )
do_flee( victim, "" );
tail_chain( );
return;
}
bool is_safe( CHAR_DATA *ch, CHAR_DATA *victim )
{
if ( IS_NPC(ch) || IS_NPC(victim) )
return FALSE;
if ( get_age( ch ) < 21 )
{
send_to_char( "You aren't old enough.\n\r", ch );
return TRUE;
}
if ( IS_SET( victim->act, PLR_KILLER ) )
return FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -