fight.c

kbk/kbk3/src/fight.c · 339.9 KB

From the archive Inahn.zip

Download the archive   « Back to the archive contents

/***************************************************************************
 *  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.                                                  *
 ***************************************************************************/

/***************************************************************************
*       ROM 2.4 is copyright 1993-1996 Russ Taylor                         *
*       ROM has been brought to you by the ROM consortium                  *
*           Russ Taylor (rtaylor@pacinfo.com)                              *
*           Gabrielle Taylor (gtaylor@pacinfo.com)                         *
*           Brian Moore (rom@rom.efn.org)                                  *
*       By using this code, you have agreed to follow the terms of the     *
*       ROM license, in the file Tartarus/doc/rom.license                  *
***************************************************************************/

/***************************************************************************
*       Tartarus code is copyright (C) 1997-1998 by Daniel Graham          *
*	In using this code you agree to comply with the Tartarus license   *
*       found in the file /Tartarus/doc/tartarus.doc                       *
***************************************************************************/

/***************************************************************************
*       POSmud code is copyright (C) 1999-2000 and for exclusive use of    *
*	POSmud only. Hah!                                                  *
***************************************************************************/

#include "include.h"

#define HITS (dt==gsn_kick||dt==gsn_lunge||dt==gsn_downstrike||dt==gsn_throw||dt==gsn_crush||dt==gsn_bash)


/* command procedures needed */
DECLARE_DO_FUN(do_quit);
DECLARE_DO_FUN(do_say);
DECLARE_DO_FUN(do_backstab      );
DECLARE_DO_FUN(do_emote         );
DECLARE_DO_FUN(do_ambush	);
DECLARE_DO_FUN(do_berserk       );
DECLARE_DO_FUN(do_deathstyle    );
DECLARE_DO_FUN(do_bash          );
DECLARE_DO_FUN(do_trip          );
DECLARE_DO_FUN(do_dirt          );
DECLARE_DO_FUN(do_flee          );
DECLARE_DO_FUN(do_kick          );
DECLARE_DO_FUN(do_disarm        );
DECLARE_DO_FUN(do_get           );
DECLARE_DO_FUN(do_recall        );
DECLARE_DO_FUN(do_yell          );
DECLARE_DO_FUN(do_myell          );
DECLARE_DO_FUN(do_sacrifice     );
DECLARE_DO_FUN(do_circle_stab	);
DECLARE_DO_FUN(do_battlecry	);
DECLARE_DO_FUN(do_steel_nerves	);
DECLARE_DO_FUN(do_look);
DECLARE_DO_FUN(do_crush);
DECLARE_DO_FUN(do_tail	);
DECLARE_DO_FUN(do_undead_drain);
DECLARE_DO_FUN(do_executioners_grace);
DECLARE_DO_FUN(do_bind);
DECLARE_DO_FUN(do_unbind);
DECLARE_DO_FUN(do_blitz);
DECLARE_SPELL_FUN(spell_evil_eye);
DECLARE_SPELL_FUN(spell_power_word_kill);
DECLARE_DO_FUN(do_echo);
DECLARE_DO_FUN(do_help);
DECLARE_DO_FUN(do_cb);
DECLARE_DO_FUN(do_ccb);
//DECLARE_DO_FUN(do_arena_echo);
void temp_death_log(CHAR_DATA *killer, CHAR_DATA *dead);
void perm_death_log(CHAR_DATA *ch, int deltype);

/*
 * Local functions.
 */
void check_downstrike args( (CHAR_DATA *ch, CHAR_DATA *victim) );
void check_assist args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
bool check_dodge args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
bool check_questdodge args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
bool check_block args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
void check_killer args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
bool check_parry args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
//bool check_flourintine args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
bool check_spin args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
bool check_displacement args( (CHAR_DATA *ch, CHAR_DATA *victim) );
bool check_defiant_absorb args((CHAR_DATA *ch, CHAR_DATA *victim, int dt ));
bool check_shield_block args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
void dam_message args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dam,int dt, bool immune ) );
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,int group_amount, int glevel ) );
bool    is_safe         args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void    make_corpse     args( ( CHAR_DATA *killer, CHAR_DATA *ch ) );
void    one_hit         args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ));
void    mob_hit         args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
void    raw_kill        args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void    set_fighting    args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void    disarm          args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
int 	battlecry_multiplier 	args( ( CHAR_DATA *ch, int dt) );
void do_counter_parry	args( (CHAR_DATA *ch,CHAR_DATA *victim, int dt,int dam) );
void 	check_ground_control args( (CHAR_DATA *ch,CHAR_DATA *victim,int chance,int dam) );
void	check_ranger_staff	args( (CHAR_DATA *ch,OBJ_DATA *wield) );
void	check_clown_mallet	args( (int level,CHAR_DATA *ch,CHAR_DATA *victim, OBJ_DATA *wield) );
void	golden_weapon	args( (CHAR_DATA *ch,OBJ_DATA *wield) );
void	check_ceial_tat args ( (CHAR_DATA *ch) );
void	check_outlaw_badge	args( (CHAR_DATA *ch) );
bool	check_counter	args( (CHAR_DATA *ch,CHAR_DATA *victim, int dam,int dt) );
bool 	check_palm	args( (CHAR_DATA *ch ) );
void check_follow_through	args( ( CHAR_DATA *ch, CHAR_DATA *victim,int dam) );
bool 	check_roll	args( (CHAR_DATA *ch,CHAR_DATA *victim,int dt) );
void	check_red_shield args(( CHAR_DATA *ch) );
void check_bracelets args((CHAR_DATA *ch));
void wing_beating args((CHAR_DATA *ch) );
void etched_pendant args((CHAR_DATA *ch) );
void hammer_pendant args((CHAR_DATA *ch) );
void kyr_tattoo args((CHAR_DATA *ch,CHAR_DATA *victim) );
void dev_tattoo args((CHAR_DATA *ch,CHAR_DATA *victim) );
void cei_tattoo(CHAR_DATA *ch);
void deo_tattoo	args( (CHAR_DATA *ch, CHAR_DATA *victim) );
void gra_tattoo	args( (CHAR_DATA *ch, CHAR_DATA *victim) );
void mer_tattoo(CHAR_DATA *ch);
void kra_tattoo args((CHAR_DATA *ch,CHAR_DATA *victim) );
void xanthr_tattoo args((CHAR_DATA *ch,CHAR_DATA *victim) );
bool check_crown_blood args((CHAR_DATA *ch,CHAR_DATA *victim,int dt, int dam, int dam_type));
void check_blue_talon args((CHAR_DATA *ch, CHAR_DATA *victim));
int 	check_cutter args((CHAR_DATA *ch,CHAR_DATA *victim));
bool 	eye_of_beholder_absorb args((CHAR_DATA *ch,CHAR_DATA *victim,
			int dt, int dam, int dam_type));
void do_strap args((CHAR_DATA *victim,OBJ_DATA *strap));
bool check_unholy_bless args((CHAR_DATA *ch, CHAR_DATA *victim));
void check_cheap_shot args((CHAR_DATA *ch, CHAR_DATA *victim));
void check_parting_blow args((CHAR_DATA *ch, CHAR_DATA *victim));
bool                 arena;
bool check_distance  args((CHAR_DATA *ch, CHAR_DATA *victim, int dt ));
bool check_ironhands args((CHAR_DATA *ch, CHAR_DATA *victim, int dt ));
bool check_unarmed_defense args((CHAR_DATA *ch, CHAR_DATA *victim, int dt ));
char *get_dam_message args((CHAR_DATA *ch, int dt));
char * get_attack_noun args((CHAR_DATA *ch, int dt));
int get_attack_number args((CHAR_DATA *ch, int dt));
bool check_dispel( int dis_level, CHAR_DATA *victim, int sn);
bool check_cutoff(CHAR_DATA *ch, CHAR_DATA *victim);
bool    check_chargeset args( ( CHAR_DATA *ch, CHAR_DATA *victim ));
void do_arena_echo(const char *txt);
int check_imperial_training(CHAR_DATA *ch);
bool check_wall_thorns args((CHAR_DATA *ch));
bool check_bloody args((CHAR_DATA *ch));

bool isShifted args ((CHAR_DATA *ch));
int get_shifted args ((CHAR_DATA *ch));
bool check_rangermob(CHAR_DATA *mob);

CHAR_DATA *jujitsu_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;
    int regen, to_heal;
    OBJ_DATA *torque;
    OBJ_DATA *obj;

    //for ( ch = char_list; ch != NULL; ch = ch->next )
    for ( ch = char_list; ch != NULL; ch = ch_next )
    {
        ch_next = ch->next;

	obj = get_eq_char(ch,WEAR_HEAD);
	if (obj != NULL && obj->pIndexData->vnum == OBJ_VNUM_TIARA)
	{
	ch->mana = UMIN(ch->mana + number_range(1,4),ch->max_mana);
    	}
	obj = get_eq_char(ch,WEAR_HOLD);
	if (obj != NULL && obj->pIndexData->vnum == 14739)
	{
	/* greater symbol of magic */
	ch->mana = UMIN(ch->mana + number_range(1,3),ch->max_mana);
	}

/* regen */
	if (!IS_NPC(ch))
	{
	regen = get_skill(ch,gsn_regeneration);
	to_heal = (ch->max_hit - ch->hit);

	if (number_percent() <=  ch->level*2)
	{
	if ((ch->hit < ch->max_hit)
	&& ch->noregen_dam < to_heal
	&& number_percent() < regen)
	{
	if (number_percent() < 3)
		check_improve(ch,gsn_regeneration,TRUE,4);
	ch->hit += number_range(1,3);
	}
	}
	}

	if (ch->regen_rate != 0)
	{
	if (ch->regen_rate > 0)
	regen = number_range(1,ch->regen_rate);
	else
	regen = number_range(1,-ch->regen_rate);
	if (ch->hit < ch->max_hit)
	{
	if (ch->regen_rate > 0)
	ch->hit = UMIN(ch->hit + regen,ch->max_hit);
	else
	ch->hit = UMIN(ch->hit - regen,ch->max_hit);
	}
	}

        torque = get_eq_char(ch,WEAR_NECK_1);
        if (torque == NULL)
                torque = get_eq_char(ch,WEAR_NECK_2);
        if (torque != NULL)
        {
        if (torque->pIndexData->vnum == OBJ_VNUM_TORQUE)
                if (ch->hit < ch->max_hit)
                        ch->hit = UMIN(ch->hit + dice(1,3),ch->max_hit);
        }

        if ( ( victim = ch->fighting ) == NULL || ch->in_room == NULL )
            continue;

	if (IS_NPC(ch) && (!IS_NPC(ch->fighting))
	&& !IS_SET(ch->act,ACT_NO_TRACK)
	&& !IS_AFFECTED(ch,AFF_CHARM)
	&& !IS_SET(ch->act,ACT_IS_HEALER)
	&& !IS_SET(ch->act,ACT_BANKER))
		ch->last_fought = ch->fighting;

	update_pc_last_fight(ch,ch->fighting);

        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;

        if ( IS_NPC( ch ) )
        {
            if ( HAS_TRIGGER( ch, TRIG_FIGHT ) )
                mp_percent_trigger( ch, victim, NULL, NULL, TRIG_FIGHT );
            if ( HAS_TRIGGER( ch, TRIG_HPCNT ) )
                mp_hprct_trigger( ch, victim );
        }

        /*
         * Fun for the whole family!
         */
        check_assist(ch,victim);
    }

    return;
}

/* for auto assisting */
void check_assist(CHAR_DATA *ch,CHAR_DATA *victim)
{
    CHAR_DATA *rch, *rch_next;

    for (rch = ch->in_room->people; rch != NULL; rch = rch_next)
    {
        rch_next = rch->next_in_room;

	if (!IS_NPC(rch) && rch->ghost > 0)
		continue;

        if (IS_AWAKE(rch) && rch->fighting == NULL)
        {

/* NPC assisting group (for charm, zombies, elementals..added by Ceran */
	if (IS_NPC(rch) && (IS_AFFECTED(rch,AFF_CHARM)) && is_same_group(rch,ch) )
 	{
		multi_hit(rch,victim,TYPE_UNDEFINED);
		continue;
	}


            /* quick check for ASSIST_PLAYER */
            if (!IS_NPC(ch) && IS_NPC(rch)
            && IS_SET(rch->off_flags,ASSIST_PLAYERS)
            &&  rch->level + 6 > victim->level)
            {
                do_emote(rch,"screams and attacks!");
                multi_hit(rch,victim,TYPE_UNDEFINED);
                continue;
            }

            /* PCs next */
            if ( !IS_NPC(ch) || IS_AFFECTED(ch,AFF_CHARM))
            {
/* First check defending */
		if (rch->defending != NULL)
		{
		CHAR_DATA *fch;

		fch = ch->fighting;
		if (rch->defending != NULL
		&& rch->defending == ch
		&& fch != NULL
		&& fch->fighting == ch
		&& number_percent() < get_skill(rch,gsn_defend)
		&& number_percent() > 40
		&& number_percent() < get_skill(rch,gsn_rescue))
		{
	act("$n leaps to $N's rescue!",rch,0,ch,TO_NOTVICT);
	act("$n leaps to your rescue!",rch,0,ch,TO_VICT);
	act("You leap to $N's rescue!",rch,0,ch,TO_CHAR);

    if (is_safe(rch,fch))
	return;

    WAIT_STATE( rch, skill_table[gsn_rescue].beats );
    WAIT_STATE(ch,12);
    check_improve(rch,gsn_defend,TRUE,1);

    stop_fighting( fch, FALSE );
    stop_fighting( ch, FALSE );

    set_fighting( rch, fch );
    set_fighting( fch, rch );
	if (IS_NPC(fch)
	&& (fch->pIndexData->vnum == MOB_VNUM_COVEN
	|| fch->pIndexData->vnum == MOB_VNUM_ACADIAN
	|| fch->pIndexData->vnum == MOB_VNUM_PROTECTOR
	|| fch->pIndexData->vnum == MOB_VNUM_RAVAGER
    || fch->pIndexData->vnum == MOB_VNUM_BRIAR
	|| fch->pIndexData->vnum == MOB_VNUM_PROTECTOR) )
		set_fighting(ch,fch);

		continue;
		}
	}


                if ( ( (!IS_NPC(rch) && IS_SET(rch->act,PLR_AUTOASSIST))
                ||     IS_AFFECTED(rch,AFF_CHARM))
                &&   is_same_group(ch,rch)
                &&   !is_safe(rch, victim))
                    multi_hit (rch,victim,TYPE_UNDEFINED);

                continue;
            }

            /* now check the NPC cases */

            if (IS_NPC(ch) && !IS_AFFECTED(ch,AFF_CHARM))

            {
                if ( (IS_NPC(rch) && IS_SET(rch->off_flags,ASSIST_ALL))

                ||   (IS_NPC(rch) && rch->group && rch->group == ch->group)

                ||   (IS_NPC(rch) && rch->race == ch->race
                   && IS_SET(rch->off_flags,ASSIST_RACE))

                ||   (IS_NPC(rch) && IS_SET(rch->off_flags,ASSIST_ALIGN)
                   &&   ((IS_GOOD(rch)    && IS_GOOD(ch))
                     ||  (IS_EVIL(rch)    && IS_EVIL(ch))
                     ||  (IS_NEUTRAL(rch) && IS_NEUTRAL(ch))))

                ||   (rch->pIndexData == ch->pIndexData
                   && IS_SET(rch->off_flags,ASSIST_VNUM)))

                {
                    CHAR_DATA *vch;
                    CHAR_DATA *target;
                    int number;

                    if (number_bits(1) == 0)
                        continue;

                    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)
                    {
                        do_emote(rch,"screams and attacks!");
                        multi_hit(rch,target,TYPE_UNDEFINED);
                    }
                }
            }
        }
    }
}


/*
 * Do one group of attacks.
 */
void multi_hit( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
    int     chance;
    int	    dual_chance;
    int	trinal_chance;
    int attacks;
    int form;
    int	i;
	AFFECT_DATA *paf;
	AFFECT_DATA *paf_next;

    OBJ_DATA *obj;
    OBJ_DATA *wield;
    if (is_affected(ch,gsn_timestop))
    {
	if (ch->fighting != NULL)
		ch->fighting = NULL;
	return;
    }
    /* decrement the wait */
    if (ch->desc == NULL)
        ch->wait = UMAX(0,ch->wait - PULSE_VIOLENCE);

	if (ch->level == MAX_LEVEL) {
		ch->wait = 0;
	}

    if (ch->desc == NULL)
        ch->daze = UMAX(0,ch->daze - PULSE_VIOLENCE);

	if (ch->level == MAX_LEVEL)
		ch->daze = 0;

	for ( paf = ch->affected; paf != NULL; paf = paf_next )
	{
		paf_next = paf->next;

		if (paf->wait > 0)
		{
			paf->wait -= 1;
		}

		/* jujitsu check - start */
		if ( paf->type == gsn_jujitsu && paf->wait == 0)
		{

			char jujitsubuf[MSL];
			int jujitsu_chance, dam;
			jujitsu_victim = paf->owner;

			jujitsu_chance = get_skill(ch,gsn_jujitsu);

			dam = (ch->drain_level + ch->level)/2;
			dam += number_range(0,(ch->drain_level + ch->level)/6);
			dam += number_range(0,(ch->drain_level + ch->level)/6);
			dam += number_range(0,(ch->drain_level + ch->level)/6);
			dam += number_range(0,(ch->drain_level + ch->level)/6);
			dam += number_range(0,(ch->drain_level + ch->level)/6);
			dam += number_range(0,(ch->drain_level + ch->level)/6);
			dam += number_range(ch->level/5,ch->level/4);

			if (jujitsu_victim->fighting != ch)
			{
				sprintf(jujitsubuf,"%s is not fighting you anymore, and you cannot complete your manuever.\n\r",jujitsu_victim->name);
				send_to_char(jujitsubuf,ch);
				affect_strip(ch,gsn_jujitsu);
			}
			else
			{
				if (number_percent() < jujitsu_chance)
				{
					send_to_char("{GATTACK 1!!!!{x\n\r",ch);
					damage(ch,jujitsu_victim,dam,gsn_jujitsu,DAM_BASH,TRUE);
					jujitsu_chance -= 10;
					dam -= number_range(0,(ch->drain_level + ch->level)/6);
					if (number_percent() < jujitsu_chance)
					{
						send_to_char("{GATTACK 2!!!!{x\n\r",ch);
						damage(ch,jujitsu_victim,dam,gsn_jujitsu,DAM_BASH,TRUE);
						jujitsu_chance -= 10;
						dam -= number_range(0,(ch->drain_level + ch->level)/6);
						if (number_percent() < jujitsu_chance)
						{
							send_to_char("{GATTACK 3!!!!{x\n\r",ch);
							damage(ch,jujitsu_victim,dam,gsn_jujitsu,DAM_BASH,TRUE);
							jujitsu_chance -= 10;
							dam -= number_range(0,(ch->drain_level + ch->level)/6);
							if (number_percent() < jujitsu_chance)
							{
								send_to_char("{GATTACK 4!!!!{x\n\r",ch);
								damage(ch,jujitsu_victim,dam,gsn_jujitsu,DAM_BASH,TRUE);
								jujitsu_chance -= 10;
								dam -= number_range(0,(ch->drain_level + ch->level)/6);
								if (number_percent() < jujitsu_chance)
								{
									send_to_char("{GATTACK 5!!!!{x\n\r",ch);
									damage(ch,jujitsu_victim,dam,gsn_jujitsu,DAM_BASH,TRUE);
								}
							}
						}
					}
				}
				affect_strip(ch,gsn_jujitsu);
			}
		}
		/* jujitsu check - end */
	}

if(is_affected(victim,gsn_snare) && number_percent()<11 && victim->fighting!=NULL)
	{
		act("In the chaos of combat, the snare holding $n comes loose.",victim,0,0,TO_ROOM);
		act("In the chaos of combat, the snare holding you comes loose.",victim,0,0,TO_CHAR);
		affect_strip(victim,gsn_snare);
	}

    /* no attacks for stunnies -- just a check */
    if (ch->position < POS_RESTING)
        return;
    if (IS_NPC(ch)) {
	    if (ch->pIndexData->vnum  == MOB_VNUM_WATER_ELEMENTAL) {
		   if (number_percent() < 20) {
			do_bash(ch,"");
	         }
	    }
	    if (ch->pIndexData->vnum  == MOB_VNUM_AIR_ELEMENTAL) {
		   if (number_percent() < 20) {
			do_trip(ch,"");
	         }
	    }
      }
    if (IS_NPC(ch))
    {
        mob_hit(ch,victim,dt);
        return;
    }

if( isShifted(ch) )
    {
	form = get_shifted(ch);
	attacks = number_range(1, form_table[form].attacks);

	for(i = 0; i < attacks; i++)
	{
		one_hit(ch, victim, dt);
	}
	return;
    }

    one_hit( ch, victim, dt );
    if (ch->fighting != victim)
        return;
    check_bracelets(ch);
    wing_beating(ch);
    hammer_pendant(ch);
    etched_pendant(ch);
    kyr_tattoo(ch,victim);
    dev_tattoo(ch,victim);
    mer_tattoo(ch);
    cei_tattoo(ch);
	deo_tattoo(ch,victim);
    gra_tattoo(ch,victim);
    kra_tattoo(ch,victim);
    xanthr_tattoo(ch,victim);
    obj = get_eq_char(ch,WEAR_BRAND);
    if (ch->fighting == victim)

   if ( (wield = get_eq_char(ch,WEAR_WIELD)) != NULL)
    {
        if (ch->fighting == victim && wield->pIndexData->vnum == 14726)
                check_blue_talon(ch,ch->fighting);
    }

    if ( ch->fighting != victim || dt == gsn_backstab || (dt ==  gsn_ambush) )
        return;

    if (IS_AFFECTED(ch,AFF_HASTE))
        one_hit(ch,victim,dt);


    chance = get_skill(ch,gsn_second_attack)/2;
    dual_chance = get_skill(ch,gsn_dual_wield)/2;
    trinal_chance = get_skill(ch,gsn_tertiary_wield)/2;

    if (is_affected(ch,gsn_maehslin) && number_percent() < 65)
    {
	act("The amber aura around $n intenses and their movements become more fluid!",ch,0,0,TO_VICT);
    act("$n's amber aura intenses and their movements become more fluid!" ,ch,0,0,TO_NOTVICT);
    act("Your amber aura intenses and your movements become more fluid!",ch,0,0,TO_CHAR);
	one_hit(ch,victim,dt);
    chance*=1.25;
	dual_chance*=1.25;
	chance*=1.25;
	}
    if (IS_AFFECTED(ch,AFF_HASTE))
    {
	chance*=1.25;
	dual_chance*=1.25;
	chance*=1.25;
    }
    if (IS_AFFECTED(ch,AFF_SLOW))
	{
      chance /= 2;
	dual_chance /= 2;
	trinal_chance /= 2;
	}
	if (check_imperial_training(ch) == IMPERIAL_DEFENSE)
	{
	chance /= 2.5;
	dual_chance /= 2.5;
	}

    if ( number_percent( ) < chance )
    {
        one_hit( ch, victim, dt );
        check_improve(ch,gsn_second_attack,TRUE,5);
        if ( ch->fighting != victim )
            return;
    }
    check_bracelets(ch);
    wing_beating(ch);

    if ( (wield = get_eq_char(ch,WEAR_WIELD)) != NULL)
    {
        if (ch->fighting == victim && wield->pIndexData->vnum == 14726)
                check_blue_talon(ch,ch->fighting);
    }

    if (get_eq_char(ch,WEAR_DUAL_WIELD) != NULL
	&& ch->pcdata->learned[gsn_second_attack] > 10)
    {
	if (number_percent( ) < dual_chance)
	{
	one_hit(ch,victim,gsn_dual_wield);
	check_improve(ch,gsn_dual_wield,TRUE,3);
	if (ch->fighting != victim)
		return;
	}
	else
	check_improve(ch,gsn_dual_wield,FALSE,3);
    }

    if (get_eq_char(ch,WEAR_TERTIARY_WIELD) != NULL
	&& ch->pcdata->learned[gsn_second_attack] > 10)
    {
	if (number_percent( ) < trinal_chance)
	{
	one_hit(ch,victim,gsn_tertiary_wield);
	check_improve(ch,gsn_tertiary_wield,TRUE,3);
	if (ch->fighting != victim)
		return;
	}
	else
	check_improve(ch,gsn_tertiary_wield,FALSE,3);
    }

	if (!IS_NPC(ch) && !str_cmp(class_table[ch->class].name,"monk")
	&&  (get_eq_char(ch,WEAR_WIELD) != NULL) )
	return; 	/* Monks can't get 3/4th attack with a weapon */

    chance = get_skill(ch,gsn_third_attack)/4;

    if (IS_AFFECTED(ch,AFF_SLOW))
        chance = 0;
    if (is_affected(ch,skill_lookup("haste")))
        chance*=1.3;
    if ( number_percent( ) < chance )
    {
        one_hit( ch, victim, dt );
        check_improve(ch,gsn_third_attack,TRUE,6);
        if ( ch->fighting != victim )
            return;
    }

    dual_chance = get_skill(ch,gsn_dual_wield)/4;
    if (is_affected(ch,skill_lookup("haste")))
        dual_chance*=1.2;
    if (get_eq_char(ch,WEAR_DUAL_WIELD) != NULL
	&& ch->pcdata->learned[gsn_third_attack] > 10)
    {
	if (number_percent( ) < dual_chance)
	{
	one_hit(ch,victim,gsn_dual_wield);
	check_improve(ch,gsn_dual_wield,TRUE,3);
	if (ch->fighting != victim)
		return;
	}
	else
	check_improve(ch,gsn_dual_wield,FALSE,3);
    }

    trinal_chance = get_skill(ch,gsn_tertiary_wield)/3;
    if (is_affected(ch,skill_lookup("haste")))
        trinal_chance*=1.2;
    if (get_eq_char(ch,WEAR_TERTIARY_WIELD) != NULL
	&& ch->pcdata->learned[gsn_third_attack] > 10)
    {
	if (number_percent( ) < trinal_chance)
	{
	one_hit(ch,victim,gsn_tertiary_wield);
	check_improve(ch,gsn_tertiary_wield,TRUE,3);
	if (ch->fighting != victim)
		return;
	}
	else
	check_improve(ch,gsn_tertiary_wield,FALSE,3);
    }

    chance = get_skill(ch,gsn_fourth_attack)/5;

    if (IS_AFFECTED(ch,AFF_SLOW))
	chance /= 2;
    if (is_affected(ch,skill_lookup("haste")))
        chance*=1.3;
    if ( number_percent() < chance )
    {
	one_hit( ch, victim, dt );
	check_improve(ch,gsn_fourth_attack,TRUE,6);
	if (ch->fighting != victim )
	    return;
    }

    dual_chance = get_skill(ch,gsn_dual_wield)/4;
    if (is_affected(ch,skill_lookup("haste")))
        dual_chance*=1.2;
    if (get_eq_char(ch,WEAR_DUAL_WIELD) != NULL
	&& ch->pcdata->learned[gsn_fourth_attack] > 10)
    {
	if (number_percent( ) < dual_chance)
	{
	one_hit(ch,victim,gsn_dual_wield);
	check_improve(ch,gsn_dual_wield,TRUE,6);
	if (ch->fighting != victim)
		return;
	}
	else
	check_improve(ch,gsn_dual_wield,FALSE,5);
    }

    trinal_chance = get_skill(ch,gsn_tertiary_wield)/6;
    if (is_affected(ch,skill_lookup("haste")))
        trinal_chance*=1.1;
    if (get_eq_char(ch,WEAR_TERTIARY_WIELD) != NULL
	&& ch->pcdata->learned[gsn_fourth_attack] > 85)
    {
	if (number_percent( ) < trinal_chance)
	{
	one_hit(ch,victim,gsn_tertiary_wield);
	check_improve(ch,gsn_tertiary_wield,TRUE,3);
	if (ch->fighting != victim)
		return;
	}
	else
	check_improve(ch,gsn_tertiary_wield,FALSE,3);
    }

/* zealotism */
	chance = get_skill(ch,gsn_zealotism)/4;
	if (chance != 0) {
	if (IS_AFFECTED(ch,AFF_SLOW))
		chance /= 2;
	if (IS_AFFECTED(ch,AFF_HASTE))
		chance*=1.25;
	if (is_affected(ch,gsn_bloodthirst))
		chance*=1.25;
	if (is_affected(ch,gsn_rage_of_dioxide))
		chance*=1.35;
	if (IS_AFFECTED(ch,AFF_BERSERK))
		chance*=1.25;

	for (i=0; i<(chance/20); i++) {
		act("Delirious with zeal, you strike $N again!",ch,0,victim,TO_CHAR);
		one_hit(ch, victim, dt);
	}
	check_improve(ch,gsn_zealotism,TRUE,1);
	if (ch->fighting != victim )
	return;
	}

/* imperial training */

	if (check_imperial_training(ch) == IMPERIAL_OFFENSE && get_skill(ch,gsn_third_attack)>80)
	{
		chance = number_range(1,2);
		for (i=0; i<chance; i++)
			one_hit(ch, victim, dt);
	}
	return;
}

/* procedure for all mobile attacks */
void mob_hit (CHAR_DATA *ch, CHAR_DATA *victim, int dt)
{
    int chance,number;
    int dual_chance;
    CHAR_DATA *vch, *vch_next;

    one_hit(ch,victim,dt);

    if (ch->fighting != victim)
        return;

    /* Area attack -- BALLS nasty! */
    if (IS_SET(ch->off_flags,OFF_AREA_ATTACK))
    {
        for (vch = ch->in_room->people; vch != NULL; vch = vch_next)
        {
            vch_next = vch->next;
            if ((vch != victim && vch->fighting == ch))
                one_hit(ch,vch,dt);
        }
    }

    if (is_affected(ch,skill_lookup("haste"))
    ||  (IS_SET(ch->off_flags,OFF_FAST) && !IS_AFFECTED(ch,AFF_SLOW)))
        one_hit(ch,victim,dt);

    if (ch->fighting != victim || dt == gsn_backstab)
        return;

    chance = get_skill(ch,gsn_second_attack)/2;
    dual_chance = ch->level*2/3;

    if (IS_AFFECTED(ch,AFF_SLOW) && !IS_SET(ch->off_flags,OFF_FAST))
    {
	dual_chance /= 2;
        chance /= 2;
    }

    if (number_percent() < chance)
    {
        one_hit(ch,victim,dt);
        if (ch->fighting != victim)
            return;
    }

    if (IS_AFFECTED(ch,AFF_HASTE))
	dual_chance *= 6/4;

    if (number_percent() < dual_chance && get_eq_char(ch,WEAR_DUAL_WIELD) != NULL)
    {
	one_hit(ch,victim,gsn_dual_wield);
	if (ch->fighting != victim)
		return;
    }

    chance = get_skill(ch,gsn_third_attack)/4;
     dual_chance *= 2/3;

    if (IS_AFFECTED(ch,AFF_SLOW) && !IS_SET(ch->off_flags,OFF_FAST))
    {
	dual_chance = 0;
        chance = 0;
    }

    if (IS_AFFECTED(ch,AFF_HASTE))
	dual_chance *= 3/2;

    if (number_percent() < chance)
    {
        one_hit(ch,victim,dt);
        if (ch->fighting != victim)
            return;
    }

    if (number_percent() < dual_chance && get_eq_char(ch,WEAR_DUAL_WIELD) != NULL)
    {
	one_hit(ch,victim,gsn_dual_wield);
	if (ch->fighting != victim)
		return;
    }

    /* oh boy!  Fun stuff! */

    if (ch->wait > 0)
        return;

    number = number_range(0,2);

    if (number == 1 && IS_SET(ch->act,ACT_MAGE))
    {
        /*  { mob_cast_mage(ch,victim); return; } */ ;
    }

    if (number == 2 && IS_SET(ch->act,ACT_CLERIC))
    {
        /* { mob_cast_cleric(ch,victim); return; } */ ;
    }

    /* now for the skills */

    number = number_range(0,9);

    switch(number)
    {
    case (0) :
        if (IS_SET(ch->off_flags,OFF_BASH))
            do_bash(ch,"");
	else if (IS_SET(ch->off_flags,OFF_TAIL))
	    do_tail(ch,"");
        break;

    case (1) :
        if (IS_SET(ch->off_flags,OFF_BERSERK) && !IS_AFFECTED(ch,AFF_BERSERK))
            do_berserk(ch,"");
        break;


    case (2) :
        if (IS_SET(ch->off_flags,OFF_DISARM)
        || (get_weapon_sn(ch) != gsn_hand_to_hand
        && (IS_SET(ch->act,ACT_WARRIOR)
        ||  IS_SET(ch->act,ACT_THIEF))))
            do_disarm(ch,"");
        break;

    case (3) :
        if (IS_SET(ch->off_flags,OFF_KICK))
            do_kick(ch,"");
        break;

    case (4) :
        if (IS_SET(ch->off_flags,OFF_KICK_DIRT))
            do_dirt(ch,"");
        break;

    case (5) :
        if (IS_SET(ch->off_flags,OFF_TAIL))
        {
               do_tail(ch,"");
        }
        break;

    case (6) :
        if (IS_SET(ch->off_flags,OFF_TRIP))
            do_trip(ch,"");
        break;

    case (7) :
        if (IS_SET(ch->off_flags,OFF_CRUSH))
        {
            do_crush(ch,"") ;
        }
        break;
    case (8) :
        if (IS_SET(ch->off_flags,OFF_BACKSTAB))
        {
            do_backstab(ch,"");
        }
	else if (IS_SET(ch->off_flags,OFF_UNDEAD_DRAIN))
		do_undead_drain(ch,"");
	break;
    case (9) :
	if ( IS_SET(ch->off_flags,OFF_UNDEAD_DRAIN))
	{
		do_undead_drain(ch,"");
	}
	break;
    }
}


/*
 * Hit one guy once.
 */
void one_hit( CHAR_DATA *ch, CHAR_DATA *victim, int dt)
{
	OBJ_DATA *wield;
	OBJ_DATA *backfist_wield;
	OBJ_DATA *backfist_dual;
	OBJ_DATA *backfist_shield;
	OBJ_DATA *backfist_hold;
    int victim_ac;
    int thac0;
    OBJ_DATA *obj;
    int bcry;
    int thac0_00;
    int thac0_32;
    int dam, mdam, bladam, tchance;
    int diceroll, diceroll2 = 0;
    int sn,skill;
    int dam_type;
    int tmp_dt;
	int handcounter=0;
    bool result;
    bool exeresult;
    int exedam;
    int form;
    /*sn = -1;*/
    const char *attack;
    char buf1[MAX_STRING_LENGTH];
    char buf2[MAX_STRING_LENGTH];
    char buf3[MAX_STRING_LENGTH];
    int thesn;

    /* just in case */
    if (victim == ch || ch == NULL || victim == NULL)
        return;

    /*
     * 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.
     */

    if(isShifted(ch))
    {
	form = get_shifted(ch);
	dt = TYPE_HIT + attack_lookup(form_table[form].attack_type);
    }

    wield = get_eq_char( ch, WEAR_WIELD );
	backfist_wield = get_eq_char( victim, WEAR_WIELD );
	backfist_dual = get_eq_char( victim, WEAR_DUAL_WIELD );
	backfist_shield = get_eq_char( victim, WEAR_SHIELD );
	backfist_hold = get_eq_char( victim, WEAR_HOLD );

    if ( dt == TYPE_UNDEFINED )
    {
        dt = TYPE_HIT;
        if ( wield != NULL && wield->item_type == ITEM_WEAPON )
            dt += wield->value[3];
        else
            dt += ch->dam_type;
    }
    if(is_affected(ch,gsn_executioner) && number_percent()<5)
    {
      act("$n suddenly darts forward with impossible agility and gracefully strikes you!",ch,0,victim,TO_VICT);
      act("$n suddenly darts forward with impossible agility and gracefully strikes $N!",ch,0,victim,TO_NOTVICT);
      act("Imbued with the grace of an executioner, you suddenly dart forward with impossible agility and gracefully strike $N!",ch,0,victim,TO_CHAR);
	exedam=GET_DAMROLL(ch)+140;
	exeresult = damage( ch, victim, exedam, gsn_executioner, DAM_HOLY, TRUE );
    }
    if(is_affected(victim,gsn_executioner) && number_percent()<7 && dt!=gsn_flurry && dt!=gsn_drum)
    {
        act("$n smoothly redirects $N's attack, and with lithe grace unleashes a deadly riposte!",victim,0,ch,TO_NOTVICT);
        act("You smoothly redirect $N's attack and with lithe grace unleash a deadly riposte!",victim,0,ch,TO_CHAR);
        act("$n smoothly redirects your attack and with lithe grace unleashes a deadly riposte!",victim,0,ch,TO_VICT);
	  exedam=GET_DAMROLL(ch)+100;
	  exeresult = damage( victim, ch, exedam, gsn_executioner, DAM_HOLY, TRUE );
    }


    if(get_skill(victim,gsn_backfist) !=0)
    {
		if (backfist_wield != NULL)
			handcounter += 1;
		if (backfist_dual != NULL)
			handcounter += 1;
		if (backfist_shield != NULL)
			handcounter += 1;
		if (backfist_hold != NULL)
			handcounter += 1;

		if (number_percent() < (get_skill(victim,gsn_backfist)/5) && handcounter < 2)
		{
			act("$n steps in quickly to strike $N with a quick backfist!",victim,0,ch,TO_NOTVICT);
			act("You step in quickly to strike $N with a quick backfist!",victim,0,ch,TO_CHAR);
			act("$n steps in quickly to strike you with a quick backfist!!",victim,0,ch,TO_VICT);
			exeresult = damage( victim, ch, GET_DAMROLL(victim)+75, gsn_backfist, DAM_BASH, TRUE );
			check_improve(victim,gsn_backfist,TRUE,1);
		}
		else
		{
			check_improve(victim,gsn_backfist,FALSE,1);
		}
    }

    if (dt < TYPE_HIT)
        if (wield != NULL)
            dam_type = attack_table[wield->value[3]].damage;
        else
            dam_type = attack_table[ch->dam_type].damage;
    else
        dam_type = attack_table[dt - TYPE_HIT].damage;

    if (dam_type == -1)
        dam_type = DAM_BASH;

    /* get the weapon skill */
    sn = get_weapon_sn(ch);
    skill = 20 + get_weapon_skill(ch,sn);

/* DUAL WIELD..kinda messy here */
    if (dt == gsn_dual_wield || dt == gsn_tertiary_wield)
    {
if (dt == gsn_dual_wield)
    wield = get_eq_char( ch, WEAR_DUAL_WIELD );
else
    wield = get_eq_char(ch,WEAR_TERTIARY_WIELD);
        tmp_dt = TYPE_HIT;
        if ( wield != NULL && wield->item_type == ITEM_WEAPON )
            tmp_dt += wield->value[3];
        else
            tmp_dt += ch->dam_type;

    if (tmp_dt < TYPE_HIT)
        if (wield != NULL)
            dam_type = attack_table[wield->value[3]].damage;
        else
            dam_type = attack_table[ch->dam_type].damage;
    else
        dam_type = attack_table[dt - TYPE_HIT].damage;

    if (dam_type == -1)
        dam_type = DAM_BASH;

    if (wield == NULL)		sn = -1;
    else switch (wield->value[0])
    {
	default:	sn = -1;	break;
	case (WEAPON_SWORD):	sn = gsn_sword;		break;
	case (WEAPON_DAGGER):	sn = gsn_dagger;	break;
	case (WEAPON_SPEAR):	sn = gsn_spear;		break;
	case (WEAPON_MACE):	sn = gsn_mace;		break;
	case (WEAPON_AXE):	sn = gsn_axe;		break;
	case (WEAPON_FLAIL):	sn = gsn_flail;		break;
	case (WEAPON_WHIP):	sn = gsn_whip;		break;
	case (WEAPON_POLEARM):	sn = gsn_polearm;	break;
    }

    skill = 10 + get_weapon_skill(ch,sn);

    }
    if(get_skill(victim,skill_lookup("blademaster"))>0 && !(cabal_down(ch,CABAL_PROTECTOR)))
    {
	tchance=3+((get_skill(victim,skill_lookup("blademaster"))-75)/3);
	if(is_affected(victim,AFF_HASTE))
		tchance+=2;
	if(is_affected(victim,AFF_SLOW))
		tchance-=5;
	if(number_percent()<tchance)
	{
      tmp_dt = TYPE_HIT;
      if (dt  == gsn_dual_wield)
    	  wield = get_eq_char(ch,WEAR_DUAL_WIELD);
      else if (dt == gsn_tertiary_wield)
	  wield = get_eq_char(ch,WEAR_TERTIARY_WIELD);
      else
	  wield = get_eq_char(ch,WEAR_WIELD);
	if (wield != NULL)
	  tmp_dt += wield->value[3];
      else
	  tmp_dt += ch->dam_type;
	if (wield != NULL && dt!=gsn_tertiary_wield)
	{
      if (tmp_dt > TYPE_HIT && tmp_dt < TYPE_HIT + MAX_DAMAGE_MESSAGE)
	  attack = attack_table[tmp_dt - TYPE_HIT].noun;
      else
      {
	  attack = attack_table[0].name;
      }
	  sprintf(buf1,"$n parries $N's %s, and skillfully unleashes an attack of $s own!",attack);
        act(buf1,victim,0,ch,TO_NOTVICT);
	  sprintf(buf2,"You parry $N's %s and skillfully unleash an attack of your own!",attack);
	  act(buf2,victim,0,ch,TO_CHAR);
        sprintf(buf3,"$n parries your %s and skillfully unleashes an attack of $s own!",attack);
	  act(buf3,victim,0,ch,TO_VICT);
	  thesn=skill_lookup("blademaster");
        bladam = number_range( wield->value[1], wield->value[2]);
	  bladam += GET_DAMROLL(ch)+(number_percent()/2);
	  exeresult = damage( victim, ch, bladam, thesn, DAM_SLASH, TRUE );
	  check_improve(victim,skill_lookup("blademaster"),TRUE,2);
          return;
	}
	}
    }

    /*
     * Calculate to-hit-armor-class-0 versus armor.
     */
    if ( IS_NPC(ch) )
    {
        thac0_00 = 20;
        thac0_32 = -4;   /* as good as a thief */
        if (IS_SET(ch->act,ACT_WARRIOR))
            thac0_32 = -10;
        else if (IS_SET(ch->act,ACT_THIEF))
            thac0_32 = -4;
        else if (IS_SET(ch->act,ACT_CLERIC))
            thac0_32 = 2;
        else if (IS_SET(ch->act,ACT_MAGE))
            thac0_32 = 6;
    }
    else
    {
        thac0_00 = class_table[ch->class].thac0_00;
        thac0_32 = class_table[ch->class].thac0_32;
    }
    thac0  = interpolate( ch->level + ch->drain_level, thac0_00, thac0_32 );

    if (thac0 < 0)
        thac0 = thac0/2;

    if (thac0 < -5)
        thac0 = -5 + (thac0 + 5) / 2;

    thac0 -= GET_HITROLL(ch) * skill/100;
    thac0 += 5 * (100 - skill) / 100;

    if (dt == gsn_backstab)
        thac0 -= 10 * (100 - get_skill(ch,gsn_backstab));

    if (dt == gsn_ambush)
	thac0 -= 15 * (100 - get_skill(ch,gsn_ambush));
    if (dt == gsn_impale)
	thac0 -= 15 * (100 - get_skill(ch,gsn_ambush));

    switch(dam_type)
    {
        case(DAM_PIERCE):victim_ac = GET_AC(victim,AC_PIERCE)/10;       break;
        case(DAM_BASH):  victim_ac = GET_AC(victim,AC_BASH)/10;         break;
        case(DAM_SLASH): victim_ac = GET_AC(victim,AC_SLASH)/10;        break;
        default:         victim_ac = GET_AC(victim,AC_EXOTIC)/10;       break;
    };

    if (victim_ac < -15)
        victim_ac = (victim_ac + 15) / 5 - 15;

    if ( !can_see( ch, victim ) )
        victim_ac -= 4;

    if ( victim->position < POS_FIGHTING)
        victim_ac += 4;

    if (victim->position < POS_RESTING)
        victim_ac += 6;

    /*
     * 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, dam_type, TRUE );
        tail_chain( );
        return;
    }

    /*
     * Hit.
     * Calc damage.
     */
    if ( IS_NPC(ch) && (!ch->pIndexData->new_format || wield == NULL))
        if (!ch->pIndexData->new_format)
        {
            dam = number_range( ( ch->level + ch->drain_level) / 2, (ch->drain_level + ch->level) * 3 / 2 );
            if ( wield != NULL )
                dam += dam / 2;
        }
        else
            dam = dice(ch->damage[DICE_NUMBER],ch->damage[DICE_TYPE]);

    else
    {
        if (sn != -1)
            check_improve(ch,sn,TRUE,5);
        if ( wield != NULL )
        {
            if (wield->pIndexData->new_format)
                dam = dice(wield->value[1],wield->value[2]) * skill/100;
            else
                dam = number_range( wield->value[1] * skill/100,
                                wield->value[2] * skill/100);

            if (get_eq_char(ch,WEAR_SHIELD) == NULL)  /* no shield = more */
                dam = dam * 11/10;

	    if (wield->level - (ch->drain_level + ch->level) >= 35)
		dam = (dam*6)/10;
	    else if (wield->level - (ch->drain_level + ch->level) >= 25)
		dam = (dam*7)/10;
	    else if (wield->level - (ch->drain_level + ch->level) >= 15)
		dam = (dam*8)/10;
	    else if (wield->level - (ch->drain_level + ch->level) >= 5)
		dam = (dam*9)/10;

            /* sharpness! */
            if (IS_WEAPON_STAT(wield,WEAPON_SHARP))
            {
                int percent;

                if ((percent = number_percent()) <= (skill / 8))
                    dam = 2 * dam + (dam * 2 * percent / 100);
            }
        }
        else
            dam = number_range( 1 + 4 * skill/100, 2 * ch->level/3 * skill/100);
    }

    /*
     * Bonuses.
     */

	dam += (ch->drain_level + ch->level)/8;

    if ( get_skill(ch,gsn_enhanced_damage) > 0 )
    {
        diceroll = number_percent();
	if (get_skill(ch,gsn_enhanced_damage_two) > 0)
	{
	diceroll2 = number_percent();
	if (diceroll2 < get_skill(ch,gsn_enhanced_damage_two)
	&& diceroll2 < get_skill(ch,gsn_enhanced_damage) )
	{
	check_improve(ch,gsn_enhanced_damage_two,TRUE,5);
		diceroll2 = diceroll2 + 5;
		diceroll = diceroll2;
	}
	}
	if (get_skill(ch,gsn_enhanced_damage_three) > 0)
	{
            check_improve(ch,gsn_enhanced_damage_three,TRUE,3);
		diceroll += get_skill(ch,gsn_enhanced_damage_three)/3;
	}
        if (diceroll <= get_skill(ch,gsn_enhanced_damage))
        {
            check_improve(ch,gsn_enhanced_damage,TRUE,6);
            dam += (dam * diceroll/125);
        }
    }
    else
	{
	dam *= 7;
	dam /= 10;
	}

    if ( !IS_AWAKE(victim) )
        dam *= 2;
     else if (victim->position < POS_FIGHTING)
        dam = dam * 3 / 2;

    if ( dt == gsn_backstab && wield != NULL)
	{
        if ( wield->value[0] != 2 )
 	    dam *= 2 + ((ch->level + ch->drain_level) / 10) ;
        else
            dam *= 2 + ((ch->drain_level + ch->level) / 8);
        }

    if ( dt == gsn_ambush )
	dam *= 5/2 + ((ch->drain_level + ch->level) / 6 );


    mdam = GET_DAMROLL(ch);

/* Let's cut back on mage's damage a bit */

    dam += mdam * UMIN(100,skill) /100;

    if (!IS_NPC(ch))
    if (!str_cmp(class_table[ch->class].name,"monk"))
    {
	if (wield == NULL
	&& get_eq_char(ch,WEAR_DUAL_WIELD) == NULL)
	dam += (2*(ch->drain_level + ch->level)/5);
    }

    if (IS_NPC(victim) && victim->pIndexData->vnum == MOB_VNUM_HYDRA)
    {
	if (wield != NULL && wield->pIndexData->vnum == OBJ_VNUM_HYDRA_SLAYER)
		dam = dice(17,50);
    }

    if (IS_NPC(victim) && victim->pIndexData->vnum == MOB_VNUM_STALKER)
    {
	dam *= .6;
    }

    bcry = battlecry_multiplier(ch,dt);
    if (wield != NULL && wield->pIndexData->vnum == 23265)
	    if (check_cutter(ch,victim) > 1)
			dam += dice(10,3);

    if (bcry == 1 && wield == NULL)
    {
     if (check_palm(ch))
     {
	act("$n strikes a powerful open handed blow!",ch,0,0,TO_ROOM);
	act("You strike a powerful open handed blow!",ch,0,0,TO_CHAR);
	if ((ch->drain_level + ch->level) <= 39)
	{
	dam *= 3;
	dam /= 2;
	}
	else
	dam *= 2;
     }
    }

    if (bcry == 1 && ch->cabal != CABAL_RAVAGER)
	{
	if ((obj = get_eq_char(ch,WEAR_HANDS)) != NULL
	&& obj->pIndexData->vnum == 29711
	&& number_percent() < 10)
	{
	act("$n delivers a blow of deadly force!",ch,0,0,TO_ROOM);
	act("You deliver a blow of deadly force!",ch,0,0,TO_CHAR);
	bcry = 2;
	}
	}
    dam *= bcry;

    if ( (get_skill(ch,gsn_cblow) > 0) || (ch->level < skill_table[gsn_cblow].skill_level[ch->class]) )
	{
	  	if  ((wield != NULL)
			&& ((wield->value[0] == WEAPON_STAFF) || (wield->value[0] == WEAPON_AXE))
			&& (number_percent() < get_skill(ch,gsn_cblow)/3) )
		{
		    act("$n lands a crushing blow!",ch,0,0,TO_ROOM);
			act("You land a crushing blow!",ch,0,0,TO_CHAR);
			dam *=1.5;
			check_improve(ch,gsn_cblow,TRUE,2);
		}
	}

	if (wield != NULL && IS_WEAPON_STAT(wield,WEAPON_VORPAL) && number_percent() < 20)
	{
		act("$p emits a fierce red glow as it lashes violently at $N!",ch,wield,victim,TO_CHAR);
		act("$p emits a fierce red glow as it lashes violently at You!",ch,wield,victim,TO_VICT);
		act("$p emits a fierce red glow as it lashes violently at $N!",ch,wield,victim,TO_NOTVICT);
		dam *= 1.5;
	}

    if (wield != NULL && wield->pIndexData->vnum == OBJ_VNUM_AVENGER)
    {
	if (IS_WEAPON_STAT(wield,WEAPON_SHADOWBANE)
	&& number_percent() < 7)
	{
	act("$p flares and sears $N!",ch,wield,victim,TO_CHAR);
	act("$p flares and sears you!",ch,wield,victim,TO_VICT);
	act("$p flares and sears $N!",ch,wield,victim,TO_NOTVICT);
	dam *= 2;
	}
	if (IS_WEAPON_STAT(wield,WEAPON_LIGHTBRINGER)
	&& number_percent() < 10)
	{
	act("$p flares and sears $N!",ch,wield,victim,TO_CHAR);
	act("$p flares and sears you!",ch,wield,victim,TO_VICT);
	act("$p flares and sears $N!",ch,wield,victim,TO_NOTVICT);
	dam *= 3;
	dam /=2;
	}

	}

if (bcry == 1)
{
    if (wield != NULL && wield->pIndexData->vnum == 24309)
    {
	if (number_percent() < 6)
	{
	act("$n's $p lands a crushing blow!",ch,wield,0,TO_ROOM);
	act("Your $p lands a crushing blow!",ch,wield,0,TO_CHAR);
	dam *= 2;
	}
    }

/* sword of planes  and mace disruption .. go right before damage report*/
        if (wield != NULL && wield->pIndexData->vnum == OBJ_VNUM_SWORD_PLANES)
        {
        if (IS_NPC(victim)
        && ( IS_SET(victim->act,ACT_UNDEAD)
        || victim->pIndexData->vnum == MOB_VNUM_FIRE_ELEMENTAL
        || victim->pIndexData->vnum == MOB_VNUM_AIR_ELEMENTAL
        || victim->pIndexData->vnum == MOB_VNUM_WATER_ELEMENTAL
        || victim->pIndexData->vnum == MOB_VNUM_EARTH_ELEMENTAL
        || victim->pIndexData->vnum == MOB_VNUM_DRAGON
        || victim->pIndexData->vnum == MOB_VNUM_UNICORN
	|| is_name(victim->name,"demon")
	|| is_name(victim->name,"familiar")
        || is_name(victim->name,"golem") ) )
        {
        if (!(saves_spell(ch->level,victim,DAM_ENERGY))
        && (!saves_spell(ch->level + 3,victim,DAM_ENERGY))
        && (!saves_spell(wield->level,victim,DAM_OTHER))
	&& number_percent() < 50)
                {
act("$n's body suddenly crumples as $p draws $s lifeforce back to the outer planes!",
victim,wield,0,TO_ROOM);
raw_kill(ch,victim);
        return;
                }
        else if (IS_SET(victim->affected_by, AFF_SANCTUARY) )
                {
                dam += (dam/2);  /* partiallyNegates sanc */
                }
        }
        }
        else if (wield != NULL && wield->pIndexData->vnum == OBJ_VNUM_MACE_DISRUPTION)
        {
        if (IS_NPC(victim)
        && ( IS_SET(victim->act,ACT_UNDEAD)) )
        {
        if (!saves_spell(ch->level,victim,DAM_ENERGY)
        && !saves_spell(ch->level,victim,DAM_ENERGY)
        && !saves_spell(ch->level,victim,DAM_OTHER))
        {
        act("$N's body explodes under $n's mace of disruption!",ch,0,victim,TO_NOTVICT);
        act("$N's body explodes under your mace of disruption!",ch,0,victim,TO_CHAR);
        raw_kill(ch,victim);
        return;
        }
        else if (IS_SET(victim->affected_by,AFF_SANCTUARY))
                {
                        dam += (3* dam/4);
                }
        }
    }

    if (IS_NPC(ch)
	&& ch->pIndexData->vnum == 19000
	&& number_percent() < 4)
	{
act("$n bellows a cry and unleashes a mighty blow upon you!",ch,0,victim,TO_VICT);
act("$n bellows a cry and unleashes a mighty blow upon $N",ch,0,victim,TO_NOTVICT);
dam += dice(ch->level,3);
}
}

    if ( dam <= 0 )
        dam = 1;
    if((get_skill(ch,skill_lookup("truestrike")))>0 && (number_percent()<((get_skill(ch,skill_lookup("truestrike"))-40)/5)-3) && !(cabal_down(ch,CABAL_PROTECTOR)))
    {
      act("$n unleashes a blow of true accuracy, striking through your defenses!",ch,0,victim,TO_VICT);
      act("$n unleashes a blow of true accuracy, striking through $N's defenses!",ch,0,victim,TO_NOTVICT);
      act("You unleash a blow of true accuracy, striking through $N's defenses!",ch,0,victim,TO_CHAR);
	dam*=1;
	result = damage( ch, victim, dam, dt, DAM_TRUESTRIKE, TRUE );
      check_improve(ch,skill_lookup("truestrike"),TRUE,1);
    }
    else
    {
    result = damage( ch, victim, dam, dt, dam_type, TRUE );
    }
    check_outlaw_badge(ch);
    check_red_shield(ch);
    check_ceial_tat(ch);

    if (wield != NULL && wield->pIndexData->vnum == OBJ_VNUM_CLOWN_MALLET)
        check_clown_mallet(ch->level,ch,ch->fighting, wield);
    if (wield != NULL && wield->pIndexData->vnum == OBJ_VNUM_RANGER_STAFF)
	check_ranger_staff(ch,wield);
    if (wield != NULL && wield->pIndexData->vnum == OBJ_VNUM_DRAGON_WEAPON && dt!=gsn_tertiary_wield)
	golden_weapon(ch,wield);
    if (wield != NULL && wield->pIndexData->vnum == 8003)
	check_ranger_staff(ch,wield);	/* Staff of magi call */

if(isShifted(ch))
	{
		form = get_shifted(ch);
		dam = dice(form_table[form].dice_num, form_table[form].dice_type);
		dam += form_table[form].dice_add;

	}
    /* but do we have a funky weapon? */
    if (result && wield != NULL)
    {
        int dam;

        if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_POISON))
        {
            int level;
            AFFECT_DATA *poison, af;

            if ((poison = affect_find(wield->affected,gsn_poison)) == NULL)
                level = wield->level;
            else
                level = poison->level;

            if (!saves_spell(level / 2,victim,DAM_POISON))
            {
                send_to_char("You feel poison coursing through your veins.",
                    victim);
                act("$n is poisoned by the venom on $p.",
                    victim,wield,NULL,TO_ROOM);

		init_affect(&af);
                af.where     = TO_AFFECTS;
		af.aftype = AFT_SPELL;
                af.type      = gsn_poison;
                af.level     = level * 3/4;
                af.duration  = level / 2;
                af.location  = APPLY_STR;
                af.modifier  = -1;
                af.bitvector = AFF_POISON;
                affect_join( victim, &af );
            }

            /* weaken the poison if it's temporary */
            if (poison != NULL)
            {
                poison->level = UMAX(0,poison->level - 2);
                poison->duration = UMAX(0,poison->duration - 1);

                if (poison->level == 0 || poison->duration == 0)
                    act("The poison on $p has worn off.",ch,wield,NULL,TO_CHAR);
            }
        }


        if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_VAMPIRIC)
	&& number_percent() < 8)
        {
            dam = number_range(wield->level/2, wield->level);
            act("$p draws life from $n.",victim,wield,NULL,TO_ROOM);
            act("You feel $p drawing your life away.",
                victim,wield,NULL,TO_CHAR);
            damage_old(ch,victim,dam,0,DAM_NEGATIVE,FALSE);
            ch->hit = UMIN(ch->hit + dam, ch->max_hit);
        }

        if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_FLAMING)
	&& number_percent() < 15)
        {
            dam = number_range(1,wield->level / 4 + 1);
            act("$n is burned by $p.",victim,wield,NULL,TO_ROOM);
            act("$p sears your flesh.",victim,wield,NULL,TO_CHAR);
            fire_effect( (void *) victim,wield->level/2,dam,TARGET_CHAR);
            damage(ch,victim,dam,0,DAM_FIRE,FALSE);
        }

        if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_FROST)
	&& number_percent() < 15)
        {
            dam = number_range(1,wield->level / 6 + 2);
            act("$p freezes $n.",victim,wield,NULL,TO_ROOM);
            act("The cold touch of $p surrounds you with ice.",
                victim,wield,NULL,TO_CHAR);
            cold_effect(victim,wield->level/2,dam,TARGET_CHAR);
            damage(ch,victim,dam,0,DAM_COLD,FALSE);
        }

        if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_SHOCKING)
	&& number_percent() < 15)
        {
            dam = number_range(1,wield->level/5 + 2);
            act("$n is struck by lightning from $p.",victim,wield,NULL,TO_ROOM);
            act("You are shocked by $p.",victim,wield,NULL,TO_CHAR);
            shock_effect(victim,wield->level/2,dam,TARGET_CHAR);
            damage(ch,victim,dam,0,DAM_LIGHTNING,FALSE);
        }

    }
    tail_chain( );
    return;
}


void check_red_shield(CHAR_DATA *ch)
{
	OBJ_DATA *shield;
	shield = get_eq_char(ch,WEAR_SHIELD);
	if (shield == NULL)
	return;
	if (shield->pIndexData->vnum != 23728)
		return;
	if (number_percent() < 6)
	{
	act("The cross on $n's shield glows a soft red.",ch,shield,0,TO_ROOM);
	act("The cross on your shield glows a soft red.",ch,shield,0,TO_CHAR);
	obj_cast_spell(skill_lookup("cure critical"), 45, ch, ch, shield);
	}
	return;
}

void check_outlaw_badge(CHAR_DATA *ch)
{
	OBJ_DATA *badge;

    	badge = get_eq_char(ch,WEAR_NECK_1);
	if (badge == NULL)
		badge = get_eq_char(ch,WEAR_NECK_2);

    if (badge == NULL)
	return;
    if (badge->pIndexData->vnum == OBJ_VNUM_BADGE
	&& number_percent() < 8)
	{
	act("$n's $p glows bright blue!",ch,badge,0,TO_ROOM);
	act("Your $p glows bright blue!",ch,badge,0,TO_CHAR);
	obj_cast_spell(skill_lookup("cure critical"), badge->level, ch, ch, badge);
	}
    return;
}

void check_ceial_tat(CHAR_DATA *ch)
{
	OBJ_DATA *tattoo;

    tattoo = get_eq_char(ch,WEAR_BRAND);
    if (tattoo == NULL)
	return;
    if (tattoo->pIndexData->vnum == 72
	&& number_percent() < 3)
	{
	act("$n's $p begins to suck life from his opponent!",ch,tattoo,0,TO_ROOM);
	act("Your $p begins to suck the life out of your opponent!",ch,tattoo,0,TO_CHAR);
	obj_cast_spell(skill_lookup("cure critical"), tattoo->level, ch, ch, tattoo);
	}
    return;
}

void check_clown_mallet(int level, CHAR_DATA *ch, CHAR_DATA *victim, OBJ_DATA *wield)
{
   AFFECT_DATA af;

	if (number_percent() < 2)
        {
	if (wield->pIndexData->vnum == OBJ_VNUM_CLOWN_MALLET)
        {
        act("$p begins to eminate a haunting tune.",ch,wield,0,TO_ROOM);
        act("$p puts your foe to sleep!",ch,wield,0,TO_CHAR);
        }
        	init_affect(&af);
	        af.where     = TO_AFFECTS;
                af.type      = gsn_clown_mallet;
                af.aftype    = AFT_SKILL;
                af.level     = ch->level;
                af.duration  = 2;
                af.location  = 0;
                af.modifier  = 0;
                af.bitvector = AFF_SLEEP;
                affect_to_char( victim, &af );
		stop_fighting( victim, TRUE);
		stop_fighting( ch, TRUE);
		victim->position = POS_SLEEPING;
		ch->position = POS_STANDING;
	 }
    return;
}
/*
void check_clown_mallet(int level,CHAR_DATA *ch,CHAR_DATA *victim, OBJ_DATA *wield)
{
  AFFECT_DATA af;

	if (wield->pIndexData->vnum == OBJ_VNUM_CLOWN_MALLET)
  	{
	act("$n lands a devasating blow!",ch,wield,0,TO_ROOM);
	act("You land a devastating blow!",ch,wield,0,TO_CHAR);

		af.where     = TO_AFFECTS;
                af.type      = gsn_sleep;
                af.level     = ch->level;
                af.duration  = level / 2;
                af.location  = 0;
                af.modifier  = 0;
                af.bitvector = AFF_SLEEP;
                affect_to_char( victim, &af );
         }
    return;
}
*/
void check_ranger_staff(CHAR_DATA *ch,OBJ_DATA *wield)
{
	if (number_percent() < 7)
	{
	if (wield->pIndexData->vnum == OBJ_VNUM_RANGER_MAGIC)
  	{
	act("$p glows softly.",ch,wield,0,TO_ROOM);
	act("Your body warms as your staff restores you!",ch,wield,0,TO_CHAR);
	}
	else
	{
	act("$p glows a burning green!",ch,wield,0,TO_ROOM);
	act("Your staff of the magi glows burning green!",ch,wield,0,TO_CHAR);
	}

      ch->hit = UMIN( ch->hit + 75, ch->max_hit );
        }
    return;
}

void golden_weapon(CHAR_DATA *ch,OBJ_DATA *wield)
{
	if (number_percent() < 7  && ch->in_room->vnum!=ROOM_FORCE_DUEL)
	{
	act("$n's weapon glows brilliant gold.",ch,wield,0,TO_ROOM);
	act("Your body warms as your weapon heals you!",ch,wield,0,TO_CHAR);
        ch->hit = UMIN( ch->hit + 75, ch->max_hit );
	}

    return;
}

int avenger_multiplier(CHAR_DATA *ch,OBJ_DATA *wield)
{
    int avenge;

    avenge = 1;
    if (IS_EVIL(ch->fighting) && wield != NULL)
	{
	if (number_percent() < 7 && IS_WEAPON_STAT(wield,WEAPON_SHADOWBANE))
		avenge = 2;
	if (number_percent() < 7 && IS_WEAPON_STAT(wield,WEAPON_LIGHTBRINGER))
	avenge = 3/2;
	}

    return avenge;
}

int battlecry_multiplier(CHAR_DATA *ch, int dt)
{
    OBJ_DATA *obj;
    int battlecry;
    int chance;
    int mod;
    battlecry = 1;
    if (IS_NPC(ch))
	return 1;
    if (!is_affected(ch,gsn_battlecry) && !IS_NPC(ch))
	return 1;
    if (cabal_down(ch,CABAL_RAVAGER))
	return 1;
    if (IS_NPC(ch) && ch->pIndexData->vnum != MOB_VNUM_RAVAGER
	&& !is_affected(ch,gsn_battlecry))
	return battlecry;
    if (dt==gsn_flurry || dt==gsn_drum)
	return 1;
    if ((ch->drain_level + ch->level) < skill_table[gsn_battlecry].skill_level[ch->class]
	&& !IS_NPC(ch))
	return 1;

    if  ((obj = get_eq_char(ch,WEAR_HANDS)) != NULL
	&& obj->pIndexData->vnum == 29711)
	mod = 3;
	else mod = 0;
    if  (number_percent( ) > (mod + 14))
	return 1;

    chance = get_skill(ch,gsn_battlecry);
    if (IS_NPC(ch) )
	chance = 100;

    if (chance > 2)
    {
    if (number_percent( ) > (chance - 10) )
    	{
	send_to_char("You fail to deliver a blow of deadly force.\n\r",ch);
	if (ch->pcdata->learned[gsn_battlecry] < 100)
	{
send_to_char("You learn from your mistakes and become better at battlecry.\n\r",ch);
	ch->pcdata->learned[gsn_battlecry]++;
	}
    	}
    else
    	{
	send_to_char("You deliver a blow of deadly force!\n\r",ch);
	act("$n delivers a blow of deadly force!",ch,NULL,NULL,TO_ROOM);
	check_improve(ch,gsn_battlecry,TRUE,1);
    	if ((ch->drain_level + ch->level) <= 29) 	battlecry = 2;
   else if ((ch->drain_level + ch->level) <= 39) 	battlecry = 3;
   else if ((ch->drain_level + ch->level) <= 49)	battlecry = 4;
   else if ((ch->drain_level + ch->level) <= 59) 	battlecry = 5;
   else battlecry = 5;
	}
    }

    if (dt == gsn_circle)
	battlecry = UMIN(battlecry,3);
    if (dt == gsn_lunge)
	battlecry = UMIN(battlecry,3);
    if (dt == gsn_backstab)
	battlecry = UMIN(battlecry,2);
    if (dt == gsn_dual_backstab)
	battlecry = UMIN(battlecry,2);
    if (dt == gsn_ambush)
	battlecry = UMIN(battlecry,2);
    if (dt == gsn_flurry)
	battlecry = 3;
    if (dt == gsn_drum)
	battlecry = 3;

    if (cabal_down(ch,CABAL_RAVAGER))
	battlecry = 1;

    return battlecry;
}



/*
 * Inflict damage from a hit.
 */
bool damage(CHAR_DATA *ch,CHAR_DATA *victim,int dam,int dt,int dam_type,
            bool show)
{
    OBJ_DATA *corpse;
    bool immune;
    OBJ_DATA *obj;
    OBJ_DATA *wield;
    bool kineticresult;
    int kineticdam;
    int originaldam;

    if ( victim->position == POS_DEAD )
        return FALSE;

    if (IS_NPC(ch) && spellbaned(ch,victim,dt))
	return FALSE;

    if (is_safe(ch,victim))
	return FALSE;

    originaldam=dam;
    /*
     * Stop up any residual loopholes.
     */
    if ( dam > 1500 && dt >= TYPE_HIT)
    {
        dam = 1500;

    }
    if ( victim != ch )
    {
        /*
         * Certain attacks are forbidden.
         * Most other attacks are returned.
         */
        if ( is_safe( ch, victim ) )
            return FALSE;
        check_killer( ch, victim );


        if ( victim->position > POS_STUNNED )
        {
            if ( victim->fighting == NULL )
            {
                set_fighting( victim, ch );
                if ( IS_NPC( victim ) && HAS_TRIGGER( victim, TRIG_KILL ) )
                    mp_percent_trigger( victim, ch, NULL, NULL, TRIG_KILL );
            }
            if (victim->timer <= 4)
                victim->position = POS_FIGHTING;
        }

        if ( victim->position > POS_STUNNED )
        {
            if ( ch->fighting == NULL )
                set_fighting( ch, victim );
        }

        /*
         * More charm stuff.
         */
        if ( victim->master == ch )
            stop_follower( victim );
    }

    if ( (dt >= TYPE_HIT || dt == gsn_dual_wield || dt == gsn_tertiary_wield)
	&& ch != victim)
    {


	if ( check_spin(ch,victim, dt))
            return FALSE;
        if ( check_parry( ch, victim, dt ) )
        {
		do_counter_parry(ch,victim,dt, dam);
		return FALSE;
	}
        if ( check_distance( ch, victim, dt ) )
            return FALSE;
	if ( check_block( ch, victim, dt) )
		return FALSE;
        if ( check_dodge( ch, victim, dt ) )
            return FALSE;
        if ( check_questdodge( ch, victim, dt ) )
            return FALSE;
        if ( check_shield_block(ch,victim, dt))
            return FALSE;
        if ( check_defiant_absorb(ch,victim,dt))
        	return FALSE;
        if (check_displacement( ch, victim))
	    return FALSE;
        if ( check_ironhands( ch, victim, dt ) )
			return FALSE;
		if ( check_unarmed_defense( ch, victim, dt ) )
			return FALSE;
	}
   //stuff for elementalist
   if (is_affected(victim,gsn_static_charge))
   {
	affect_strip(victim,gsn_static_charge);
	damage_old(victim,ch,victim->level * number_range(6,8),gsn_static_charge,DAM_LIGHTNING,TRUE);
   }
/* damage reduction */
    if (dam > 85)
    {
	dam = (dam - 85);
	dam *= 7;
	dam /= 10;
	dam += 85;
    }
    if (is_affected(victim,gsn_fireshield) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .65;
    if (is_affected(victim,gsn_wraithform) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .65;
    if (is_affected(victim,gsn_stoneskin) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .8;
    if (is_affected(victim,gsn_shield) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .8;
    if (is_affected(victim,gsn_kinetic_shield) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .75;
    if (is_affected(victim,gsn_barrier) && dt!=gsn_barrier && dam_type!=DAM_TRUESTRIKE)
	dam *= .50;

    if (is_affected(victim,gsn_shackles))
	dam *= 1.5;
    if (is_affected(victim, gsn_soften))
	dam *= 1.3;

    if (is_affected(ch,gsn_rage))
        dam *= 1.25;

    un_camouflage( ch, NULL);
    un_earthfade(ch,NULL);
    un_hide(ch, NULL);
    un_invis(ch, NULL);
    un_sneak(ch, NULL);
    un_duo(ch, NULL);
    /*
     * Damage modifiers.
     */
    //elemental shields
/*
    if (is_affected(victim, gsn_shield_of_flames))
	dam *= .9;
    if (is_affected(victim, gsn_shield_of_frost))
	dam *= .88;
    if (is_affected(victim, gsn_shield_of_bubbles))
	dam *= .86;
    if (is_affected(victim, gsn_shield_of_dust))
	dam *= .83;  //slightly more defensive
    if (is_affected(victim, gsn_shield_of_lightning))
	dam *= .86;
    if (is_affected(victim, gsn_shield_of_wind))
	dam *= .86;
	*/
    //orduno brand stuff
    if (is_affected(victim, gsn_body_of_wood))
    {
	dam /= 10;
	dam *= 9;
    }
    if (is_affected(victim, gsn_body_of_clay))
    {
	dam /= 10;
	dam *= 8;
    }
    if (is_affected(victim, gsn_body_of_iron))
    {
	dam /= 10;
	dam *= 7;
    }
    if (is_affected(victim, gsn_body_of_steel))
    {
	dam /= 10;
	dam *= 6;
    }
    if ((is_affected(victim, gsn_body_of_stone)) && (!is_affected(victim, gsn_ressist))
    && (!IS_AFFECTED(victim, AFF_SANCTUARY)))
    {
	dam /= 10;
	dam *= 5;
    }
    if (is_affected(victim, gsn_body_of_diamond))
    {
	dam /= 10;
	dam *= 4;
    }

    if ( dam > 1 && !IS_NPC(victim)
    &&   victim->pcdata->condition[COND_DRUNK]  > 10 )
        dam = 9 * dam / 10;

    if ( dam > 1 && IS_AFFECTED(victim, AFF_SANCTUARY) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
    {
    if ( (dt >= TYPE_HIT || dt == gsn_dual_wield || dt == gsn_tertiary_wield))
	{
	if (dt == gsn_dual_wield)
		wield = get_eq_char(ch,WEAR_DUAL_WIELD);
	else if (dt == gsn_tertiary_wield)
	wield = get_eq_char(ch,WEAR_TERTIARY_WIELD);
  	else
	wield = get_eq_char(ch,WEAR_WIELD);
	if (wield == NULL )
		dam /= 2;
	else if (wield->pIndexData->vnum != 29724)
        dam /= 2;
	}
    else
	dam /= 2;
    }

    if (is_affected(victim,gsn_shroud))
	dam *= 1;

    if (is_affected(victim,gsn_steel_nerves))
	dam *= .9;

    obj = get_eq_char(ch,WEAR_HEAD);
    if (obj != NULL
    && obj->pIndexData->vnum == OBJ_VNUM_TIARA
    && (dam_type == DAM_COLD || dam_type == DAM_FIRE
	|| dam_type == DAM_HOLY || dam_type == DAM_NEGATIVE
    || dam_type == DAM_ACID) )
	{
    if (dam > 125)
    {
	dam = (dam - 125);
	dam *= 6;
	dam /= 10;
	dam += 125;
    }
	}

    if (check_crown_blood(ch,victim,dt,dam,dam_type))
	return FALSE;

    if ((dt >= TYPE_HIT || dt==gsn_backstab || HITS) && (ch != victim) && (is_affected(victim,gsn_steel_nerves)) && dam > 1  && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
    {
	dam *= .8;
    }

    if ((dt >= TYPE_HIT || dt==gsn_backstab || HITS) && (ch != victim)
	&& dam > 1 && dam_type!=DAM_TRUESTRIKE)
    {
	dam -= dam*3/10;
    }

    if ( dam > 1 && ((IS_AFFECTED(victim, AFF_PROTECT_EVIL) && IS_EVIL(ch) )
    ||               (IS_AFFECTED(victim, AFF_PROTECT_GOOD) && IS_GOOD(ch) )) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
        dam -= dam / 4;

    if (is_affected(victim,gsn_spellbane) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
    {
	if (dam_type > 3)
		{
		dam *= 7;
		dam /= 10;
		}
    }

if (isShifted(victim))
	dam *= (victim->dam_reduc * 0.01);

    immune = FALSE;

    /* Check for absorb */
    if (check_absorb(ch,victim,dt))
	return FALSE;
    if (eye_of_beholder_absorb(ch,victim,dt,dam,dam_type))
	return FALSE;

    /*
     * Check for parry, and dodge.
     */

    switch(check_immune(victim,dam_type))
    {
        case(IS_IMMUNE):
            immune = TRUE;
            dam = 0;
            break;
        case(IS_RESISTANT):
	    if (IS_NPC(victim))
        	dam -= dam/3;
	    else
		dam -= dam/3;
            break;
        case(IS_VULNERABLE):
            dam += dam/3;
            break;
    }

    if (dt == gsn_dual_wield)
	wield = get_eq_char(ch,WEAR_DUAL_WIELD);
    else if ( dt == gsn_tertiary_wield )
	wield = get_eq_char(ch,WEAR_TERTIARY_WIELD);
    else wield = get_eq_char(ch,WEAR_WIELD);

    if (show)
        dam_message( ch, victim, dam, dt, immune );
   if ( (dt >= TYPE_HIT || dt == gsn_dual_wield || dt == gsn_tertiary_wield || dt == gsn_drum || dt==gsn_flurry)
	&& ch != victim)
    {
     if (is_affected(victim,gsn_kinetic_shield) && dam>0)
	{
	  if(number_percent()<67 || dam>150) {
        act("$n's kinetic shield reacts to $N's attack!",victim,0,ch,TO_NOTVICT);
        act("Your kinetic shield reacts to $N's attack!",victim,0,ch,TO_CHAR);
        act("$n's kinetic shield reacts to your attack!",victim,0,ch,TO_VICT);
	  kineticdam=originaldam*.15;
	  kineticresult = damage_old( victim, ch, kineticdam, gsn_kinetic_shield, DAM_ENERGY, TRUE );
	  }}
     if (is_affected(victim,gsn_self_immolation) && dam>0)
     {
	act("$N is burned by the flames surrounding $n!",victim,NULL,ch,TO_NOTVICT);
	act("$N is burned by the flames surrounding you!",victim,NULL,ch,TO_CHAR);
	act("You are burned by the flames engulfing $n!",victim,NULL,ch,TO_VICT);
	damage_old(victim,ch,number_range(30,100),gsn_flames,DAM_FIRE,
TRUE);
     }

    }
    if (dam == 0)
        return FALSE;

    /*
     * Hurt the victim.
     * Inform the victim of his new state.
     */
    victim->hit -= dam;
    if (dam_type == DAM_FIRE || dam_type == DAM_ACID)
	victim->noregen_dam += dam;
    if (victim->noregen_dam > victim->max_hit)
	victim->noregen_dam = victim->max_hit;

    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) && ch != 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),
                ch->in_room->vnum );
            log_string( log_buf );
	  }

            /*
             * Dying penalty:
             */

        raw_kill(ch, victim );


        /*
         * Death trigger
         */
        if ( IS_NPC( victim ) && HAS_TRIGGER( victim, TRIG_DEATH) )
        {
            victim->position = POS_STANDING;
            mp_percent_trigger( victim, ch, NULL, NULL, TRIG_DEATH );
        }
      if (!IS_NPC(ch)
        &&  (corpse = get_obj_list(ch,"corpse",ch->in_room->contents)) != NULL
        &&  corpse->item_type == ITEM_CORPSE_NPC && can_see_obj(ch,corpse))
        {
            OBJ_DATA *coins;

            corpse = get_obj_list( ch, "corpse", ch->in_room->contents );
            if ( IS_SET(ch->act, PLR_AUTOLOOT) &&
                 corpse && corpse->contains) /* exists and not empty */
                do_get( ch, "all corpse" );

            if (IS_SET(ch->act,PLR_AUTOGOLD) &&
                corpse && corpse->contains  && /* exists and not empty */
                !IS_SET(ch->act,PLR_AUTOLOOT))
                if ((coins = get_obj_list(ch,"gcash",corpse->contains)) != NULL)
                    do_get(ch, "all.gcash corpse");

            if ( IS_SET(ch->act, PLR_AUTOSAC) )
	{
              if ( IS_SET(ch->act,PLR_AUTOLOOT) && corpse && corpse->contains)
                return TRUE;  /* leave if corpse has treasure */
              else
                do_sacrifice( ch, "corpse" );
        }
	}
        return TRUE;
    }

    if ( victim == ch )
        return TRUE;

    /*
     * Take care of link dead people.
     */
    if ( !IS_NPC(victim) && victim->desc == NULL )
    {
        if ( number_range( 0, victim->wait ) == 0 )
        {
            do_recall( victim, "" );
            return TRUE;
        }
    }

    /*
     * Wimp out?
     */
    /*if ( IS_NPC(victim) && dam > 0 && victim->wait < PULSE_VIOLENCE / 2)
    {
        if ( ( IS_SET(victim->act, ACT_WIMPY) && number_bits( 2 ) == 0
        &&   victim->hit < victim->max_hit / 5)
        ||   ( IS_AFFECTED(victim, AFF_CHARM) && victim->master != NULL
        &&     victim->master->in_room != victim->in_room)
        && !is_centurion(victim) )
            do_flee( victim, "" );
    }*/

    if(ch->in_room != victim->in_room || dt == gsn_parting_blow)
    return TRUE;

    if ( IS_NPC(victim) && dam > 0 && victim->wait < PULSE_VIOLENCE / 2)
    {
        if ( (( IS_SET(victim->act, ACT_WIMPY) && number_bits( 2 ) == 0
        &&   victim->hit < victim->max_hit / 5))
        ||   (( IS_AFFECTED(victim, AFF_CHARM) && victim->master != NULL
        &&     victim->master->in_room != victim->in_room
 	      && !is_centurion(victim) )
        && dt != gsn_parting_blow))
            do_flee( victim, "" );
    }


    if (victim->level >= 30)
    {
    if ( !IS_NPC(victim)
    &&   victim->hit > 0
    &&   victim->hit <= victim->wimpy
    &&   victim->wait < PULSE_VIOLENCE / 2
    && dt != gsn_parting_blow)
         do_flee( victim, "" );
    }
    else
    {
    if ( !IS_NPC(victim)
    &&   victim->hit > 0
    &&   (victim->hit*100)/victim->max_hit <= victim->wimpy
    &&   victim->wait < PULSE_VIOLENCE / 2
    && dt != gsn_parting_blow)
        do_flee( victim, "" );
    }

    tail_chain( );
    return TRUE;
}



/*
 * Inflict damage from a hit.
 */
bool damage_old( CHAR_DATA *ch, CHAR_DATA *victim, int dam, int dt, int dam_type, bool show )
{

    OBJ_DATA *corpse;
    bool immune;
    OBJ_DATA *obj;
    OBJ_DATA *wield;
    bool kineticresult;
    int kineticdam;
    int originaldam;
    CHAR_DATA *owner = NULL;
    bool nosafe = FALSE;

    if ((dt == gsn_poison || dt == gsn_plague) && (ch != victim))
	{
	owner = ch;
	ch = victim;
	nosafe = TRUE;
	}

    if (!nosafe && is_safe(ch,victim))
	return FALSE;

    if ( victim->position == POS_DEAD )
        return FALSE;

    if (IS_NPC(ch) && spellbaned(ch,victim,dt))
		return FALSE;
    if (IS_NPC(victim) && victim->pIndexData->vnum == MOB_VNUM_RAVAGER)
    {
	if (spellbaned(ch,victim,dt))
		return FALSE;
    }

    if (is_safe(ch,victim))
	return FALSE;
    /*
     * Stop up any residual loopholes.
     */
    originaldam=dam;
    if ( dam > 1400 && dt >= TYPE_HIT)
    {
        bug( "Damage: %d: more than 1400 points!", dam );
        dam = 1400;
    }
   if ( victim != ch )
    {
        /*
         * Certain attacks are forbidden.
         * Most other attacks are returned.
         */
        if ( is_safe( ch, victim ) )
            return FALSE;
        check_killer( ch, victim );

    if ( (dt >= TYPE_HIT
	|| dt == gsn_backstab
	|| dt == gsn_ambush
	|| dt == gsn_cleave
	|| dt == gsn_deathstrike)
	&& ch != victim && dam_type!=DAM_TRUESTRIKE)
    {
	if (check_counter(ch,victim,dam,dt))
		return FALSE;
	if(is_affected(victim,gsn_steel_nerves) && dt!=gsn_kinetic_shield)
		dam*=.8;
	}
    if(dt==gsn_dual_backstab || HITS) {
	if(is_affected(victim,gsn_steel_nerves) && dam_type!=DAM_TRUESTRIKE)
	    dam=dam*6/10;
	}
        if ( victim->position > POS_STUNNED )
        {
            if ( victim->fighting == NULL )
                set_fighting( victim, ch );
            if (victim->timer <= 4)
                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 FALSE;
            }
        }

        /*
         * More charm stuff.
         */
        if ( victim->master == ch )
            stop_follower( victim );
    }

    /*
     * Inviso attacks ... not.
     */

    un_camouflage(ch,NULL);
    un_hide(ch, NULL);
    un_invis(ch, NULL);
    un_sneak(ch, NULL);

    if (( (dt >= TYPE_HIT || dt == gsn_dual_wield) || (dt == gsn_tertiary_wield) )
	&& ch != victim)
    {

        if ( check_parry( ch, victim, dt ) )
        {
		do_counter_parry(ch,victim,dt, dam);
		return FALSE;
	}
        //if ( check_flourintine( ch, victim, dt ) )
        //    return FALSE;
	if ( check_block( ch, victim, dt) )
		return FALSE;
        if ( check_dodge( ch, victim, dt ) )
            return FALSE;
        if ( check_questdodge( ch, victim, dt ) )
            return FALSE;
        if ( check_shield_block(ch,victim, dt))
            return FALSE;
        //if ( check_phase( ch, victim) )
        //    return FALSE;
	if (check_displacement( ch, victim))
            return FALSE;
        if ( check_spin(ch,victim, dt))
            return FALSE;
    }


    /* damage reduction */
    if (dam > 85)
    {
	dam = (dam - 85);
	dam *= 7;
	dam /= 10;
	dam += 85;
    }




    /*
     * Damage modifiers.
     */
    if (is_affected(ch, gsn_rage))
    {
	dam *= 5;
	dam /= 4;
    }
//elemental shields
    if (is_affected(victim, gsn_shield_of_flames))
        dam *= .9;
    if (is_affected(victim, gsn_shield_of_frost))
        dam *= .88;
    if (is_affected(victim, gsn_shield_of_bubbles))
        dam *= .86;
    if (is_affected(victim, gsn_shield_of_dust))
        dam *= .83;  //slightly more defensive
    if (is_affected(victim, gsn_shield_of_lightning))
        dam *= .86;
    if (is_affected(victim, gsn_shield_of_wind))
	dam *= .86;
 //orduno brand stuff
    if (is_affected(victim, gsn_body_of_wood))
    {
        dam /= 10;
        dam *= 9;
    }
    if (is_affected(victim, gsn_body_of_clay))
    {
        dam /= 10;
        dam *= 8;
    }
    if (is_affected(victim, gsn_body_of_iron))
    {
        dam /= 10;
        dam *= 7;
    }
    if (is_affected(victim, gsn_body_of_steel))
    {
        dam /= 10;
        dam *= 6;
    }
    if ((is_affected(victim, gsn_body_of_stone)) && (!is_affected(victim, gsn_steel_nerves))
    && (!IS_AFFECTED(victim, AFF_SANCTUARY)))
    {
        dam /= 10;
        dam *= 5;
    }
    if (is_affected(victim, gsn_body_of_diamond))
    {
        dam /= 10;
        dam *= 4;
    }

    if ( dam > 1 && !IS_NPC(victim)
    &&   victim->pcdata->condition[COND_DRUNK]  > 10 )
        dam = 9 * dam / 10;

    if ( dam > 1 && IS_AFFECTED(victim, AFF_SANCTUARY) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
    {
    if ( (dt >= TYPE_HIT || dt == gsn_dual_wield || dt == gsn_tertiary_wield))
	{
	if (dt == gsn_dual_wield)
		wield = get_eq_char(ch,WEAR_DUAL_WIELD);
	else if (dt == gsn_tertiary_wield)
	wield = get_eq_char(ch,WEAR_TERTIARY_WIELD);
  	else
	wield = get_eq_char(ch,WEAR_WIELD);
	if (wield == NULL )
		dam /= 2;
	else if (wield->pIndexData->vnum != 29724)
        dam /= 2;
	}
    else
	dam /=2;
    }

    obj = get_eq_char(ch,WEAR_HEAD);

    if (obj != NULL
    && obj->pIndexData->vnum == OBJ_VNUM_TIARA
    && (dam_type == DAM_COLD || dam_type == DAM_FIRE
	|| dam_type == DAM_HOLY || dam_type == DAM_NEGATIVE
    || dam_type == DAM_ACID) )
	{
    if (dam > 125)
    {
	dam = (dam - 125);
	dam *= 6;
	dam /= 10;
	dam += 125;
    }
	}
    if (is_affected(victim,gsn_fireshield) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .5;
    if (is_affected(victim,gsn_wraithform) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .6;
    if (is_affected(victim,gsn_stoneskin) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .7;
    if (is_affected(victim,gsn_shield) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .7;
    if (is_affected(victim,gsn_kinetic_shield) && dt!=gsn_kinetic_shield && dam_type!=DAM_TRUESTRIKE)
	dam *= .7;

    if (is_affected(victim,gsn_shackles))
	dam *= 1.5;

    if (is_affected(ch,gsn_rage_of_dioxide))
	dam *= 1.15;

     if (check_crown_blood(ch,victim,dt,dam,dam_type))
	return FALSE;

    if ( dam > 1 && ((IS_AFFECTED(victim, AFF_PROTECT_EVIL) && IS_EVIL(ch) )
    ||               (IS_AFFECTED(victim, AFF_PROTECT_GOOD) && IS_GOOD(ch) )) && dam_type!=DAM_TRUESTRIKE)
        dam -= dam / 4;

    immune = FALSE;

    if (check_absorb(ch,victim,dt))
	return FALSE;
    if (eye_of_beholder_absorb(ch,victim,dt,dam,dam_type))
	return FALSE;


    /*
     * Check for parry, and dodge.
     */

    switch(check_immune(victim,dam_type))
    {
        case(IS_IMMUNE):
            immune = TRUE;
            dam = 0;
            break;
        case(IS_RESISTANT):
	    if (IS_NPC(victim))
        	dam -= dam/3;
	    else
		dam -= dam/5;
            break;
        case(IS_VULNERABLE):
            dam += dam/3;
            break;
    }

    if (show)
        dam_message( ch, victim, dam, dt, immune );

   if ( (dt >= TYPE_HIT || dt == gsn_dual_wield || dt == gsn_tertiary_wield || dt == gsn_drum || dt==gsn_flurry)
	&& ch != victim)
    {
     if (is_affected(victim,gsn_kinetic_shield) && dam>0)
	{
	  if(number_percent()<67 || originaldam>175) {
        act("$n's kinetic shield reacts to $N's attack!",victim,0,ch,TO_NOTVICT);
        act("Your kinetic shield reacts to $N's attack!",victim,0,ch,TO_CHAR);
        act("$n's kinetic shield reacts to your attack!",victim,0,ch,TO_VICT);
	  kineticdam=originaldam*.15;
	  kineticresult = damage_old( victim, ch, kineticdam, gsn_kinetic_shield, DAM_ENERGY, TRUE );
	  }
      if (is_affected(victim,gsn_self_immolation) && dam>0)
     {
        act("$N is burned by the flames engulfing $n!",victim,NULL,ch,TO_NOTVICT);
        act("$N is burned by the flames engulfing you!",victim,NULL,ch,TO_CHAR);
        act("You are burned by the flames engulfing $n!",victim,NULL,ch,TO_VICT);
        damage_old(victim,ch,number_range(30,100),gsn_flames,DAM_FIRE, TRUE);
     }
      }
    }

    if (dam == 0)
        return FALSE;

    /*
     * Hurt the victim.
     * Inform the victim of his new state.
     */
    victim->hit -= dam;
    if (dam_type == DAM_FIRE || dam_type == DAM_ACID)
	victim->noregen_dam += dam;
    if (victim->noregen_dam > victim->max_hit)
	victim->noregen_dam = victim->max_hit;

    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) && ch != 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),
                ch->in_room->vnum );
            log_string( log_buf );
	}
            /*
             * Dying penalty:
             */

        raw_kill(ch, victim );
        /* RT new auto commands */
        if ( !IS_NPC(ch) && IS_NPC(victim) )
        {
            corpse = get_obj_list( ch, "corpse", ch->in_room->contents );

            if ( IS_SET(ch->act, PLR_AUTOLOOT) &&
                 corpse && corpse->contains) /* exists and not empty */
                do_get( ch, "all corpse" );

            if (IS_SET(ch->act,PLR_AUTOGOLD) &&
                corpse && corpse->contains  && /* exists and not empty */
                !IS_SET(ch->act,PLR_AUTOLOOT))
              do_get(ch, "gold corpse");

            if ( IS_SET(ch->act, PLR_AUTOSAC) )
	{
              if ( IS_SET(ch->act,PLR_AUTOLOOT) && corpse && corpse->contains)
                return TRUE;  /* leave if corpse has treasure */
              else
                do_sacrifice( ch, "corpse" );
        }
	}

        return TRUE;
    }

    if ( victim == ch )
        return TRUE;

    /*
     * Take care of link dead people.
     */
    if ( !IS_NPC(victim) && victim->desc == NULL )
    {
        if ( number_range( 0, victim->wait ) == 0 )
        {
            do_recall( victim, "" );
            return TRUE;
        }
    }

    /*
     * Wimp out?
     */
    if ( IS_NPC(victim) && dam > 0 && victim->wait < PULSE_VIOLENCE / 2)
    {
        if ( ( IS_SET(victim->act, ACT_WIMPY) && number_bits( 2 ) == 0
        &&   victim->hit < victim->max_hit / 5)
        ||   ( 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 < PULSE_VIOLENCE / 2 )
        do_flee( victim, "" );

    tail_chain( );
    return TRUE;
}

bool is_area_safe(CHAR_DATA *ch, CHAR_DATA *victim)
{
    if (victim->in_room == NULL || ch->in_room == NULL)
	return TRUE;
    if (victim == ch )
	return TRUE;
    if (victim->fighting == ch)
	return FALSE;
    if (IS_NPC(ch) && IS_GOOD(ch) && IS_GOOD(victim))
	return FALSE;
    if (IS_IMMORTAL(victim) && victim->invis_level > 2)
	return TRUE;
    if (IS_IMMORTAL(ch) && IS_IMMORTAL(victim) && victim->level > LEVEL_IMMORTAL && !is_same_group(ch,victim))
	return FALSE;
    if (IS_IMMORTAL(ch) && victim->level < ch->level && !is_same_group(ch,victim))
	return FALSE;

   /* killing mobiles */
    if (IS_NPC(victim))
    {
	if (IS_SET(victim->in_room->room_flags,ROOM_SAFE))
        {
	    send_to_char("Not in this room.\n\r",ch);
	    return TRUE;
	}
	if (is_same_group(ch,victim))
            return TRUE;
    }
    /* killing players */
    else
    {
        if (IS_SET(victim->in_room->room_flags,ROOM_SAFE))
        {
            send_to_char("Not in this room.\n\r",ch);
            return TRUE;
        }
        if (IS_NPC(ch) && ch->master != NULL && !IS_NPC(ch->master))
            return TRUE;
        if (IS_NPC(ch))
            return FALSE;
	if (is_same_group(ch,victim))
            return TRUE;

    }
    if (!IS_NPC(ch))
        ch->ghost = (time_t)NULL;
    return FALSE;
}

bool is_safe(CHAR_DATA *ch, CHAR_DATA *victim)
{
    if (victim->in_room == NULL || ch->in_room == NULL)
        return TRUE;

    if (IS_NPC(ch) && victim->invis_level >= LEVEL_HERO)
	return TRUE;

    if (!IS_NPC(ch))
	{
	if (ch->pcdata->death_status == HAS_DIED)
		return TRUE;
	}
    if (!IS_NPC(victim))
	{
	if (victim->pcdata->death_status == HAS_DIED)
		return TRUE;
	}

/* Handle Link dead players , only saves from PKS, not mobs -Ceran */
    if (!IS_NPC(victim) && victim->desc == NULL && !IS_NPC(ch)
	&& victim->fighting != ch && ch->fighting != victim)
	{
	act("The gods protect $N from $n.",ch,0,victim,TO_NOTVICT);
	act("The gods protect $N from you.",ch,0,victim,TO_CHAR);
	return TRUE;
 	}

/* Protect newbies. 1 hour max - Dioxide*/
    if (!IS_NPC(victim) && ((victim->played + current_time - victim->logon) < 3)
	&& !IS_NPC(ch) && ((ch->played + current_time - ch->logon) < 3))
	{
	act("The gods protect $N from $n.",ch,0,victim,TO_NOTVICT);
	act("The gods protect $N from you.",ch,0,victim,TO_CHAR);
	return TRUE;
 	}

    if (is_affected(victim,gsn_timestop))
    {
	act("$n is stuck in time and the gods protect $m.",victim,0,0,TO_ROOM);
	act("$N tries to do something but you are stuck in time and unaffected.",victim,0,ch,TO_CHAR);
	if (victim->fighting != NULL)
		victim->fighting = NULL;
	return TRUE;
    }

    if (victim->fighting == ch || victim == ch)
        return FALSE;

    if (IS_NPC(ch) && ch->last_fought == victim)
	return FALSE;


    if (victim->ghost > 0)
    {
	act("The gods protect $N from $n.",ch,0,victim,TO_NOTVICT);
	act("The gods protect you from $n.",ch,0,victim,TO_VICT);
	act("The gods protect $N from you.",ch,0,victim,TO_CHAR);
	return TRUE;
    }

    if (ch->ghost > 0)
    {
	if (!IS_NPC(victim))
	{
	act("The gods protect $N from $n.",ch,0,victim,TO_NOTVICT);
	act("The gods protect you from $n.",ch,0,victim,TO_VICT);
	act("The gods protect $N from you.",ch,0,victim,TO_CHAR);
		return TRUE;
	}
            if (IS_AFFECTED(victim,AFF_CHARM) && victim->master != NULL
		&& !IS_NPC(victim->master))
            {
  	act("The gods protect $N from $n.",ch,0,victim,TO_NOTVICT);
	act("The gods protect you from $n.",ch,0,victim,TO_VICT);
	act("The gods protect $N from you.",ch,0,victim,TO_CHAR);
                return TRUE;
            }

    }

    if (IS_IMMORTAL(ch) && is_affected(ch,gsn_riot) && !IS_NPC(victim))
    {
	send_to_char("You can't riot on mortals.\n\r",ch);
	return TRUE;
    }

    if (IS_IMMORTAL(ch) && ch->level > LEVEL_IMMORTAL)
        return FALSE;


    if (IS_SET(victim->act,PLR_CRIMINAL))
    {
	if (IS_NPC(ch) && ch->pIndexData->vnum == MOB_VNUM_VIGILANTE)
		return FALSE;
    }
    if(IS_NPC(victim)&&victim->pIndexData->vnum==MOB_VNUM_VIGILANTE)
	return FALSE;

    /* killing mobiles */
    if (IS_NPC(victim))
    {
        if (!IS_NPC(ch))
        {
            /* no charmed creatures unless in pk of master */
            if (IS_AFFECTED(victim,AFF_CHARM) && !can_pk(ch,victim->master) && !is_centurion(victim))
            {
  	act("The gods protect $N from $n.",ch,0,victim,TO_NOTVICT);
	act("The gods protect you from $n.",ch,0,victim,TO_VICT);
	act("The gods protect $N from you.",ch,0,victim,TO_CHAR);
                return TRUE;
            }
        }
	else
	{
	if (IS_AFFECTED(ch,AFF_CHARM) && IS_AFFECTED(victim,AFF_CHARM)
	&& !can_pk(ch->master,victim->master))
                return TRUE;
	}
    }
    /* killing players */
    else
    {
        /* NPC doing the killing */
        if (IS_NPC(ch))
        {
            /* charmed mobs and pets cannot attack players while owned */
            if (IS_AFFECTED(ch,AFF_CHARM) && ch->master != NULL
            &&  ch->master->fighting != victim && !is_centurion(ch)
            && !check_rangermob(ch))
            {
                send_to_char("Players are your friends!\n\r",ch);
                return TRUE;
            }
        }
        /* player doing the killing */
        else
        {
	    if (!can_pk(ch, victim))
    	    {
	if (!IS_IMMORTAL(victim)) {
  	act("The gods protect $N from $n.",ch,0,victim,TO_NOTVICT);
	act("The gods protect you from $n.",ch,0,victim,TO_VICT);
	act("The gods protect $N from you.",ch,0,victim,TO_CHAR);
		}
        	return TRUE;
    	    }
        }
    }
    return FALSE;
}

bool is_safe_spell(CHAR_DATA *ch, CHAR_DATA *victim, bool area )
{
    if (victim->in_room == NULL || ch->in_room == NULL)
        return TRUE;

    if (victim == ch && area)
        return TRUE;

    if (victim->fighting == ch || victim == ch)
        return FALSE;

    if (IS_IMMORTAL(ch) && ch->level > LEVEL_IMMORTAL && !area)
        return FALSE;

    /* killing mobiles */
    if (IS_NPC(victim))
    {
        /* safe room? */
        if (IS_SET(victim->in_room->room_flags,ROOM_SAFE))
            return TRUE;

        if (victim->pIndexData->pShop != NULL)
            return TRUE;

        /* no killing healers, trainers, etc */
        if (IS_SET(victim->act,ACT_TRAIN)
        ||  IS_SET(victim->act,ACT_PRACTICE)
        ||  IS_SET(victim->act,ACT_IS_HEALER)
        ||  IS_SET(victim->act,ACT_IS_CHANGER))
            return TRUE;

        if (!IS_NPC(ch))
        {
            /* no pets */
            if (IS_SET(victim->act,ACT_PET))
                return TRUE;

            /* no charmed creatures unless owner */
            if (IS_AFFECTED(victim,AFF_CHARM) && (area || ch != victim->master))
                return TRUE;

            /* legal kill? -- cannot hit mob fighting non-group member */
            if (victim->fighting != NULL && !is_same_group(ch,victim->fighting))
                return TRUE;
        }
        else
        {
            /* area effect spells do not hit other mobs */
            if (area && !is_same_group(victim,ch->fighting))
                return TRUE;
        }
    }
    /* killing players */
    else
    {
        if (area && IS_IMMORTAL(victim) && victim->level > LEVEL_IMMORTAL)
            return TRUE;

        /* NPC doing the killing */
        if (IS_NPC(ch))
        {
            /* charmed mobs and pets cannot attack players while owned */
            if (IS_AFFECTED(ch,AFF_CHARM) && ch->master != NULL
            &&  ch->master->fighting != victim)
                return TRUE;

            /* safe room? */
            if (IS_SET(victim->in_room->room_flags,ROOM_SAFE))
                return TRUE;

            /* legal kill? -- mobs only hit players grouped with opponent*/
            if (ch->fighting != NULL && !is_same_group(ch->fighting,victim))
                return TRUE;
        }

        /* player doing the killing */
        else
        {
            if (!is_cabal(ch))
                return TRUE;

            if (IS_SET(victim->act,PLR_KILLER) || IS_SET(victim->act,PLR_THIEF))
                return FALSE;

            if (!is_cabal(victim))
                return TRUE;

            if (ch->level > victim->level + 8)
                return TRUE;
        }

    }
    return FALSE;
}
/*
 * See if an attack justifies a KILLER flag.
 */
void check_killer( CHAR_DATA *ch, CHAR_DATA *victim )
{
    /*
     * Follow charm thread to responsible character.
     * Attacking someone's charmed char is hostile!
     */
    while ( IS_AFFECTED(victim, AFF_CHARM) && victim->master != NULL )
        victim = victim->master;

    /*
     * NPC's are fair game.
     * So are killers and thieves.
     */
    if ( IS_NPC(victim)
    ||   IS_SET(victim->act, PLR_KILLER)
    ||   IS_SET(victim->act, PLR_THIEF))
        return;

    /*
     * NPC's are cool of course (as long as not charmed).
     * Hitting yourself is cool too (bleeding).
     * So is being immortal (Alander's idea).
     * And current killers stay as they are.
     */
    if ( IS_NPC(ch)
    ||   ch == victim
    ||   ch->level >= LEVEL_IMMORTAL
    ||   !is_cabal(ch)
    ||   IS_SET(ch->act, PLR_KILLER)
    ||   ch->fighting  == victim)
        return;

    save_char_obj( ch );
    return;
}

/* Check a counter-parry */

void do_counter_parry(CHAR_DATA *ch,CHAR_DATA *victim,int dt, int dam)
{
	int chance;
	int tmp_dt;
	char *attack;
	OBJ_DATA *wield;
	char buf1[MAX_STRING_LENGTH];
	char buf2[MAX_STRING_LENGTH];

	if ((chance = get_skill(victim,gsn_counter_parry)) == 0
	|| IS_NPC(victim)
	|| victim->level < skill_table[gsn_counter_parry].skill_level[victim->class])
		return;

	chance /= 5;
	if (chance > 20)
		chance = 20;

	if (number_percent() < chance)
	{
    tmp_dt = TYPE_HIT;
    if (dt  == gsn_dual_wield)
    	wield = get_eq_char(ch,WEAR_DUAL_WIELD);
    else if (dt == gsn_tertiary_wield)
	wield = get_eq_char(ch,WEAR_TERTIARY_WIELD);
    else
	wield = get_eq_char(ch,WEAR_WIELD);


    if (wield != NULL)
	tmp_dt += wield->value[3];
    else
	tmp_dt += ch->dam_type;


    if (tmp_dt > TYPE_HIT && tmp_dt < TYPE_HIT + MAX_DAMAGE_MESSAGE)
	attack = attack_table[tmp_dt - TYPE_HIT].noun;
    else
	attack = attack_table[0].name;

    sprintf(buf1,"You counter parry $n's %s!",attack);
    sprintf(buf2,"$N counter parries your %s!",attack);
    act(buf1,ch,0,victim,TO_VICT);
    act(buf2,ch,0,victim,TO_CHAR);
        if (cabal_down(victim,CABAL_RAVAGER))
		return;

	damage_old(victim,ch,dam,gsn_counter_parry,TYPE_HIT,TRUE);
	check_improve(victim,gsn_counter_parry,TRUE,3);
	return;
	}

	check_improve(victim,gsn_counter_parry,FALSE,2);
	return;
}
bool check_displacement(CHAR_DATA *ch, CHAR_DATA *victim)
{
    int chance;

    if (!(is_affected(victim, gsn_displacement)))
	return FALSE;
    chance = get_skill(victim,gsn_displacement);
    chance /= 3;
    chance *= 2;

    if (!can_see(victim,ch))
	chance /=2;

    if (IS_AFFECTED(ch,AFF_DETECT_ILLUSION))
	chance /= 4;

    if (number_percent() > chance + victim->level - ch->level)
	return FALSE;

    act("$n's attack passes harmlessly through $N.",ch,NULL,victim,TO_NOTVICT);
    act("$n's attack misses you completely.",ch,NULL,victim,TO_VICT);
    act("Your attack passes harmlessly through $N.",ch,NULL,victim,TO_CHAR);
    return TRUE;
}

bool check_counter(CHAR_DATA *ch,CHAR_DATA *victim,int dam,int dt)
{
    int chance;

    if (dt == gsn_counter )
	return FALSE;
    if (dt == gsn_counter_parry)
	return FALSE;

    if (ch->fighting != NULL)
		return FALSE;

    if ( (chance = get_skill(victim,gsn_counter)) == 0
    || victim->level < skill_table[gsn_counter].skill_level[ch->class])
	return FALSE;

    if (!can_see(victim,ch))
	chance -= 30;
    if (get_eq_char(victim,WEAR_WIELD) == NULL)
	chance -= 50;
    chance += (victim->level - ch->level);

    if (victim->position != POS_FIGHTING && IS_AWAKE(victim))
    {
	if (number_percent() < chance)
	{
	act("You counter $n's attack!",ch,0,victim,TO_VICT);
	act("$N counters your attack!",ch,0,victim,TO_CHAR);
	act("$N counters $n's attack!",ch,0,victim,TO_NOTVICT);
	check_improve(victim,gsn_counter,TRUE,1);
	damage_old(victim,ch,dam,gsn_counter,TYPE_UNDEFINED,TRUE);
	return TRUE;
	}
    }

    check_improve(victim,gsn_counter,FALSE,2);
    return FALSE;
}



/*
 * Check for parry.
 */
bool check_parry( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
    int flourintine = 0;
    int chance;
    int tmp_dt;
    OBJ_DATA *wield;
    char buf1[MAX_STRING_LENGTH];
    char buf2[MAX_STRING_LENGTH];
    char *attack;
    OBJ_DATA *victimwield;

    if ( !IS_AWAKE(victim) )
        return FALSE;

    chance = get_skill(victim,gsn_parry) / 2;

    if ( get_eq_char( victim, WEAR_WIELD ) == NULL )
    {
        if (IS_NPC (victim) || isShifted(victim))
            chance /= 2;
        else
            return FALSE;
    }

    if (IS_AFFECTED(victim,AFF_BLIND))
        chance *= number_range(6/10,3/4);
    if (is_affected(victim,gsn_executioner))
	  chance+=20;
    if (is_affected(ch,gsn_rage_of_dioxide))
	  chance-=10;
    if (is_affected(victim,skill_lookup("haste")))
	  chance+=20;
    if (is_affected(ch,skill_lookup("haste")))
	  chance-=15;
    if (is_affected(victim,gsn_rage))
	chance *= .75;
/* The rest is all new dual wield stuff, with dam types displayed for
clarity when dual wielding - Ceran */
    tmp_dt = TYPE_HIT;
    if (dt  == gsn_dual_wield)
    	wield = get_eq_char(ch,WEAR_DUAL_WIELD);
    else if (dt == gsn_tertiary_wield)
	wield = get_eq_char(ch,WEAR_TERTIARY_WIELD);
    else
	wield = get_eq_char(ch,WEAR_WIELD);
    if (wield != NULL)
    {
    /* Weapons affect parrying. */
    switch (wield->value[0])
    {
	default:			chance+=15;		break;
	case (WEAPON_SWORD): 	chance+=5;		break;
	case (WEAPON_DAGGER): 	chance+=5;		break;
	case (WEAPON_SPEAR):	chance-=5;		break;
	case (WEAPON_STAFF):	chance-=5;		break;
	case (WEAPON_MACE):	chance-=5;		break;
	case (WEAPON_AXE):	chance-=5;		break;
	case (WEAPON_FLAIL):	chance+=10;		break;
	case (WEAPON_WHIP):	chance+=10;		break;
	case (WEAPON_POLEARM):	chance-=5;		break;
    }
    }
    if((victimwield=get_eq_char(victim,WEAR_WIELD)) != NULL)
    {
    switch (victimwield->value[0])
    {
	default:						break;
	case (WEAPON_SWORD): 	chance+=10; flourintine++; 		break;
	case (WEAPON_DAGGER): 	chance-=20;		break;
	case (WEAPON_SPEAR):	chance+=20;		break;
	case (WEAPON_STAFF):	chance+=10;		break;
	case (WEAPON_MACE):	chance-=20;		break;
	case (WEAPON_AXE):	chance-=25;		break;
	case (WEAPON_FLAIL):	chance-=10;		break;
	case (WEAPON_WHIP):	chance-=10;		break;
	case (WEAPON_POLEARM):	chance+=10;		break;
    }
    }

	if ((get_skill(victim,gsn_flourintine) > 0) && flourintine == 1)
	{
		check_improve(victim,gsn_flourintine,TRUE,1);
		chance += get_skill(victim,gsn_flourintine) / 7;
	}
i

Showing the first 100 KB of 339.9 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571