bool damage_acid( char_data* victim, char_data* ch, int damage, const char* string, bool plural ) { damage *= 100-victim->Save_Acid( ); damage /= 100; dam_message( victim, ch, damage, string, lookup( acid_index, damage, plural ) ); return inflict( victim, ch, damage, "acid" ); }
bool damage_shock( char_data* victim, char_data* ch, int damage, const char* string, bool plural ) { damage *= 100-victim->Save_Shock( ); damage /= 100; dam_message( victim, ch, damage, string, lookup( electric_index, damage, plural ) ); return inflict( victim, ch, damage, "shock" ); }
/* * Alert: As of bpl14, this function returns the following codes: * < 0 Victim died. * = 0 No damage. * > 0 How much damage done. */ int damage(struct char_data *ch, struct char_data *victim, int dam, int attacktype) { if (GET_POS(victim) <= POS_DEAD) { /* This is "normal"-ish now with delayed extraction. -gg 3/15/2001 */ if (PLR_FLAGGED(victim, PLR_NOTDEADYET) || MOB_FLAGGED(victim, MOB_NOTDEADYET)) return (-1); log("SYSERR: Attempt to damage corpse '%s' in room #%d by '%s'.", GET_NAME(victim), GET_ROOM_VNUM(IN_ROOM(victim)), GET_NAME(ch)); die(victim); return (-1); /* -je, 7/7/92 */ } /* peaceful rooms */ if (ch != victim && ROOM_FLAGGED(IN_ROOM(ch), ROOM_PEACEFUL)) { send_to_char(ch, "This room just has such a peaceful, easy feeling...\r\n"); return (0); } /* shopkeeper protection */ if (!ok_damage_shopkeeper(ch, victim)) return (0); /* You can't damage an immortal! */ if (!IS_NPC(victim) && (GET_LEVEL(victim) >= LVL_IMMORT)) dam = 0; if (victim != ch) { /* Start the attacker fighting the victim */ if (GET_POS(ch) > POS_STUNNED && (FIGHTING(ch) == NULL)) set_fighting(ch, victim); /* Start the victim fighting the attacker */ if (GET_POS(victim) > POS_STUNNED && (FIGHTING(victim) == NULL)) { set_fighting(victim, ch); if (MOB_FLAGGED(victim, MOB_MEMORY) && !IS_NPC(ch)) remember(victim, ch); } } /* If you attack a pet, it hates your guts */ if (victim->master == ch) stop_follower(victim); /* If the attacker is invisible, he becomes visible */ if (AFF_FLAGGED(ch, AFF_INVISIBLE | AFF_HIDE)) appear(ch); /* Cut damage in half if victim has sanct, to a minimum 1 */ if (AFF_FLAGGED(victim, AFF_SANCTUARY) && dam >= 2) dam /= 2; /* Check for PK if this is not a PK MUD */ if (!pk_allowed) { check_killer(ch, victim); if (PLR_FLAGGED(ch, PLR_KILLER) && (ch != victim)) dam = 0; } /* Set the maximum damage per round and subtract the hit points */ dam = MAX(MIN(dam, 100), 0); GET_HIT(victim) -= dam; /* Gain exp for the hit */ if (ch != victim) gain_exp(ch, GET_LEVEL(victim) * dam); update_pos(victim); /* * skill_message sends a message from the messages file in lib/misc. * dam_message just sends a generic "You hit $n extremely hard.". * skill_message is preferable to dam_message because it is more * descriptive. * * If we are _not_ attacking with a weapon (i.e. a spell), always use * skill_message. If we are attacking with a weapon: If this is a miss or a * death blow, send a skill_message if one exists; if not, default to a * dam_message. Otherwise, always send a dam_message. */ if (!IS_WEAPON(attacktype)) skill_message(dam, ch, victim, attacktype); else { if (GET_POS(victim) == POS_DEAD || dam == 0) { if (!skill_message(dam, ch, victim, attacktype)) dam_message(dam, ch, victim, attacktype); } else { dam_message(dam, ch, victim, attacktype); } } /* Use send_to_char -- act() doesn't send message if you are DEAD. */ switch (GET_POS(victim)) { case POS_MORTALLYW: act("$n is mortally wounded, and will die soon, if not aided.", TRUE, victim, 0, 0, CommTarget::TO_ROOM); send_to_char(victim, "You are mortally wounded, and will die soon, if not aided.\r\n"); break; case POS_INCAP: act("$n is incapacitated and will slowly die, if not aided.", TRUE, victim, 0, 0, CommTarget::TO_ROOM); send_to_char(victim, "You are incapacitated an will slowly die, if not aided.\r\n"); break; case POS_STUNNED: act("$n is stunned, but will probably regain consciousness again.", TRUE, victim, 0, 0, CommTarget::TO_ROOM); send_to_char(victim, "You're stunned, but will probably regain consciousness again.\r\n"); break; case POS_DEAD: act("$n is dead! R.I.P.", FALSE, victim, 0, 0, CommTarget::TO_ROOM); send_to_char(victim, "You are dead! Sorry...\r\n"); break; default: /* >= POSITION SLEEPING */ if (dam > (GET_MAX_HIT(victim) / 4)) send_to_char(victim, "That really did HURT!\r\n"); if (GET_HIT(victim) < (GET_MAX_HIT(victim) / 4)) { send_to_char(victim, "%sYou wish that your wounds would stop BLEEDING so much!%s\r\n", CCRED(victim, C_SPR), CCNRM(victim, C_SPR)); if (ch != victim && MOB_FLAGGED(victim, MOB_WIMPY)) do_flee(victim, NULL, 0, 0); } if (!IS_NPC(victim) && GET_WIMP_LEV(victim) && (victim != ch) && GET_HIT(victim) < GET_WIMP_LEV(victim) && GET_HIT(victim) > 0) { send_to_char(victim, "You wimp out, and attempt to flee!\r\n"); do_flee(victim, NULL, 0, 0); } break; } /* Help out poor linkless people who are attacked */ if (!IS_NPC(victim) && !(victim->desc) && GET_POS(victim) > POS_STUNNED) { do_flee(victim, NULL, 0, 0); if (!FIGHTING(victim)) { act("$n is rescued by divine forces.", FALSE, victim, 0, 0, CommTarget::TO_ROOM); GET_WAS_IN(victim) = IN_ROOM(victim); char_from_room(victim); char_to_room(victim, 0); } } /* stop someone from fighting if they're stunned or worse */ if (GET_POS(victim) <= POS_STUNNED && FIGHTING(victim) != NULL) stop_fighting(victim); /* Uh oh. Victim died. */ if (GET_POS(victim) == POS_DEAD) { if (ch != victim && (IS_NPC(victim) || victim->desc)) { if (AFF_FLAGGED(ch, AFF_GROUP)) group_gain(ch, victim); else solo_gain(ch, victim); } if (!IS_NPC(victim)) { mudlog(BRF, LVL_IMMORT, TRUE, "%s killed by %s at %s", GET_NAME(victim), GET_NAME(ch), world[IN_ROOM(victim)].name); if (MOB_FLAGGED(ch, MOB_MEMORY)) forget(ch, victim); } die(victim); return (-1); } return (dam); }
/* * Inflict damage from a hit. */ int damage(CHAR_DATA *ch,CHAR_DATA *victim,int dam,int dt,int dam_type, bool show, int agg, int combo) { /*OBJ_DATA *corpse;*/ bool immune; if ( victim->position == P_DEAD ) return P_DEAD; /* @@@@@ FIX TORPOR if ( victim->position == P_TORPOR ) return P_TORPOR; */ /* damage reduction */ if ( dam > 15) dam = (dam - 5)/2 + 5; if(IS_SET(ch->form, FORM_HORRID)) dam++; /* @@@@@ FIX BITE DAMAGE FOR SERPENTIS 3 if(is_affected(ch, skill_lookup("skin of the adder")) && dam_type == DAM_BITE) dam++; */ /* In case of -ve agg ratings */ if (agg < 0) agg = 0; /* soakage */ dam = do_soak(victim, dam, agg); if ( victim != ch ) { if ( victim->position > P_STUN ) { if ( victim->fighting == NULL ) { set_fighting( victim, ch ); if ( IS_NPC( victim ) && HAS_TRIGGER( victim, TRIG_KILL ) ) mp_percent_trigger( victim, ch, NULL, NULL, TRIG_KILL ); } if (victim->timer <= 4) victim->position = P_FIGHT; } if ( victim->position > P_STUN ) { if ( ch->fighting == NULL ) set_fighting( ch, victim ); } /* * More charm stuff. */ if ( victim->master == ch ) stop_follower( victim ); } /* * Inviso attacks ... not. */ if ( IS_AFFECTED(ch, AFF_INVISIBLE) ) { affect_strip( ch, gsn_invis ); REMOVE_BIT( ch->affected_by, AFF_INVISIBLE ); act( "$n fades into existence.", ch, NULL, NULL, TO_ROOM, 0 ); } /* * Damage modifiers. */ if ( dam > 1 && !IS_NPC(victim) && victim->condition[COND_DRUNK] > 10 ) dam = 9 * dam / 10; if ( dam > 1 && !IS_NPC(victim) && victim->condition[COND_HIGH] > 10 ) dam = 9 * dam / 10; if ( dam > 1 && ((IS_AFFECTED(victim, AFF_PROTECT_EVIL) && !IS_NATURAL(ch) )) ) dam -= dam / 4; immune = FALSE; /* * Check for parry, and dodge. if ( dt >= TYPE_HIT && ch != victim) { if ( check_parry( ch, victim ) ) return -1; if ( check_dodge( ch, victim ) ) return -1; } */ 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/2; break; } if (show) dam_message( ch, victim, dam, dt, immune, combo ); if(dam > (victim->health + victim->agghealth -7)) { victim->position = P_MORT; stop_fighting(ch, TRUE); } else if(dam == (victim->health + victim->agghealth -7)) { victim->position = P_INCAP; stop_fighting(ch, TRUE); } if (dam == 0) return -1; else if(IS_SET(ch->off_flags, BANDAGED)) REMOVE_BIT(ch->off_flags, BANDAGED); /* * Hurt the victim. * Inform the victim of his new state. */ if( (victim->race == race_lookup("vampire")) && (dt == DAM_FIRE) ) { victim->agghealth -= dam; update_pos( victim, UMAX(1, agg) ); if(agg <= 0) agg = 1; } else if( (victim->race == race_lookup("werewolf")) && (dt == DAM_SILVER) ) { victim->agghealth -= dam; update_pos( victim, UMAX(1, agg) ); if(agg <= 0) agg = 1; } else if( (victim->race == race_lookup("faerie")) && (dt == DAM_IRON) ) { victim->health -= dam; victim->GHB += dam/3; update_pos( victim, agg ); } else if(agg) { victim->agghealth -= dam; update_pos( victim, agg ); } else { victim->health -= dam; update_pos( victim, 0 ); } switch( victim->position ) { case P_MORT: act( "$n is mortally wounded, and will die soon, if not aided.", victim, NULL, NULL, TO_ROOM, 0 ); send_to_char("You are mortally wounded, and may die soon, if not aided.\n\r", victim ); break; case P_INCAP: act( "$n is incapacitated and will slowly die, if not aided.", victim, NULL, NULL, TO_ROOM, 0 ); send_to_char("You are incapacitated and will slowly die, if not aided.\n\r", victim ); break; case P_TORPOR: act( "$n is mortally wounded, and will slowly die if not aided.", victim, NULL, NULL, TO_ROOM, 0 ); send_to_char("You enter torpor.\n\r", victim ); break; case P_STUN: act( "$n is stunned, but will probably recover.", victim, NULL, NULL, TO_ROOM, 0 ); send_to_char("You are stunned, but will probably recover.\n\r", victim ); break; case P_DEAD: act( "$n is DEAD!!", victim, 0, 0, TO_ROOM, 0 ); send_to_char( "You have been KILLED!!\n\r\n\r", victim ); break; default: if ( dam > MAX_HEALTH / 4 ) send_to_char( "That really did HURT!\n\r", victim ); if ( (victim->health + victim->agghealth - 7) < MAX_HEALTH / 4 ) send_to_char( "You sure are BLEEDING!\n\r", victim ); break; } if(dam_type == DAM_FIRE) fire_effect((void *) victim, agg+dam/2, dam, TARGET_CHAR); if(dam_type == DAM_COLD) cold_effect((void *) victim, agg+dam/2, dam, TARGET_CHAR); if(dam_type == DAM_LIGHTNING) shock_effect((void *) victim, agg+dam/2, dam, TARGET_CHAR); if(dam_type == DAM_ACID) acid_effect((void *) victim, agg+dam/2, dam, TARGET_CHAR); if(dam_type == DAM_POISON) poison_effect((void *) victim, agg+dam/2, dam, TARGET_CHAR); /* * Sleep spells and extremely wounded folks. */ if ( !IS_AWAKE(victim) ) stop_fighting( victim, FALSE ); /* * Payoff for killing things. */ if ( (victim->position == P_INCAP && IS_NPC(victim)) || victim->position == P_DEAD || victim->position == P_TORPOR ) { if ( !IS_NPC(victim) ) { log_string( LOG_GAME, Format("%s killed by %s at %d", victim->name, (IS_NPC(ch) ? ch->short_descr : ch->name), ch->in_room->vnum) ); } snprintf( log_buf, 2*MIL, "\tY[WIZNET]\tn %s got toasted by %s at %s [room %d]", (IS_NPC(victim) ? victim->short_descr : victim->name), (IS_NPC(ch) ? ch->short_descr : ch->name), ch->in_room->name, ch->in_room->vnum); if (IS_NPC(victim)) wiznet(log_buf,NULL,NULL,WIZ_MOBDEATHS,0,0); else wiznet(log_buf,NULL,NULL,WIZ_DEATHS,0,0); /* * Death trigger */ if ( IS_NPC( victim ) && HAS_TRIGGER( victim, TRIG_DEATH) ) { victim->position = P_STAND; mp_percent_trigger( victim, ch, NULL, NULL, TRIG_DEATH ); } if((!str_cmp(ch->description, "") || strlen(ch->description) < 10) && ch->played > 10*60*60) { send_to_char("No experience without a description.\n\r", ch); } else { if(ch->ooc_xp_count < 2) { send_to_char("You learn from your encounter.\n\r", ch); ch->oocxp += 1; ch->ooc_xp_count++; } else if(IS_SET(victim->act2, ACT2_HUNTER) && ch->ooc_xp_count < 50) { send_to_char("You learn from your encounter.\n\r", ch); ch->exp += 1; ch->ooc_xp_count++; } } if(ch->quest) { if(ch->quest->quest_type == Q_HITMAN && ch->quest->victim == victim) (*quest_table[ch->quest->quest_type].q_fun) (ch, 2); if(victim->quest != NULL && victim->quest->quest_type == Q_HITMAN && victim->quest->victim == victim && victim->quest->questor != ch) (*quest_table[victim->quest->quest_type].q_fun) (victim->quest->questor, 3); if(victim->quest != NULL && (victim->quest->quest_type == Q_BODYGUARD || victim->quest->quest_type == Q_RESCUE) && victim->quest->victim == victim) (*quest_table[victim->quest->quest_type].q_fun) (victim->quest->questor, 3); } if(victim->position != P_TORPOR || agg) update_pos( victim, agg ); return victim->position; } if ( victim == ch ) return ch->position; /* Link dead salvation. */ if ( !IS_NPC(victim) && victim->desc == NULL ) { do_function(victim, &do_flee,""); } tail_chain( ); return victim->position; }
void damage(struct char_data *ch, struct char_data *victim, int dam, int attacktype) { char buf[MAX_STRING_LENGTH]; struct message_type *messages; int i,j,nr,max_hit,exp; int hit_limit(struct char_data *ch); assert(GET_POS(victim) > POSITION_DEAD); if ((GET_LEVEL(victim)>20) && !IS_NPC(victim)) /* You can't damage an immortal! */ dam=0; if (victim != ch) { if (GET_POS(victim) > POSITION_STUNNED) { if (!(victim->specials.fighting)) set_fighting(victim, ch); GET_POS(victim) = POSITION_FIGHTING; } if (GET_POS(ch) > POSITION_STUNNED) { if (!(ch->specials.fighting)) set_fighting(ch, victim); if (IS_NPC(ch) && IS_NPC(victim) && victim->master && !number(0,10) && IS_AFFECTED(victim, AFF_CHARM) && (victim->master->in_room == ch->in_room)) { if (ch->specials.fighting) stop_fighting(ch); hit(ch, victim->master, TYPE_UNDEFINED); return; } } } if (victim->master == ch) stop_follower(victim); if (IS_AFFECTED(ch, AFF_INVISIBLE)) appear(ch); if (IS_AFFECTED(victim, AFF_SANCTUARY)) dam = MIN(dam, 18); /* Max 18 damage when sanctuary */ dam=MIN(dam,100); dam=MAX(dam,0); GET_HIT(victim)-=dam; if (ch != victim) gain_exp(ch,GET_LEVEL(victim)*dam); update_pos(victim); if ((attacktype >= TYPE_HIT) && (attacktype <= TYPE_SLASH)) { if (!ch->equipment[WIELD]) { dam_message(dam, ch, victim, TYPE_HIT); } else { dam_message(dam, ch, victim, attacktype); } } else { for(i = 0; i < MAX_MESSAGES; i++) { if (fight_messages[i].a_type == attacktype) { nr=dice(1,fight_messages[i].number_of_attacks); for(j=1,messages=fight_messages[i].msg;(j<nr)&&(messages);j++) messages=messages->next; if (!IS_NPC(victim) && (GET_LEVEL(victim) > 20)) { act(messages->god_msg.attacker_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_CHAR); act(messages->god_msg.victim_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_VICT); act(messages->god_msg.room_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_NOTVICT); } else if (dam != 0) { if (GET_POS(victim) == POSITION_DEAD) { act(messages->die_msg.attacker_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_CHAR); act(messages->die_msg.victim_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_VICT); act(messages->die_msg.room_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_NOTVICT); } else { act(messages->hit_msg.attacker_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_CHAR); act(messages->hit_msg.victim_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_VICT); act(messages->hit_msg.room_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_NOTVICT); } } else { /* Dam == 0 */ act(messages->miss_msg.attacker_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_CHAR); act(messages->miss_msg.victim_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_VICT); act(messages->miss_msg.room_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_NOTVICT); } } } } switch (GET_POS(victim)) { case POSITION_MORTALLYW: act("$n is mortally wounded, and will die soon, if not aided.", TRUE, victim, 0, 0, TO_ROOM); act("You are mortally wounded, and will die soon, if not aided.", FALSE, victim, 0, 0, TO_CHAR); break; case POSITION_INCAP: act("$n is incapacitated and will slowly die, if not aided.", TRUE, victim, 0, 0, TO_ROOM); act("You are incapacitated an will slowly die, if not aided.", FALSE, victim, 0, 0, TO_CHAR); break; case POSITION_STUNNED: act("$n is stunned, but will probably regain conscience again.", TRUE, victim, 0, 0, TO_ROOM); act("You're stunned, but will probably regain conscience again.", FALSE, victim, 0, 0, TO_CHAR); break; case POSITION_DEAD: act("$n is dead! R.I.P.", TRUE, victim, 0, 0, TO_ROOM); act("You are dead! Sorry...", FALSE, victim, 0, 0, TO_CHAR); break; default: /* >= POSITION SLEEPING */ max_hit=hit_limit(victim); if (dam > (max_hit/5)) act("That Really did HURT!",FALSE, victim, 0, 0, TO_CHAR); if (GET_HIT(victim) < (max_hit/5)) { act("You wish that your wounds would stop BLEEDING that much!",FALSE,victim,0,0,TO_CHAR); if (IS_NPC(victim)) if (IS_SET(victim->specials.act, ACT_WIMPY)) do_flee(victim, "", 0); } break; } if (!IS_NPC(victim) && !(victim->desc)) { do_flee(victim, "", 0); if (!victim->specials.fighting) { act("$n is rescued by divine forces.", FALSE, victim, 0, 0, TO_ROOM); victim->specials.was_in_room = victim->in_room; char_from_room(victim); char_to_room(victim, 0); } } if (GET_POS(victim) < POSITION_STUNNED) if (ch->specials.fighting == victim) stop_fighting(ch); if (!AWAKE(victim)) if (victim->specials.fighting) stop_fighting(victim); if (GET_POS(victim) == POSITION_DEAD) { if (IS_NPC(victim) || victim->desc) if (IS_AFFECTED(ch, AFF_GROUP)) { group_gain(ch, victim); } else { /* Calculate level-difference bonus */ exp = GET_EXP(victim)/3; if (IS_NPC(ch)) exp += (exp*MIN(4, (GET_LEVEL(victim) - GET_LEVEL(ch))))>>3; else exp += (exp*MIN(8, (GET_LEVEL(victim) - GET_LEVEL(ch))))>>3; exp = MAX(exp, 1); gain_exp(ch, exp); change_alignment(ch, victim); } if (!IS_NPC(victim)) { sprintf(buf, "%s killed by %s at %s", GET_NAME(victim), (IS_NPC(ch) ? ch->player.short_descr : GET_NAME(ch)), world[victim->in_room].name); log(buf); } die(victim); }