fight.c

kbkmud/src/fight.c · 317.6 KB

From the archive kbkmud.tar.gz

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                       *
***************************************************************************/
#include "include.h"

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

/*
 * Local functions.
 */
void 	check_downstrike 	args( ( CHAR_DATA *ch, CHAR_DATA *victim) );
void 	check_assist 		args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void	affect_join_obj		args(	(OBJ_DATA *obj, AFFECT_DATA *af)	);
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_fam		args( ( CHAR_DATA *ch, char *attack	)	);
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_spin 		args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
bool 	check_displacement 	args( ( CHAR_DATA *ch, CHAR_DATA *victim) );
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, char *dnoun, bool isPlural, bool showCharName) );
void    death_cry       	args( ( CHAR_DATA *ch ) );
void    group_gain      	args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
long	quest_credit_compute	args( ( CHAR_DATA *ch, CHAR_DATA *victim, int group_amount ) );
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    raw_kill_new		args( ( CHAR_DATA *ch, CHAR_DATA *victim, bool deathCry, bool fLook ) );
void    set_fighting    	args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void    disarm          	args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
void 	check_ground_control 	args( ( CHAR_DATA *ch,CHAR_DATA *victim,int chance,int dam) );
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 	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);
void 	do_arena_echo		( const char *txt);
int 	check_imperial_training	( CHAR_DATA *ch);
bool 	check_wall_thorns 	args( ( CHAR_DATA *ch));
void 	one_hit_new 		args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt, bool specials, bool blockable, int addition, int multiplier, char *dnoun));
bool 	damage_new 		args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dam, int dt, int dam_type, bool show, bool blockable, int addition, int multiplier, char *dnoun));
char *  weapon_name_lookup    args( ( int type) );

int 	con_multiplier		args( (int con, int dam) );
//Customizable dnoun, isPlural for singular or plural dverbs, showCharName (i.e. Zornath's blah or The blah), dealtByAffect for DoTs, keep_invisible to avoid revealing the ch
bool    damage_newer		args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dam, int dt, int dam_type, bool show, bool blockable, int addition, int multiplier, char *dnoun, bool isPlural, bool showCharName, AFFECT_DATA *dealtByAffect, bool keep_invisible ) );
int	damage_calculate	args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt, int dam_type, bool show, bool blockable, int addition, int multiplier) );
bool    check_blademaster     	args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) );
void 	check_restrike 		args( ( CHAR_DATA *ch, CHAR_DATA *victim));
bool 	check_ward_diminution	args( (CHAR_DATA *mage, CHAR_DATA *attacker, int dam, int type, int dt) );
bool	check_unholy_new	args( (CHAR_DATA *ch, CHAR_DATA *victim, OBJ_DATA *obj)	);
bool	is_affected_obj		args( (OBJ_DATA *obj, int sn)			);
void	check_paladin_combo	args( (CHAR_DATA *ch, CHAR_DATA *victim) );
float hitroll_multiplier	args( (CHAR_DATA *ch, CHAR_DATA *victim, float max_multiplier) );
bool check_shield_magnetism	args( ( CHAR_DATA *ch, CHAR_DATA *victim, int dt ));

 /*
 * 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 *obj;

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

	/* 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);
		}
	    }
	}

	//////// Begin Lich Quaff Potion Time Interval Messages ////////
	if (is_affected(ch,skill_lookup("lich elixir affect")))
	{
		AFFECT_DATA *lichAffect = affect_find(ch->affected,skill_lookup("lich elixir affect"));
		char buf[MSL];

		if (lichAffect->level == 59)
		{
			if (lichAffect->modifier == 8)
			{
				act("{BYou feel the elixir eating at your internal organs.{x",ch,0,0,TO_CHAR);
				lichAffect->modifier--;
			}
			else if (lichAffect->modifier == 6)
			{
				act("{BThin stripes of blackened energy play around you.{x",ch,0,0,TO_CHAR);
				lichAffect->modifier--;
			}
			else if (lichAffect->modifier == 4)
			{
				act("{BYour limbs, muscles, and bones seem to grow, the pain of transformation crippling you.{x",ch,0,0,TO_CHAR);
				lichAffect->modifier--;
			}
			else if (lichAffect->modifier == 2)
			{
				act("{BChunks of skin fall from your body, and suddenly the pain is gone.",ch,0,0,TO_CHAR);
				affect_strip(ch,skill_lookup("lich elixir affect"));
				ch->pcdata->learned[skill_lookup("minion tactics")] = 1;
     				ch->pcdata->learned[skill_lookup("minion sanc")] =1;
     				ch->pcdata->learned[skill_lookup("minion flight")] =1;
     				ch->pcdata->learned[skill_lookup("minion sneak")] =1;
     				ch->pcdata->learned[skill_lookup("minion recall")] =1;
     				ch->pcdata->learned[skill_lookup("minion haste")] =1;
     				ch->pcdata->learned[skill_lookup("minion trans")] =1;
				ch->pcdata->learned[skill_lookup("ritual of abominations")] = 1;
				ch->pcdata->learned[skill_lookup("vampiric touch")] = 1;
    
     				ch->race = race_lookup("lich");

    				ch->perm_stat[STAT_STR]=pc_race_table[ch->race].max_stats[STAT_STR];
        			ch->perm_stat[STAT_INT]=pc_race_table[ch->race].max_stats[STAT_INT];
       				ch->perm_stat[STAT_WIS]=pc_race_table[ch->race].max_stats[STAT_WIS];
        			ch->perm_stat[STAT_DEX]=pc_race_table[ch->race].max_stats[STAT_DEX];
        			ch->perm_stat[STAT_CON]=pc_race_table[ch->race].max_stats[STAT_CON];
    				ch->mod_stat[STAT_STR]=0;
    				ch->mod_stat[STAT_INT]=0;
    				ch->mod_stat[STAT_WIS]=0;
    				ch->mod_stat[STAT_DEX]=0;
    				ch->mod_stat[STAT_CON]=0;
    				sprintf(buf, "{RThe power of the undead courses through your veins as your soul becomes one with the Prime Negative Plane.{x\n\r");
				send_to_char(buf,ch);
				ch->ghost += 10;
			}
			else
				lichAffect->modifier--;
		}

		else if (lichAffect->level == 60)
		{
			if (lichAffect->modifier == 8)
			{
				act("{BYou feel the elixir eating at your internal organs.{x",ch,0,0,TO_CHAR);
				lichAffect->modifier--;
			}
			else if (lichAffect->modifier == 6)
			{
				act("{BThin stripes of blackened energy play around you.{x",ch,0,0,TO_CHAR);
				lichAffect->modifier--;
			}
			else if (lichAffect->modifier == 4)
			{
				act("{BYour limbs, muscles, and bones seem to grow, the pain of transformation crippling you.{x",ch,0,0,TO_CHAR);
				lichAffect->modifier--;
			}
			else if (lichAffect->modifier == 2)
			{

				act("{RJust as quickly, your body falls to the ground, the power leaving you.{x",ch,0,0,TO_CHAR);
				affect_strip(ch,skill_lookup("lich elixir affect"));
				if (!IS_IMMORTAL(ch))
					age_death(ch);
			}
			else
				lichAffect->modifier--;
		}
	}
	//////// End Lich Quaff Potion Time Interval Messages ////////

	if (ch->regen_rate != 0)
	{
	    if (ch->regen_rate > 0)
	  	regen = number_range(1,ch->regen_rate);
	    else
		regen = number_range(ch->regen_rate, -1);
	
		if (ch->regen_rate > 0) {
		    ch->hit = UMIN(ch->hit + regen,ch->max_hit);
			ch->mana = UMIN(ch->mana + regen / 2, ch->max_mana);
			ch->move = UMIN(ch->move + regen / 2, ch->max_move);
		}
		else {
		    ch->hit = UMAX(ch->hit + regen,0);
			ch->mana = UMAX(ch->mana + regen / 2, 0);
			ch->move = UMAX(ch->move + regen / 2, 0);
	    }
	}

        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;

	for (obj = ch->carrying;obj != NULL; obj = obj->next_content)
 	   if (IS_SET(obj->progtypes,IPROG_FIGHT))
		(obj->pIndexData->iprogs->fight_prog) (obj,ch);

	if (IS_SET(ch->progtypes,MPROG_FIGHT) && (ch->wait <= 0))
	   	(ch->pIndexData->mprogs->fight_prog) (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)
        {

	    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))
            {

            	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, dual_chance;
    char buf[MAX_STRING_LENGTH];

    if (is_affected(ch,gsn_timestop))
    {
	if (ch->fighting != NULL)
		ch->fighting = NULL;
	return;
    }

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

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

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

    if(ch->in_room!=victim->in_room)
    {
	ch->fighting		= NULL;
	victim->fighting	= NULL;
	ch->position		= POS_STANDING;
	victim->position	= POS_STANDING;
	update_pos(ch);
	update_pos(victim);
	return;
    }

    if(is_affected(victim,gsn_snare) && number_percent()<80 && 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);
    }


    if (ch->position < POS_RESTING)
        return;

    if (IS_NPC(ch))
    {
        mob_hit(ch,victim,dt);
        return;
    }

    if (IS_NPC(victim) && IS_CABAL_GUARD(victim) && !IS_NPC(ch) && (ch->pcdata->newbie==TRUE || ch->ghost > 0))
    {
		int attempt, door;
    		for ( attempt = 0; attempt < 6; attempt++ )
    		{
			EXIT_DATA *pexit;
    			ROOM_INDEX_DATA *was_in;
			door = number_door( );
			was_in = ch->in_room;
			if ( ( pexit = was_in->exit[door] ) == 0 || pexit->u1.to_room == NULL || pexit->u1.to_room->cabal>0)
	    			continue;
			act("$N growls with rage and throws you out of the room!",ch,0,victim,TO_CHAR);
			act("$N growls with rage and throws $n out of the room!",ch,0,victim,TO_ROOM);
        		char_from_room(ch);
        		char_to_room(ch, pexit->u1.to_room);
			do_look(ch,"auto");
			ch->ghost = 1;
			stop_fighting( victim, TRUE );
			return;
		}
    }

    if (IS_NPC(victim) && IS_CABAL_GUARD(victim) && !IS_NPC(ch) && ch->cabal==victim->cabal)
    {
	sprintf(buf,"How DARE you attack me, %s!",ch->name);
	do_cb(victim,buf);
    }

    // First hit.
    one_hit( ch, victim, dt );

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

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

    if (IS_AFFECTED(ch,AFF_HASTE) && (IS_NPC(ch) || get_skill(ch,gsn_third_attack)>5))
        one_hit(ch,victim,dt);

    chance = get_skill(ch,gsn_second_attack)/2 + GET_HITROLL(ch) / 5;
    dual_chance = get_skill(ch,gsn_dual_wield)/2 + GET_HITROLL(ch) / 5;

    if (is_affected(ch,gsn_maehslin) && number_percent() < 20)
    {
	act("The amber aura around $n intenses and their movements become more fluid!",ch,0,victim,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_new(ch,victim,dt,HIT_NOSPECIALS,HIT_UNBLOCKABLE,HIT_NOADD,HIT_NOMULT,NULL);
    }

//////////////////////////// Begin Critical Strike Check /////////////////////////////////
	if (number_percent() < ch->pcdata->learned[skill_lookup("critical strike")] / 6)
	{
		if (is_wielded(ch,WEAPON_SWORD,WIELD_PRIMARY) || is_wielded(ch,WEAPON_AXE,WIELD_PRIMARY) || is_wielded(ch,WEAPON_DAGGER,WIELD_PRIMARY) || is_wielded(ch,WEAPON_SPEAR,WIELD_PRIMARY) || is_wielded(ch,WEAPON_POLEARM,WIELD_PRIMARY) || is_wielded(ch,WEAPON_EXOTIC,WIELD_PRIMARY))
		{	
			act("You deliver a critical strike!",ch,0,0,TO_CHAR);
			act("$n delivers a critical strike!",ch,0,0,TO_ROOM);
			one_hit_new(ch,victim,dt,HIT_NOSPECIALS,HIT_UNBLOCKABLE,HIT_NOADD,175,"critical strike");
			if (!is_affected(victim,skill_lookup("critical strike")))
			{
				act("$n's critical strike tears open an immense gash in your body!",ch,0,victim,TO_VICT);
				act("$n's critical strike tears open an immense gash in $N's body!",ch,0,victim,TO_NOTVICT);
				act("Your critical strike tears open an immense gash in $N's body!",ch,0,victim,TO_CHAR);
				AFFECT_DATA bleeding;
				init_affect(&bleeding);
				bleeding.aftype = AFT_SKILL;
				bleeding.type = skill_lookup("critical strike");
				bleeding.affect_list_msg = str_dup("induces major bleeding");
				bleeding.owner_name = str_dup(ch->original_name);
				bleeding.duration = 3;
				if (is_wielded(ch,WEAPON_SWORD,WIELD_PRIMARY))
					bleeding.level = 3;
				else if (is_wielded(ch,WEAPON_AXE,WIELD_PRIMARY))
					bleeding.level = 4;
				else if (is_wielded(ch,WEAPON_DAGGER,WIELD_PRIMARY))
					bleeding.level = 2;
				else if (is_wielded(ch,WEAPON_POLEARM,WIELD_PRIMARY))
					bleeding.level = 5;
				else if (is_wielded(ch,WEAPON_SPEAR,WIELD_PRIMARY))
					bleeding.level = 6;
				else
					bleeding.level = 10;
				affect_to_char(victim,&bleeding);
			}
		}	
		else if (is_wielded(ch,WEAPON_FLAIL,WIELD_PRIMARY) || is_wielded(ch,WEAPON_MACE,WIELD_PRIMARY) || is_wielded(ch,WEAPON_STAFF,WIELD_PRIMARY) || is_wielded(ch,WEAPON_WHIP,WIELD_PRIMARY))
		{	
			act("You deliver a critical strike!",ch,0,0,TO_CHAR);
			act("$n delivers a critical strike!",ch,0,0,TO_ROOM);
			one_hit_new(ch,victim,dt,HIT_NOSPECIALS,HIT_UNBLOCKABLE,HIT_NOADD,175,"critical strike");
			if (!is_affected(victim,skill_lookup("critical strike")))
			{
				act("You feel your bones shatter under the force of $n's critical strike!",ch,0,victim,TO_VICT);
				act("$n's critical strike shatters $N's bones!",ch,0,victim,TO_NOTVICT);
				act("Your critical strike shatters $N's bones!",ch,0,victim,TO_CHAR);
				AFFECT_DATA boneshatter;
				init_affect(&boneshatter);
				boneshatter.aftype = AFT_SKILL;
				boneshatter.type = skill_lookup("critical strike");
				boneshatter.duration = 3;
				boneshatter.level = 1;
				boneshatter.owner_name = str_dup(ch->original_name);
				boneshatter.location = APPLY_STR;
				if (is_wielded(ch,WEAPON_FLAIL,WIELD_PRIMARY))
					boneshatter.modifier = -3;
				else if (is_wielded(ch,WEAPON_MACE,WIELD_PRIMARY))
					boneshatter.modifier = -4;
				else if (is_wielded(ch,WEAPON_STAFF,WIELD_PRIMARY))
					boneshatter.modifier = -3;
				else if (is_wielded(ch,WEAPON_WHIP,WIELD_PRIMARY))
					boneshatter.modifier = -2;
				else
					boneshatter.modifier = -1;
				affect_to_char(victim,&boneshatter);
				
				boneshatter.location = APPLY_DEX;
				if (is_wielded(ch,WEAPON_FLAIL,WIELD_PRIMARY))
					boneshatter.modifier = -3;
				else if (is_wielded(ch,WEAPON_MACE,WIELD_PRIMARY))
					boneshatter.modifier = -4;
				else if (is_wielded(ch,WEAPON_STAFF,WIELD_PRIMARY))
					boneshatter.modifier = -3;
				else if (is_wielded(ch,WEAPON_WHIP,WIELD_PRIMARY))
					boneshatter.modifier = -2;
				else
					boneshatter.modifier = -1;
				affect_to_char(victim,&boneshatter);
			}
		}
	}
//////////////////////////// End Critical Strike Check /////////////////////////////////			
			
//////////////////////////// Begin Anaconda Stance Fight Check /////////////////////////////////
    AFFECT_DATA *anacondaCheck = affect_find(ch->affected,gsn_stance), 
                *poisonCheck = affect_find(victim->affected,gsn_poison), 
		anacondaPoison;

    int poisonLevel = 51, poisonDuration = 3, strLoss = -1;

    if (anacondaCheck != NULL)
    {
	if (anacondaCheck->level == 5)
	{
		if (number_percent() < 15)
		{
				act("$n strikes forward suddenly, piercing through your defenses!",ch,0,victim,TO_VICT);
				act("$n strikes forward suddenly, piercing through $N's defenses!",ch,0,victim,TO_NOTVICT);
				act("With the speed of an Anaconda, you penetrate $N's defenses!",ch,0,victim,TO_CHAR);
				one_hit_new(ch,victim,TYPE_UNDEFINED,HIT_NOSPECIALS,HIT_UNBLOCKABLE,HIT_NOADD,150,"serpent strike");
				if (poisonCheck != NULL)
				{
					if (!str_cmp(poisonCheck->name,"anaconda venom"))
					{
						poisonLevel = poisonCheck->level + 2;
						if (poisonCheck->duration < 20)
							poisonDuration = poisonCheck->duration + 3;
						else poisonDuration = poisonCheck->duration;
						strLoss = poisonCheck->modifier - 1;
						if (poisonLevel > 100)
							poisonLevel = 100;
						if (poisonDuration > 100)
							poisonDuration = 100;
						if (strLoss > 100)
							strLoss = 100;
						act("You feel your body tingle as poison seeps into your veins.",ch,0,victim,TO_VICT);
						act("$N looks very sick.",ch,0,victim,TO_NOTVICT);
						act("You release poison into $N's veins!",ch,0,victim,TO_CHAR);
						affect_remove(victim,poisonCheck);
						init_affect(&anacondaPoison);
						anacondaPoison.where 		= TO_AFFECTS;
						anacondaPoison.aftype		= AFT_SKILL;
						anacondaPoison.type		= gsn_poison;
						anacondaPoison.level		= poisonLevel;
						anacondaPoison.duration		= poisonDuration;
						anacondaPoison.name		= str_dup("anaconda venom");
						anacondaPoison.location		= APPLY_STR;
						anacondaPoison.modifier		= strLoss;
						anacondaPoison.owner_name		= str_dup(ch->original_name);
						anacondaPoison.bitvector	= AFF_POISON;
						affect_to_char(victim,&anacondaPoison);
					
					}
				}
				else if (poisonCheck == NULL)
				{
					act("You feel your body tingle as poison seeps into your veins.",ch,0,victim,TO_VICT);
					act("$N looks very sick.",ch,0,victim,TO_ROOM);
					act("You release poison into $N's veins!",ch,0,victim,TO_CHAR);
					init_affect(&anacondaPoison);
					anacondaPoison.where 		= TO_AFFECTS;
					anacondaPoison.aftype		= AFT_SKILL;
					anacondaPoison.type		= gsn_poison;
					anacondaPoison.level		= poisonLevel;
					anacondaPoison.duration		= poisonDuration;
					anacondaPoison.name		= str_dup("anaconda venom");
					anacondaPoison.modifier		= strLoss;
					anacondaPoison.owner_name		= str_dup(ch->original_name);
					affect_to_char(victim,&anacondaPoison);
				}
		}
	}
    }
//////////////////////////// End Anaconda Stance Fight Check /////////////////////////////////

    if (check_darkshout(ch) == DARKSHOUT_MEPHISTOPHELES && number_percent() < 40)
    {
        damage_new(ch, victim, 250, TYPE_UNDEFINED, DAM_FIRE, TRUE, HIT_UNBLOCKABLE, HIT_NOADD, HIT_NOMULT, "infernal wrath");
    }

    if (is_affected(ch,gsn_shield_of_truth) && get_eq_char(ch,WEAR_SHIELD) != NULL)
    {
	int healingCheck = number_percent();
	
	if (healingCheck <= 65)
	{
		act("The power of your god flows through your body, revitalizing you.",ch,0,0,TO_CHAR);
		act("$n looks more at peace as his wounds seem to heal.",ch,0,0,TO_ROOM);
	}
	if (healingCheck < 45)
		(*skill_table[skill_lookup("cure serious")].spell_fun) (skill_lookup("cure serious"), 51, ch, ch, TAR_CHAR_DEFENSIVE);
	if (healingCheck >= 45 && healingCheck < 57)
		(*skill_table[skill_lookup("cure critical")].spell_fun) (skill_lookup("cure serious"), 51, ch, ch, TAR_CHAR_DEFENSIVE);
	if (healingCheck >= 57 && healingCheck <= 65)
		(*skill_table[skill_lookup("heal")].spell_fun) (skill_lookup("heal"), 51, ch, ch, TAR_CHAR_DEFENSIVE);
    }

    if (IS_AFFECTED(ch,AFF_HASTE))
    {
	chance*=1.25;
	dual_chance*=1.25;
    }

    if (IS_AFFECTED(ch,AFF_SLOW))
    {
      	chance /= 2;
	dual_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;
    }

    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);
	}
    }

    chance = get_skill(ch,gsn_third_attack)/4 + GET_HITROLL(ch) / 10;

    if (IS_AFFECTED(ch,AFF_SLOW))
        chance = 0;
    if (IS_AFFECTED(ch,AFF_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 + GET_HITROLL(ch) / 10;
    if (IS_AFFECTED(ch,AFF_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);
	}
    }

    chance = get_skill(ch,gsn_fourth_attack)/5 + GET_HITROLL(ch) / 15;

    if (IS_AFFECTED(ch,AFF_SLOW))
	chance /= 2;
    if (IS_AFFECTED(ch,AFF_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 + GET_HITROLL(ch) / 15;
    if (IS_AFFECTED(ch,AFF_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);
	}
    }
	
	int off_chance = 3 * get_skill(ch,skill_lookup("unarmed offense")) / 4;
	if (IS_AFFECTED(ch,AFF_HASTE)) off_chance = 3 * off_chance / 2;
	if (check_imperial_training(ch) == IMPERIAL_OFFENSE) off_chance = 5 * off_chance / 4;
	
	if (get_eq_char(ch,WEAR_WIELD) == NULL && get_eq_char(ch,WEAR_DUAL_WIELD) == NULL &&
		ch->pcdata->learned[skill_lookup("unarmed offense")] > 10) {
		if (number_percent() < off_chance) {
			one_hit(ch,victim,dt);
			check_improve(ch,skill_lookup("unarmed offense"),TRUE,3);
			if (number_percent() < off_chance / 2) {
				one_hit(ch,victim,dt);
				check_improve(ch,skill_lookup("unarmed offense"),TRUE,5);
			}
		}
		else check_improve(ch,skill_lookup("unarmed offense"),FALSE,3);
	}

    if (is_affected(victim,gsn_blackjack)) 
    {
	affect_strip(victim,gsn_blackjack);
	return;
    }

    /* imperial training */
    if (check_imperial_training(ch) == IMPERIAL_OFFENSE && get_skill(ch,gsn_third_attack)>80)
	    one_hit(ch, victim, dt);

    int extraAttacks;
    if(ch->numAttacks > 0)
	for (extraAttacks = 1;extraAttacks<=ch->numAttacks;extraAttacks++)
		if (extraAttacks <= 20)
			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,AFF_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;
    	}

    	if (ch->pIndexData->vnum >= 28000 && ch->pIndexData->vnum <= 28011)
    	{
		int hits=number_range(1,2);
		int x;

		for (x=0; x<hits; x++)	
		{
	    		one_hit(ch,victim,dt);
	    		if (ch->fighting != victim)
	 			return;
		}
    	}

    	if (ch->wait > 0)
        	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;
    	}

    int extraAttacks;
    if(ch->numAttacks > 0)
	for (extraAttacks = 1;extraAttacks<=ch->numAttacks;extraAttacks++)
		if(extraAttacks <= 20)
			one_hit(ch,victim,dt);
}


/*
 * Hit one guy once.
 */
void one_hit(CHAR_DATA *ch, CHAR_DATA *victim, int dt)
{
	one_hit_new(ch,victim,dt,HIT_SPECIALS,HIT_BLOCKABLE,HIT_NOADD,HIT_NOMULT,NULL);
}

void one_hit_new( CHAR_DATA *ch, CHAR_DATA *victim, int dt, bool specials, bool blockable, int addition, int multiplier, char *dnoun)
{
    OBJ_DATA *wield;
    int dam, mdam, fchance, tchance, diceroll, diceroll2 = 0, sn, skill, dam_type, tmp_dt, tdt=dt;
    bool result, truestrike = FALSE, exeresult;
    const char *attack;
    char buf1[MAX_STRING_LENGTH], buf2[MAX_STRING_LENGTH], buf3[MAX_STRING_LENGTH];
	
    /* just in case */
    if (victim == ch || ch == NULL || victim == NULL)
        return;

    if(dt == TYPE_TRUESTRIKE)
    {
	truestrike = TRUE;
	dt = TYPE_UNDEFINED;
    }

    if ( victim->position == POS_DEAD || (ch->in_room != victim->in_room))
        return;

    if (is_safe(ch,victim))
	return;

    /*
     * Figure out the type of damage message.
     */
    wield = get_eq_char( ch, WEAR_WIELD );

    if ( dt == TYPE_UNDEFINED )
    {
        dt = TYPE_HIT;
        if ( wield != NULL && wield->item_type == ITEM_WEAPON )
            dt += wield->value[3];
        else 
            dt += ch->dam_type;

    }

    if(is_affected(ch,gsn_executioner) && number_percent()<5 && specials==TRUE && tdt==TYPE_UNDEFINED)
    {
      	act("$n darts forward and gracefully strikes you!",ch,0,victim,TO_VICT);
     	act("$n darts forward and gracefully strikes $N!",ch,0,victim,TO_NOTVICT);
      	act("Moving fluidly, you dart forward and gracefully strike $N!",ch,0,victim,TO_CHAR);
		one_hit_new( ch, victim, TYPE_UNDEFINED, HIT_NOSPECIALS, HIT_UNBLOCKABLE, HIT_NOADD, HIT_NOMULT, NULL);
		return;
    }
    if(is_affected(victim,gsn_executioner) && number_percent()<7 && dt!=gsn_flurry && dt!=gsn_drum && specials==TRUE)
    {
        act("$n smoothly redirects $N's attack, unleashing a deadly riposte!",victim,0,ch,TO_NOTVICT);
        act("You smoothly redirect $N's attack, and unleash a deadly riposte!",victim,0,ch,TO_CHAR);
        act("$n smoothly redirects your attack, unleashing a deadly riposte!",victim,0,ch,TO_VICT);
		one_hit_new( victim, ch, TYPE_UNDEFINED, HIT_NOSPECIALS, HIT_UNBLOCKABLE, HIT_NOADD, HIT_NOMULT, NULL);
		return;
    }
	
    if (IS_NPC(ch) && ch->pIndexData->vnum == 3011)
	truestrike = TRUE;

    if(get_skill(victim,gsn_backfist) !=0 && specials==TRUE)
    {
		if (number_percent() < (get_skill(victim,gsn_backfist)/4) && count_hands(ch) < 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), gsn_backfist, DAM_BASH, TRUE );
			check_improve(victim,gsn_backfist,TRUE,2);
		}
		else
		{
			check_improve(victim,gsn_backfist,FALSE,5);
		}
    }

    if(is_affected(victim,gsn_shield_of_redemption) && get_eq_char(victim,WEAR_SHIELD) != NULL && number_percent() > 40)
	damage_new(victim, ch, number_range(20,30), TYPE_UNDEFINED, DAM_HOLY, TRUE, HIT_UNBLOCKABLE, HIT_NOADD, HIT_NOMULT, "shield of redemption");

    if (wield != NULL)
	dam_type = attack_table[wield->value[3]].damage;
    else
	dam_type = attack_table[ch->dam_type].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);

    if (dt == gsn_dual_wield)
    {
		wield = get_eq_char( ch, WEAR_DUAL_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(truestrike)
    	dam_type = DAM_TRUESTRIKE;

    if(victim->cabal==CABAL_KNIGHT && get_skill(victim,skill_lookup("blademaster"))>0 && specials==TRUE)
    {
	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)
	{
		attack = get_attack_noun(ch,dt);
		if(cabal_down_new(victim,CABAL_KNIGHT,FALSE))
			return;
	  	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);
		attack = get_attack_noun(victim,dt);
	  	one_hit_new( victim, ch, dt, HIT_NOSPECIALS, HIT_UNBLOCKABLE, HIT_NOADD, HIT_NOMULT, str_dup(attack));
		check_improve(victim, skill_lookup("blademaster"),TRUE,5);
	  	return;
	}
    }

    if((IS_NPC(victim) && IS_SET(victim->off_flags,OFF_FADE)) || is_affected(victim,gsn_displacement))
    {
	fchance = 25 + (victim->level - ch->level);
	if(IS_AFFECTED(ch,AFF_HASTE))
		fchance-=8;
	if(IS_AFFECTED(victim,AFF_HASTE))
		fchance+=5;
	if(number_percent()<fchance)
	{
	    attack = get_attack_noun(ch,dt);
	    sprintf(buf1,"$N's %s lands on empty air near $n.",attack);
	    act(buf1,victim,0,ch,TO_NOTVICT);
	    sprintf(buf2,"$N's %s lands on empty air near you.",attack);
            act(buf2,victim,0,ch,TO_CHAR);
	    sprintf(buf3,"Your %s lands on empty air near $n.",attack);
            act(buf3,victim,0,ch,TO_VICT);

	    if(!ch->fighting && !victim->fighting)
		set_fighting(ch,victim);

	    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 *= 1.2;
            }
        }
        else
       	    dam = number_range( 1 + GET_DAMROLL(ch) / 12 + 7 * skill/100, (ch->level - 5) * 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);

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

    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.2;
    }

    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 *= 1.5;
	}
	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 *= 1.7;
	}

    }

    if(!IS_NPC(ch) && ch->cabal == CABAL_RAGER 
    && !cabal_down_new(ch,CABAL_RAGER,FALSE) && number_percent()<=5 && specials==TRUE)
    {
	send_to_char("You land an especially devastating blow!\n\r",ch);
	act("$n lands an especially devastating blow!",ch,0,0,TO_ROOM);
	dam *= 3.5;
    }

    // Same as above, except for rager mobs.
    if (IS_NPC(ch) && ch->cabal == CABAL_RAGER && number_percent() < 15 && specials == TRUE
	&& (IS_CABAL_OUTER_GUARD(ch) || IS_CABAL_GUARD(ch)))
    {
        send_to_char("You land an especially devastating blow!\n\r",ch);
        act("$n lands an especially devastating blow!",ch,0,0,TO_ROOM);
        dam *= 3;
    }

    if ( dam <= 0 )
        dam = 1;

	//Bulwark of blades damage reflection -- Zornath
	if(is_affected(victim,skill_lookup("bulwark of blades"))) {
		int chance;
		AFFECT_DATA bulwark_bleed;
		
		if (get_skill(victim,skill_lookup("blade mastery")) < 1) chance = 30;
		else chance = 50;
		
		if (number_percent() < chance) {
			act("The blade barrier around $N dices your flesh as your strike $M!",ch,0,victim,TO_CHAR);
			act("The blade barrier around $N dices into $n's flesh!",ch,0,victim,TO_NOTVICT);
			act("The blade barrier around you dices into $n's flesh as $e strikes you!",ch,0,victim,TO_VICT);
		
			if (get_skill(victim,skill_lookup("blade mastery")) < 1)
				damage_newer(victim,ch,dam / 6,TYPE_UNDEFINED,DAM_SLASH,TRUE,HIT_UNBLOCKABLE,HIT_NOADD,HIT_NOMULT,"the dicing blades",SINGULAR,DAM_NOT_POSSESSIVE,NULL,FALSE);
			else {
				damage_newer(victim,ch,dam / 3,TYPE_UNDEFINED,DAM_SLASH,TRUE,HIT_UNBLOCKABLE,HIT_NOADD,HIT_NOMULT,"the dicing blades",SINGULAR,DAM_NOT_POSSESSIVE,NULL,FALSE);	
				
				//10% chance to add a bleed effect
				if (number_percent() < 10 && !is_affected(ch,skill_lookup("dicing wounds"))) {
					act("The blades dig deep into $n's flesh, unleashing a mist of blood!",ch,0,victim,TO_VICT);
					act("The blades dig deep into $n's flesh, unleashing a mist of blood!",ch,0,victim,TO_NOTVICT);
					act("The blades dig deep into your flesh, unleashing a spray of blood!",ch,0,victim,TO_CHAR);
					init_affect(&bulwark_bleed); 
					bulwark_bleed.aftype = TO_AFFECTS;
					bulwark_bleed.type = skill_lookup("dicing wounds");
					bulwark_bleed.duration = 3;
					bulwark_bleed.level = victim->level;
					bulwark_bleed.owner_name = str_dup(victim->original_name);
					bulwark_bleed.affect_list_msg = str_dup("bleeding uncontrollably");
					affect_to_char(ch,&bulwark_bleed);
				}
			}
		}
	}
	
    if(ch->cabal==CABAL_KNIGHT && get_skill(ch,skill_lookup("truestrike")) 
	&& number_percent()<((get_skill(ch,skill_lookup("truestrike"))-40)/5)-3 && !cabal_down_new(ch,CABAL_KNIGHT,FALSE) 
	&& specials==TRUE)
    {
      	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.5;
      	result = damage_new( ch, victim, dam, dt, DAM_TRUESTRIKE, TRUE, blockable, addition, multiplier,NULL);
      	check_improve(ch,skill_lookup("truestrike"),TRUE,1);
    }
    else
    	result = damage_new( ch, victim, dam, dt, dam_type, TRUE, blockable, addition, multiplier,dnoun);

    /* 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 = 10;
            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) && !IS_AFFECTED(victim,AFF_POISON)) 
            {
                send_to_char("You feel poison coursing through your veins.\n\r", 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_MALADY;
                af.type      = gsn_poison;
                af.level     = level * 3/4;
                af.duration  = level / 10;
                af.location  = APPLY_STR;
                af.modifier  = -6;
                af.bitvector = AFF_POISON;
				af.owner_name	= str_dup(ch->original_name);
                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->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,dt,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,dt,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,dt,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,dt,DAM_LIGHTNING,FALSE);
        }
    } // End special weapon flag if.

    tail_chain( );
    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;
}

/*
 * Inflict damage from a hit.
 */

bool damage(CHAR_DATA *ch,CHAR_DATA *victim,int dam,int dt,int dam_type, bool show) 
{
	return damage_new(ch, victim, dam, dt, dam_type, show, HIT_BLOCKABLE, HIT_NOADD, HIT_NOMULT, NULL);
}


bool damage_old( CHAR_DATA *ch, CHAR_DATA *victim, int dam, int dt, int dam_type, bool show )
{
	return damage_new(ch, victim, dam, dt, dam_type, show, HIT_BLOCKABLE, HIT_NOADD, HIT_NOMULT, NULL);
}

int con_multiplier(int con, int dam) {
	float damage = dam;
	switch(con) {
		case 25: damage *= 0.955; break;
		case 24: damage *= 0.96; break;
		case 23: damage *= 0.965; break;
		case 22: damage *= 0.97; break;
		case 21: damage *= 0.975; break;
		case 20: damage *= 0.98; break;
		case 19: damage *= 0.985; break;
		case 18: damage *= 0.99; break;
		case 17: damage *= 0.995; break;
		case 16: damage *= 1; break;
		case 15: damage *= 1.02; break;
		case 14: damage *= 1.04; break;
		case 13: damage *= 1.06; break;
		case 12: damage *= 1.08; break;
		case 11: damage *= 1.1; break;
		case 10: damage *= 1.12; break;
		case 9: damage *= 1.14; break;
		case 8: damage *= 1.16; break;
		case 7: damage *= 1.18; break;
		case 6: damage *= 1.2; break;
		case 5: damage *= 1.22; break;
		case 4: damage *= 1.24; break;
		case 3: damage *= 1.26; break;
		case 2: damage *= 1.35; break;
		case 1: damage *= 1.45; break;
		default: damage *= 2; break;
	}
	return (int)damage;
}

float calculate_ac_redux(int ac) {
	float ac_mod = 0;
	//If <75% reduction
	if (ac > AC_PER_ONE_PERCENT_DECREASE_DAMAGE * 75) 
		//Damage modifier is AC divided by some predefined constant that can be tweaked to increase or decrease the effectiveness of AC. Zornath
		ac_mod = ((float)ac / (float)AC_PER_ONE_PERCENT_DECREASE_DAMAGE) / (float)100;
	//Otherwise asymptotically approach 100%
	else {
		//Finding a widening factor for (-1/x) + 100, so that redux asymptotically approaches 100 
		long widening_factor = -1 * AC_PER_ONE_PERCENT_DECREASE_DAMAGE * 75 * 25;
		long asymp_mod = widening_factor / ac + 100;
		ac_mod = (float)asymp_mod / (float)100;
	}
	return ac_mod;
}

bool damage_newer(CHAR_DATA *ch, CHAR_DATA *victim, int dam, int dt, int dam_type, bool show, bool blockable, int addition, int multiplier, char *dnoun, bool isPlural, bool showCharName, AFFECT_DATA *dealtByAffect, bool keep_invisible)
{
    OBJ_DATA *corpse;
    OBJ_DATA *obj;
    OBJ_DATA *wield;
    bool immune;
    int originaldam;
    CHAR_DATA *owner = NULL;
    bool nosafe = FALSE;
	int ac;
	
	dam = con_multiplier(get_curr_stat(victim,STAT_CON),dam);
	
	//Armor class affects damage taken now. Zornath
	switch(dt) {
		case DAM_PIERCE: ac = GET_AC(victim,AC_PIERCE); break;
		case DAM_SLASH: ac = GET_AC(victim,AC_SLASH); break;
		case DAM_BASH: ac = GET_AC(victim,AC_BASH); break;
		default: ac = GET_AC(victim,AC_EXOTIC); break;
	}
	
	dam -= dam * calculate_ac_redux(ac);
	
	//For damage dealt by affects such as poison, plague, etc., lookup the owner by name
	if (dealtByAffect) {
		owner = find_char_by_name(dealtByAffect->owner_name);
		ch = victim;
	}
	
    if ( victim->position == POS_DEAD )
        return FALSE;

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

	if (is_affected(ch,skill_lookup("valiant wrath")))
    {
		dnoun = str_dup("valiant wrath");
		dt += DAM_SOUND;
    }
	
	if (get_skill(ch,skill_lookup("elemental affinity")) > 75) {
		dam = (23 * dam) / 20;
	}

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


    originaldam=dam;
    /*
     * Stop up any residual loopholes.
     */

    if ( dam > 3000 && dt >= TYPE_HIT)
    {
        dam = 3000;
    }

    dam+=addition;

    if (multiplier != HIT_NOMULT) 
    {
	dam *= multiplier/100.1;
    }

    if (!IS_NPC(ch) && IS_SET(ch->act,PLR_MORON))
 	dam *= .50;

    if ( victim != ch && ch->in_room == victim->in_room)
    {
        /*
         * Certain attacks are forbidden.
         * Most other attacks are returned.
         */
        check_killer( ch, victim );

        if ( victim->position > POS_STUNNED && victim != ch && !((is_same_group(ch,victim) || is_safe(ch,victim)) && dnoun && dnoun[strlen(dnoun)-1] == '*'))
        {
            if ( victim->fighting == NULL )
                set_fighting( victim, ch );
            if (victim->timer <= 4)
                victim->position = POS_FIGHTING;
        }

        if ( victim->position > POS_STUNNED && victim != ch)
        {
            if ( ch->fighting == NULL && !((is_same_group(ch,victim) || is_safe(ch,victim)) && dnoun && dnoun[strlen(dnoun)-1] == '*'))
                set_fighting( ch, victim );
        }

        /*
         * More charm stuff.
         */
        if ( victim->master == ch && !(dnoun && dnoun[strlen(dnoun)-1] == '*'))
            stop_follower( victim );
    }

    if ( (dt >= TYPE_HIT || dt == gsn_dual_wield) && ch != victim && blockable==HIT_BLOCKABLE && ch->in_room == victim->in_room && dam>0) 
    {

	if (check_shield_magnetism(ch, victim, dt)) return FALSE;

	if (check_parry(ch,victim,dt))
	{
		(check_restrike(ch,victim));
		return FALSE;
	}		
        
	if (check_dodge(ch,victim,dt))			return FALSE;

	if (check_spin(ch,victim, dt))			return FALSE;

        if (check_distance(ch,victim,dt))		return FALSE;

	if (check_unarmed_defense(ch,victim,dt))	return FALSE;
		
	if (check_shield_block(ch,victim,dt))		return FALSE;

        if (check_questdodge(ch,victim,dt))		return FALSE;
	
	if (check_ironhands(ch,victim,dt))		return FALSE;
   }

   if (ch->enhancedDamMod >= 0)
   {
	dam *= (ch->enhancedDamMod / 100);
   }

   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 *= 8;
	dam /= 10;
	dam += 85;
    }

   if (is_affected(victim,gsn_soul_channel) && dam_type != DAM_TRUESTRIKE)
   {
	AFFECT_DATA *af;
	int start, level = 0;
	af = affect_find(victim->affected,gsn_soul_channel);
	for (start = 1; start <= level; start++)
	{
		dam *= .8;
	}
    }
    if (is_affected(victim,gsn_stoneskin) && dam_type!=DAM_TRUESTRIKE)
	dam *= .8;
    if (is_affected(victim,gsn_shield) && dam_type!=DAM_TRUESTRIKE)
	dam *= .95;
    if (is_affected(victim,gsn_barrier) && dam_type!=DAM_TRUESTRIKE)
	dam *= .5;
	if (is_affected(victim,skill_lookup("aura")) && dam_type != DAM_TRUESTRIKE)
		dam *= 0.7;
		
    if (is_affected(ch,gsn_rage) && dam_type!=DAM_TRUESTRIKE)
        dam *= 1.25;

    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;

    // Dragonplate
    obj = get_eq_char(ch,WEAR_BODY);
    if (obj != NULL && obj->pIndexData->vnum == OBJ_VNUM_DRAGONPLATE)
    {
	if(!IS_AFFECTED(victim, AFF_SANCTUARY) && dam_type!=DAM_TRUESTRIKE) {
		dam *= .75;
	}
    }

    // Armored carapace 
    obj = get_eq_char(victim,WEAR_ABOUT);
    if (obj!=NULL && obj->pIndexData->vnum==28015)
	dam *= .6;

    // Aura of Darkness
    obj = get_eq_char(victim,WEAR_BODY);
    if (obj!=NULL && obj->pIndexData->vnum==28017 && (dam_type==DAM_HOLY || dam_type==DAM_NEGATIVE))
	dam *= .4;

    /* Check for fire demon belt immunity */
    obj = get_eq_char(victim,WEAR_WAIST);
    if (obj!=NULL && obj->pIndexData->vnum==28016 && dam_type==DAM_FIRE)
	dam *= .4;

	if (victim->dam_mod < 20)
		dam *= 0.2;
	else dam *= (victim->dam_mod / 100.01);

    if (check_ward_diminution(victim, ch, dam, dam_type, dt))
	dam = 1;


	if (!keep_invisible) {
	    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.
     */
    if ( dam > 1 && IS_AFFECTED(victim, AFF_SANCTUARY) && dam_type!=DAM_TRUESTRIKE) {
		if (!is_affected(victim,skill_lookup("shroud")))
			dam /= 2;
		else dam *= 0.4;
	}

    immune = FALSE; 

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

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

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

    //ObsidianPalace
    if(IS_NPC(victim) && victim->pIndexData->vnum>28003 && victim->pIndexData->vnum<28012 && !IS_AFFECTED(victim,AFF_SANCTUARY))
	dam/=2;
    if(IS_NPC(victim) && victim->pIndexData->vnum==28006 && dam>10 && dam_type!=DAM_MENTAL)
	dam=number_range(5,25);

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


    if(wield && IS_SET(victim->vuln_flags, VULN_IRON) && !str_cmp(wield->material->name,"iron"))
	dam += dam / 3;
    if(wield && IS_SET(victim->vuln_flags, VULN_SILVER) && !str_cmp(wield->material->name,"silver"))
        dam += dam / 3;
	
	if (is_affected(victim,skill_lookup("divine transferrer"))) {
		AFFECT_DATA *af;
		CHAR_DATA *transferree;
		
		af = affect_find(victim->affected,skill_lookup("divine transferrer"));
		if ((transferree = find_char_by_name(af->owner_name)) != NULL) {
			if (transferree->in_room == ch->in_room) {
				if (is_affected(transferree,skill_lookup("divine transferree"))) {
					damage_newer(ch,transferree,dam/2,dt,dam_type,TRUE,HIT_UNBLOCKABLE,HIT_NOADD,HIT_NOMULT,"the divine transferrance",PLURAL,DAM_NOT_POSSESSIVE,NULL,FALSE);
					dam /= 2;
				}
			}
		}
	}
	

    if (showCharName)
    {
    	if (show && isPlural)
       		dam_message( ch, victim, dam, dt, immune, dnoun, PLURAL, DAM_POSSESSIVE );
    	else if (show && !isPlural)
       		dam_message( ch, victim, dam, dt, immune, dnoun, SINGULAR, DAM_POSSESSIVE );
    }
    else
    {
    	if (show && isPlural)
       		dam_message( ch, victim, dam, dt, immune, dnoun, PLURAL, DAM_NOT_POSSESSIVE );
    	else if (show && !isPlural)
       		dam_message( ch, victim, dam, dt, immune, dnoun, SINGULAR, DAM_NOT_POSSESSIVE );
    }

    if ( (dt >= TYPE_HIT || dt == gsn_dual_wield) && ch != victim)
    {
      	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(20,60),gsn_flames,DAM_FIRE, TRUE);
     	}

    }

    if (dam <= 0)
        return FALSE;

    /*
     * Hurt the victim.
     * Inform the victim of his new state.
     */
    if (is_affected(victim,skill_lookup("mana shield")) && victim->mana > dam)
    {
		victim->mana -= dam;
    }
    else if (is_affected(victim,skill_lookup("mana shield")) && victim->mana <= dam)
    {
		act("{rYour mana shield cannot withstand the force of $n's attack and shatters!{x",ch,0,victim,TO_VICT);
		act("{rThe mana shield around $N crumbles under your attack!{x",ch,0,victim,TO_CHAR);
		act("The mana shield around $N crumbles under $n's attack!",ch,0,victim,TO_NOTVICT);
		victim->hit -= (dam - victim->mana);
		victim->mana = 0;
		affect_strip(victim,skill_lookup("mana shield"));
		AFFECT_DATA shield_timer;
		init_affect(&shield_timer);
		shield_timer.aftype = AFT_MALADY;
		shield_timer.type = skill_lookup("mental exhaustion");
		shield_timer.duration = (ch->level / 5);
		shield_timer.affect_list_msg = str_dup("prevents usage of mana shield");
		affect_to_char(victim,&shield_timer);
    }
    else
    	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 
	&& !arena)
        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 )
    {
		if (owner)
			group_gain( owner, victim );
		else
			group_gain( ch, victim );

        if ( !IS_NPC(victim) )
        {
            sprintf( log_buf, "%s killed by %s at %ld", victim->name,
                (IS_NPC(ch) ? ch->short_descr : owner ? owner->name : ch->name), victim->in_room->vnum );
            log_string( log_buf );
		}

            /*
			* Dying penalty:
			*/

		if (owner)
	        raw_kill(owner, victim);
		else
	        raw_kill(ch, victim);

        /*
			* Death trigger
		*/
      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(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
	&& dt != gsn_cutoff))
	    do_flee( victim, "" );
    }

    if ( !IS_NPC(victim)
    &&   victim->hit > 0
    &&   victim->hit <= victim->wimpy
    &&   victim->wait < PULSE_VIOLENCE / 2 
    && dt != gsn_parting_blow)
        do_flee( victim, "" );

    tail_chain( );
    return TRUE;
}

bool damage_new(CHAR_DATA *ch, CHAR_DATA *victim, int dam, int dt, int dam_type, bool show, bool blockable, int addition, int multiplier, char *dnoun)
{
    return damage_newer(ch,victim,dam,dt,dam_type,show,blockable,addition,multiplier,dnoun,TRUE,TRUE, NULL, FALSE);
}

int damage_calculate(CHAR_DATA *ch, CHAR_DATA *victim, int dt, int dam_type, bool show, bool blockable, int addition, int multiplier)
{
    OBJ_DATA *obj;
    OBJ_DATA *wield;
    int diceroll, diceroll2 = 0;
    int sn, skill;
    int dam, mdam;
    bool immune;
    int originaldam;

    wield = get_eq_char( ch, WEAR_WIELD );
    sn = get_weapon_sn(ch);
    skill = 20 + get_weapon_skill(ch,sn);

    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 *= 1.2;
            }
        }
        else {
       	    dam = number_range( 1 + 7 * skill/100, (ch->level - 5) * skill/100);
			dam += GET_DAMROLL(ch) / 15; 
		}
    }


    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;
    } 

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

    originaldam=dam;
    if ( dam > 3000 && dt >= TYPE_HIT)
    {
        dam = 3000;
    }

    dam+=addition;

    if (multiplier != HIT_NOMULT) 
    {
	dam *= multiplier/100.1;
    }

    if (!IS_NPC(ch) && IS_SET(ch->act,PLR_MORON))
 	dam *= .50;

    if ( (dt >= TYPE_HIT || dt == gsn_dual_wield) && ch != victim && blockable==HIT_BLOCKABLE && ch->in_room == victim->in_room && dam>0) 
    {	
   }

   if (ch->enhancedDamMod >= 0)
   {
	dam *= (ch->enhancedDamMod / 100);
   }

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

    if (is_affected(victim,gsn_stoneskin) && dam_type!=DAM_TRUESTRIKE)
	dam *= .8;
    if (is_affected(victim,gsn_shield) && dam_type!=DAM_TRUESTRIKE)
	dam *= .95;
    if (is_affected(victim,gsn_barrier) && dam_type!=DAM_TRUESTRIKE)
	dam *= .5;
    if (is_affected(ch,gsn_rage) && dam_type!=DAM_TRUESTRIKE)
        dam *= 1.25;

    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;

    // Dragonplate
    obj = get_eq_char(ch,WEAR_BODY);
    if (obj != NULL && obj->pIndexData->vnum == OBJ_VNUM_DRAGONPLATE)
    {
	if(!IS_AFFECTED(victim, AFF_SANCTUARY) && dam_type!=DAM_TRUESTRIKE) {
		dam *= .75;
	}
    }

    // Armored carapace 
    obj = get_eq_char(victim,WEAR_ABOUT);
    if (obj!=NULL && obj->pIndexData->vnum==28015)
	dam *= .6;

    // Aura of Darkness
    obj = get_eq_char(victim,WEAR_BODY);
    if (obj!=NULL && obj->pIndexData->vnum==28017 && (dam_type==DAM_HOLY || dam_type==DAM_NEGATIVE))
	dam *= .4;

    /* Check for fire demon belt immunity */
    obj = get_eq_char(victim,WEAR_WAIST);
    if (obj!=NULL && obj->pIndexData->vnum==28016 && dam_type==DAM_FIRE)
	dam *= .4;

    if (dam_type!=DAM_TRUESTRIKE)
    	dam *= (victim->dam_mod / 100.01);

    if (check_ward_diminution(victim, ch, dam, dam_type, dt))
	dam = 1;


    /*
     * Damage modifiers.
     */
    if ( dam > 1 && IS_AFFECTED(victim, AFF_SANCTUARY) && dam_type!=DAM_TRUESTRIKE)
 	dam /= 2;

    immune = FALSE; 


    //ObsidianPalace
    if(IS_NPC(victim) && victim->pIndexData->vnum>28003 && victim->pIndexData->vnum<28012 && !IS_AFFECTED(victim,AFF_SANCTUARY))
	dam/=2;
    if(IS_NPC(victim) && victim->pIndexData->vnum==28006 && dam>10 && dam_type!=DAM_MENTAL)
	dam=number_range(5,25);

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


    if(wield && IS_SET(victim->vuln_flags, VULN_IRON) && !str_cmp(wield->material->name,"iron"))
	dam -= dam / 3;
    if(wield && IS_SET(victim->vuln_flags, VULN_SILVER) && !str_cmp(wield->material->name,"silver"))
        dam -= dam / 3;


    return dam;
}

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;
	}

    if(IS_NPC(ch) && IS_NPC(victim) && !IS_AFFECTED(ch,AFF_CHARM) && !IS_AFFECTED(victim,AFF_CHARM) && !ch->desc &&
	!ch->hunting && !victim->hunting && victim!=ch && !ch->desc && !victim->desc)
	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;
 	}

    if (!IS_NPC(victim) && victim->pcdata->newbie==TRUE && !IS_NPC(ch))
	{
	act("$N is too young for $n to harm.",ch,0,victim,TO_NOTVICT);
	act("$N is too young for you to harm.",ch,0,victim,TO_CHAR);
	act("You are too young for $n to harm.",ch,0,victim,TO_VICT);
	return TRUE;
 	}
    if (!IS_NPC(ch) && ch->pcdata->newbie==TRUE && !IS_NPC(victim))
	{
	act("$n is too young to harm $N.",ch,0,victim,TO_NOTVICT);
	act("You are too young to harm $N. Type newbie to change this.",ch,0,victim,TO_CHAR);
	act("$n is too young to harm you.",ch,0,victim,TO_VICT);
	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_ENFORCER)
		return FALSE;
    }
    if(IS_NPC(victim)&&victim->pIndexData->vnum==MOB_VNUM_ENFORCER)
	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))
            {
                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;

    if (!IS_NPC(victim) && victim->pcdata->newbie==TRUE && !IS_NPC(ch))
	  return TRUE;

    /* 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;
}

bool check_blademaster( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
    int chance;
    int tsn;
    char buf1[MAX_STRING_LENGTH];
    char buf2[MAX_STRING_LENGTH];
    char *attack;

    if ( !IS_AWAKE(victim) )
        return FALSE;
		

    tsn=skill_lookup("blademaster");
    chance = get_skill(victim,tsn) / 3;
    if(chance==0)
	  return FALSE;
    if ( get_eq_char( victim, WEAR_WIELD ) == NULL )
    {
        if (IS_NPC(victim))
            chance /= 2;
        else
            return FALSE;
    }
    if (IS_AFFECTED(victim,AFF_SLOW))
        chance*=.5;
    if (IS_AFFECTED(victim,AFF_HASTE))
	  chance+=8;

    if (check_imperial_training(ch) == IMPERIAL_OFFENSE)
		chance -= 20;
    if (check_imperial_training(ch) == IMPERIAL_DEFENSE)
		chance += 20;

    chance+=(get_curr_stat(victim,STAT_DEX))*.6;
    if(chance>50)
	chance=50;
    if ( number_percent( ) >= chance)
        return FALSE;
    attack=get_dam_message(ch,dt);
    sprintf(buf1,"You block $n's %s with an agile cross parry.",attack);
    sprintf(buf2,"$N blocks your %s with an agile cross parry.",attack);
    act(buf1,ch,0,victim,TO_VICT);
    act(buf2,ch,0,victim,TO_CHAR);
    check_improve(victim,tsn,TRUE,1);
    return TRUE;
}

//Hitroll vs hitroll check that returns the ratio between two characters' hitrolls, up to a predefined max_multiplier.
float hitroll_multiplier(CHAR_DATA *ch, CHAR_DATA *victim, float max_multiplier) {
	int ch_hitroll = GET_HITROLL(ch);
	int victim_hitroll = GET_HITROLL(victim);
	float hit_ratio;
	
	//Hitroll vs hitroll multiplier based on ratio
	if (victim_hitroll >= ch_hitroll) {
		hit_ratio = ch_hitroll == 0 ? ch_hitroll = 1 : ch_hitroll > 0 ? victim_hitroll / ch_hitroll : ch_hitroll / victim_hitroll;
		if (hit_ratio > max_multiplier)
			return max_multiplier;
		else 
			return hit_ratio;
	}
	return 1;
}

bool check_displacement(CHAR_DATA *ch, CHAR_DATA *victim)
{
    float chance, hit_ratio;
	int ch_hitroll, victim_hitroll;

    if (!(is_affected(victim, gsn_displacement)))
	return FALSE;
    chance = get_skill(victim,gsn_displacement);
    chance /= 1.5;
	
	ch_hitroll = GET_HITROLL(ch);
	victim_hitroll = GET_HITROLL(victim);
	
	//For simplicity...
	if (victim_hitroll <= 0) victim_hitroll = 1;
	if (ch_hitroll <= 0) ch_hitroll = 1;

	if (victim_hitroll < ch_hitroll) {
		hit_ratio = (float)ch_hitroll / (float)victim_hitroll;
		
		if (hit_ratio > 1.5)
			chance *= 1.5;
		else 
			chance *= hit_ratio;
	}

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

    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;
}

/*
 * Check for parry.
 */

bool check_parry( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
    OBJ_DATA *wield, *victimwield;
    char *attack, buf1[MSL], buf2[MSL];
    int flourintine=0, ch_hitroll, victim_hitroll, roll;
	float chance, hit_ratio;

    if ( !IS_AWAKE(victim) )
        return FALSE;

    chance = get_skill(victim,gsn_parry) / 2;
	
	ch_hitroll = GET_HITROLL(ch);
	victim_hitroll = GET_HITROLL(victim);
	
	//For simplicity...
	if (victim_hitroll <= 0) victim_hitroll = 1;
	if (ch_hitroll <= 0) ch_hitroll = 1;

	if (victim_hitroll < ch_hitroll) {
		hit_ratio = (float)ch_hitroll / (float)victim_hitroll;
		
		if (hit_ratio > 1.25)
			chance *= 1.25;
		else 
			chance *= hit_ratio;
	}

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

    if (IS_AFFECTED(victim,AFF_BLIND))
        chance *= .75;

    if (IS_AFFECTED(victim,AFF_HASTE))
	  chance+=20;

    if (IS_AFFECTED(ch,AFF_HASTE))
	  chance-=15;

    chance-=5*abs((ch->size-victim->size));

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

    if (wield != NULL)
    {
    	switch (wield->value[0])
    	{
		case (WEAPON_SWORD): 	chance+=5;		break;
		case (WEAPON_DAGGER): 	chance-=5;		break;
		case (WEAPON_SPEAR):	chance+=0;		break;
		case (WEAPON_STAFF):	chance+=0;		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;
		default: break;
    	}
    }

    if((victimwield=get_eq_char(victim,WEAR_WIELD)) != NULL)
    {
    	switch (victimwield->value[0])
    	{
		case (WEAPON_SWORD): 	chance+=10; flourintine++;		break;
		case (WEAPON_DAGGER): 	chance-=20;		break;
		case (WEAPON_SPEAR):	chance+=15;		break;
		case (WEAPON_STAFF):	chance+=15;		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+=10;		break;
		default: break;
    	}	
    }
	
    if ((get_skill(victim,gsn_flourintine) > 0) && flourintine == 1) 
    {
	check_improve(victim,gsn_flourintine,TRUE,1);
	chance += get_skill(victim,gsn_flourintine) / 7;
    }

    /* imperial training */
    if (check_imperial_training(ch) == IMPERIAL_OFFENSE)
	chance -= 20;
    if (check_imperial_training(victim) == IMPERIAL_DEFENSE)
	chance += 20;
    if (check_imperial_training(victim) == IMPERIAL_OFFENSE)
	chance -= 20;
    if (check_imperial_training(ch) == IMPERIAL_DEFENSE)
	chance += 20;
        
    if (!IS_NPC(victim) && IS_SET(victim->act,PLR_MORON))
 	chance /= 2;
	
	switch(get_curr_stat(victim,STAT_STR)) {
		case 25: chance += 10; break;
		case 24: chance += 8; break;
		case 23: chance += 6; break;
		case 22: chance += 4; break;
		case 21: chance += 3; break;
		case 20: chance += 2; break;
		case 19: chance += 1; break;
		default: chance += 0; break;
	}

    chance+=attack_table[get_attack_number(ch,dt)].modifier;

    if (chance > 95)	
	chance = 95;

	attack = get_dam_message(ch,dt);
	roll = number_percent();
    if ( roll >= chance)
       return FALSE;

    if (chance - roll >= 40) {
		sprintf(buf1,"You masterfully deflect $n's %s with your %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
		sprintf(buf2,"$N masterfully deflects your %s with $S %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
	}
	else if (chance - roll >= 30) {
		sprintf(buf1,"You gracefully parry $n's %s with your %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
		sprintf(buf2,"$N gracefully parries your %s with $S %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
	}
	else if (chance - roll >= 20) {
		sprintf(buf1,"You parry $n's %s with your %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
		sprintf(buf2,"$N parries your %s with $S %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
	}
	else if (chance - roll >= 10) {
		sprintf(buf1,"You manage to parry $n's %s with your %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
		sprintf(buf2,"$N manages to parry your %s with $S %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
	}
	else {
		sprintf(buf1,"You barely manage to parry $n's %s with your %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
		sprintf(buf2,"$N barely manages to parry your %s with $S %s.",attack, victimwield ? weapon_name_lookup(victimwield->value[0]) : "hands");
	}
	
    act(buf1,ch,0,victim,TO_VICT);
    act(buf2,ch,0,victim,TO_CHAR);
    check_improve(victim,gsn_parry,TRUE,2);
    return TRUE;
}

bool check_block( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
    float chance, hit_ratio;
    int tmp_dt, ch_hitroll, victim_hitroll, roll;
    OBJ_DATA *wield;
    char buf1[MAX_STRING_LENGTH];
    char buf2[MAX_STRING_LENGTH];
    char *attack;

    if ( !IS_AWAKE(victim) )
        return FALSE;
    if (IS_NPC(victim))
	return FALSE;

    chance = get_skill(victim,gsn_block);

    if ( victim->level <skill_table[gsn_block].skill_level[victim->class])
  	return FALSE;

    chance /= 2.25;
	
	ch_hitroll = GET_HITROLL(ch);
	victim_hitroll = GET_HITROLL(victim);
	
	//For simplicity...
	if (victim_hitroll <= 0) victim_hitroll = 1;
	if (ch_hitroll <= 0) ch_hitroll = 1;

	if (victim_hitroll < ch_hitroll) {
		hit_ratio = (float)ch_hitroll / (float)victim_hitroll;
		
		if (hit_ratio > 1.25)
			chance *= 1.25;
		else 
			chance *= hit_ratio;
	}

    if (get_eq_char(victim,WEAR_WIELD) != NULL)
	return FALSE;

    if (!can_see(ch,victim))
        chance /= 2;
    if (is_affected(victim,gsn_rage))
        chance *= .75;
    if ( number_percent( ) >= chance + (victim->drain_level +  victim->level) - (ch->drain_level + ch->level) )
    {
	check_improve(victim,gsn_block,FALSE,5);
        return FALSE;
    }

/* 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
	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
    {
	bug("In check_block, bad dam message: dt %d.",tmp_dt);
	attack = attack_table[0].name;
    }

    if (chance - roll >= 40) {
		sprintf(buf1,"You masterfully deflect $n's %s with your hands.",attack);
		sprintf(buf2,"$N masterfully deflects your %s with $S hands.",attack);
	}
	else if (chance - roll >= 30) {
		sprintf(buf1,"You gracefully block $n's %s with your hands.",attack);
		sprintf(buf2,"$N gracefully blocks your %s with $S hands.",attack);
	}
	else if (chance - roll >= 20) {
		sprintf(buf1,"You block $n's %s with your hands.",attack);
		sprintf(buf2,"$N blocks your %s with $S hands.",attack);
	}
	else if (chance - roll >= 10) {
		sprintf(buf1,"You manage to block $n's %s with your hands.",attack);
		sprintf(buf2,"$N manages to block your %s with $S hands.",attack);
	}
	else {
		sprintf(buf1,"You barely manage to block $n's %s with your hands.",attack);
		sprintf(buf2,"$N barely manages to block your %s with $S hands.",attack);
	}
	
    act(buf1,ch,0,victim,TO_VICT);
    act(buf2,ch,0,victim,TO_CHAR);
    check_improve(victim,gsn_block,TRUE,6);
    return TRUE;
}

/*
 * Check for shield block.
 */

bool check_shield_block( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
    float chance, hit_ratio;
	int ch_hitroll, victim_hitroll, roll;
    char buf1[MAX_STRING_LENGTH];
    char buf2[MAX_STRING_LENGTH];
    char *attack;

    if ( !IS_AWAKE(victim) )
        return FALSE;

    if(victim->level < skill_table[gsn_shield_block].skill_level[victim->class])
	return FALSE;

    chance = (( get_skill(victim,gsn_shield_block) / 4) + 15);
	
	ch_hitroll = GET_HITROLL(ch);
	victim_hitroll = GET_HITROLL(victim);
	
	//For simplicity...
	if (victim_hitroll <= 0) victim_hitroll = 1;
	if (ch_hitroll <= 0) ch_hitroll = 1;

	if (victim_hitroll < ch_hitroll) {
		hit_ratio = (float)ch_hitroll / (float)victim_hitroll;
		
		if (hit_ratio > 1.35)
			chance *= 1.35;
		else 
			chance *= hit_ratio;
	}

	/* imperial training */
    if (check_imperial_training(ch) == IMPERIAL_OFFENSE)
	chance -= 10;
    if (check_imperial_training(victim) == IMPERIAL_DEFENSE)
	chance += 10;
    if (check_imperial_training(victim) == IMPERIAL_OFFENSE)
	chance -= 20;
    if (check_imperial_training(ch) == IMPERIAL_DEFENSE)
	chance += 20;

    if (is_affected(victim,gsn_shield_of_purity) && get_eq_char(victim,WEAR_SHIELD) != NULL)
	chance += 30;

    if (is_affected(victim,gsn_shield_of_justice) && get_eq_char(victim,WEAR_SHIELD) != NULL)
	chance -= 30;

	switch(get_curr_stat(victim,STAT_STR)) {
		case 25: chance += 13; break;
		case 24: chance += 10; break;
		case 23: chance += 9; break;
		case 22: chance += 7; break;
		case 20: chance += 4; break;
		case 19: chance += 2; break;
		default: chance += 0; break;
	}
	
	switch(get_curr_stat(victim,STAT_DEX)) {
		case 25: chance += 8; break;
		case 24: chance += 7; break;
		case 23: chance += 6; break;
		case 22: chance += 5; break;
		case 20: chance += 4; break;
		case 19: chance += 3; break;
		default: chance += 0; break;
	}
	
    if ( get_eq_char( victim, WEAR_SHIELD ) == NULL )
        return FALSE;
		

	roll = number_percent();
    if ( roll >= chance  )
        return FALSE;

    attack=get_dam_message(ch,dt);
	
    if (!is_affected(victim,gsn_shield_of_purity) && !is_affected(victim,gsn_shield_of_justice))
    {
    	sprintf(buf1,"You block $n's %s with your shield.",attack);
    	sprintf(buf2,"$N shield blocks your %s.",attack);
    }
    
    else if (is_affected(victim,gsn_shield_of_purity) && get_eq_char(victim,WEAR_SHIELD) != NULL)
    {
	sprintf(buf1,"Your god guides your shield into the path of $n's %s.",attack);
	sprintf(buf2,"$N gracefully deflects your %s with his divine shield.",attack);
    }

    else if (is_affected(victim,gsn_shield_of_justice) && get_eq_char(victim,WEAR_SHIELD) != NULL)
    {
	sprintf(buf1,"Blocking $n's %s with your divine shield, you execute a powerful counterattack!",attack);
	sprintf(buf2,"Blocking your %s with his divine shield, $N executes a powerful counterattack!",attack);
    }
	else {
		if (chance - roll >= 40) {
			sprintf(buf1,"You masterfully block $n's %s with your shield.",attack);
			sprintf(buf2,"$N masterfully blocks your %s with $S shield.",attack);
		}
		else if (chance - roll >= 30) {
			sprintf(buf1,"You gracefully block $n's %s with your shield.",attack);
			sprintf(buf2,"$N gracefully blocks your %s with $S shield.",attack);
		}
		else if (chance - roll >= 20) {
			sprintf(buf1,"You block $n's %s with your shield.",attack);
			sprintf(buf2,"$N blocks your %s with $S shield.",attack);
		}
		else if (chance - roll >= 10) {
			sprintf(buf1,"You manage to block $n's %s with your shield.",attack);
			sprintf(buf2,"$N manages to block your %s with $S shield.",attack);
		}
		else {
			sprintf(buf1,"You barely manage to block $n's %s with your shield.",attack);
			sprintf(buf2,"$N barely manages to block your %s with $S shield.",attack);
		}
	}

    act(buf1,ch,0,victim,TO_VICT);
    act(buf2,ch,0,victim,TO_CHAR);
    if (is_affected(victim, gsn_shield_of_justice) && get_eq_char(victim,WEAR_SHIELD) != NULL)
one_hit_new(victim,ch,TYPE_UNDEFINED,HIT_NOSPECIALS,HIT_UNBLOCKABLE,HIT_NOADD,200,"strike of justice");
    check_improve(victim,gsn_shield_block,TRUE,4);
    return TRUE;
}

/*
 * Check for dodge.
 */

bool check_dodge( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
    char buf1[MSL], buf2[MSL], *attack;
    int dex, dexa, fam, ch_hitroll, victim_hitroll, roll;
	float hit_ratio, chance;

    if ( !IS_AWAKE(victim) )
        return FALSE;

    chance = ( 3 * get_skill(victim,gsn_dodge) / 10);

    dex = get_curr_stat(victim,STAT_DEX);
    dexa= get_curr_stat(ch,STAT_DEX);
	
	ch_hitroll = GET_HITROLL(ch);
	victim_hitroll = GET_HITROLL(victim);
	
	//For simplicity...
	if (victim_hitroll <= 0) victim_hitroll = 1;
	if (ch_hitroll <= 0) ch_hitroll = 1;
	
	//Only increase the chance if the victim has more hitroll than the opponent. This is to prevent mage
	//classes from getting gibbed since they don't stack hitroll right now. Dodge will stay the same for
	//mages but increase for melee classes that utilize hitroll up to 1.5x the base chance, which can be at
	//most 30%. Zornath
	if (victim_hitroll < ch_hitroll) {
		hit_ratio = (float)ch_hitroll / (float)victim_hitroll;
		
		if (hit_ratio > 1.5)
			chance *= 1.5;
		else 
			chance *= hit_ratio;
	}

    if (dex <= 5)
	chance += 0;
    else if (dex <= 10)
	chance += dex/2;
    else if (dex <=15)
	chance += (2*dex/3);
    else if (dex <= 20)
	chance += dex;
    else
	chance += 3*dex/2;

    chance+=dex-dexa;
    chance+=(ch->size-victim->size)*5;

    if((fam = get_skill(ch,gsn_wilderness_fam) > 0) && isInWilderness(ch))
	chance += fam/2;

    /* imperial training */
    if (check_imperial_training(ch) == IMPERIAL_OFFENSE)
	chance -= 20;
    if (check_imperial_training(ch) == IMPERIAL_DEFENSE)
	chance += 20;
    if (check_imperial_training(victim) == IMPERIAL_OFFENSE)
	chance -= 20;
    if (check_imperial_training(victim) == IMPERIAL_DEFENSE)
	chance += 20;
    if (!can_see(victim,ch))
        chance /= 2;
    if (!IS_NPC(victim) && IS_SET(victim->act,PLR_MORON))
	chance /= 2;

    // haste/slow
    if (IS_AFFECTED(victim,AFF_HASTE))
	chance += 20;
    if (IS_AFFECTED(victim,AFF_SLOW))
	chance -= 20;
    if (IS_AFFECTED(ch,AFF_HASTE))
        chance -= 20;
    if (IS_AFFECTED(ch,AFF_SLOW))
        chance += 20;

    if (chance > 95)    
	chance = 95; 
	
	roll = number_percent();
    if ( roll >= chance)
        return FALSE;

    attack=get_dam_message(ch,dt);
    if (chance - roll >= 40) {
		sprintf(buf1,"You deftly dodge $n's %s.",attack);
		sprintf(buf2,"$N deftly dodges your %s.",attack);
	}
	else if (chance - roll >= 30) {
		sprintf(buf1,"You gracefully sidestep $n's %s.",attack);
		sprintf(buf2,"$N gracefully sidesteps your %s.",attack);
	}
	else if (chance - roll >= 20) {
		sprintf(buf1,"You dodge $n's %s.",attack);
		sprintf(buf2,"$N dodges your %s.",attack);
	}
	else if (chance - roll >= 10) {
		sprintf(buf1,"You manage to avoid $n's %s.",attack);
		sprintf(buf2,"$N manages to avoid your %s.",attack);
	}
	else {
		sprintf(buf1,"You barely escape $n's %s.",attack);
		sprintf(buf2,"$N barely escapes your %s.",attack);
	}
	

    if(isInWilderness(ch) && check_fam(ch,attack))
	return TRUE;

    act(buf1,ch,0,victim,TO_VICT);
    act(buf2,ch,0,victim,TO_CHAR);
    check_improve(victim,gsn_dodge,TRUE,5);
    return TRUE;
}

/*
 * Check for quest dodge.
 */

bool check_questdodge( CHAR_DATA *ch, CHAR_DATA *victim, int dt )
{
    float chance, hit_ratio;
    char buf1[MAX_STRING_LENGTH];
    char buf2[MAX_STRING_LENGTH];
    char *attack;
    int dex, dexa, ch_hitroll, victim_hitroll, roll;

    if ( !IS_AWAKE(victim) )
        return FALSE;

	if (get_skill(victim,gsn_questdodge) == 0)
		return FALSE;

	chance = ( 3 * get_skill(victim,gsn_questdodge) / 7);
	
	ch_hitroll = GET_HITROLL(ch);
	victim_hitroll = GET_HITROLL(victim);
	
	//For simplicity...
	if (victim_hitroll <= 0) victim_hitroll = 1;
	if (ch_hitroll <= 0) ch_hitroll = 1;

	if (victim_hitroll < ch_hitroll) {
		hit_ratio = (float)ch_hitroll / (float)victim_hitroll;
		
		if (hit_ratio > 1.3)
			chance *= 1.3;
		else 
			chance *= hit_ratio;
	}
    dex = get_curr_stat(victim,STAT_DEX);
    dexa= get_curr_stat(ch,STAT_DEX);
    if (dex <= 5)
	chance += 0;
    else if (dex <= 10)
	chance += dex/2;
    else if (dex <=15)
	chance += (2*dex/3);
    else if (dex <= 20)
	chance += (8*dex/10);
    else
	chance += dex;
    chance+=dex-dexa;
    chance+=(ch->size-victim->size)*5;
    if (is_affected(ch,gsn_executioner))
	  chance+=30;

	roll = number_percent();
    if ( roll >= chance)
      return FALSE;
    attack=get_dam_message(ch,dt);
	if (chance - roll >= 40) {
		sprintf(buf1,"You deftly evade $n's %s.",attack);
		sprintf(buf2,"$N deftly evades your %s.",attack);
	}
	else if (chance - roll >= 30) {
		sprintf(buf1,"You gracefully dart around $n's %s.",attack);
		sprintf(buf2,"$N gracefully darts around yo

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

Site Stats

Snippets: 1791
Codebases: 571