c_cpp 添加陷阱到宝箱
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 添加陷阱到宝箱相关的知识,希望对你有一定的参考价值。
/* This is meant to be used with the treasure code that I released
* a while back. It can be used for whatever you want. You'll notice
* that some stuff is commented out. This is so you can elect to have
* it or not.
*/
/* This code was designed for use with a ROM style MUD. It will not
* work without modifications to your code. It's been added to three
* MUDs now without problems, so we know it works. If you have problems
* with it, please make sure you have at least looked at the treasure
* chest code that I submitted to Kyndig.com or that is located on the
* www.aww-mud.org site. If you absolutely can't get this to work for
* you, you can contact me at dalsor@cfl.rr.com, or via my primary
* MUD at www.aww-mud.org port 6500.
*
* In any case, all the defines and includes and calls and other such
* programming lingo you will need are to be found in said treasure
* code. Again, please make sure you have looked at that code.
*/
/* Add a new gsn for unarm traps. Add a command called unarm.
* Note, we use the command unarm becase disarm is typically already a
* skill.
*/
/* Finally, I've included a modified search function (do_search), that
* will let people search a treasure chest to see if it has a trap.
* I highly recommend if you allow searching, make it so disarming is
* easier if you do find the trap. In the unarm phase, consider making
* it so that if the character dies due to a failed unarm, it will
* display a diffeent message to let the char know the severity of what
* happened. One MUD wanted it, another didn't, so I did not include
* it here. If you want it, add it.
*/
/* bleh... sucks when you write more crap in comments than actual code...
*/
/* And now... the disclaimer. Make sure this is in your header. There are
* no requirements for using this code except that you give proper credit
* to the original creators.
* Please don't claim this as your code. I wrote it, de-bugged it, and released
* it so you and yours' can have fun with it. I'm not asking for credit in your
* help files, your snippet files, an email, or anything beyond enjoying this
* snippet. Just don't say you wrote it when you didn't. I've seen an alarming
* number of claims that someone else 'wrote' my homes code, or my smithing code,
* or my whatever code, and it's just plain irritating. If you change it, great!
* If you make it better, wonderful! But I wrote it.
*/
/*
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-1998 Russ Taylor
ROM has been brought to you by the ROM consortium
Russ Taylor (rtaylor@hypercube.org)
Gabrielle Taylor (gtaylor@hypercube.org)
Brian Moore (zump@rom.org)
By using this code, you have agreed to follow the terms of the
ROM license, in the file Rom24/doc/rom.license
*/
/* TIP: add something in save.c to make sure boxes save right. I cant/wont
* tell you how to do everything ;)
*/
#define ptc printf_to_char
#define stc send_to_char
/* In act_move, or where do_pick is located, add this. */
/* traps! these only kick in if not unarmed first */
if ( obj->value[3] == TRAP_BOOMER )
{
trap_damage( ch, obj );
/* if the box explodes or erupts in flame, remove it */
if ( obj->value[3] == TRAP_BOOMER || obj->value[3] == TRAP_FIRE )
{
obj_from_char( obj );
extract_obj( obj );
return;
}
}
/* blade needs to sever limbs in the future */
if ( obj->value[3] == TRAP_BLADE || obj->value[3] == TRAP_MANA )
{
trap_damage( ch, obj );
}
/* acid - nasty stuff */
if ( obj->value[3] == TRAP_ACID )
{
OBJ_DATA *aObj, *aObj_next;
trap_damage( ch, obj );
for (aObj = ch->carrying; aObj != NULL; aObj = aObj_next)
{
aObj_next = aObj->next_content;
acid_effect(aObj,obj->value[4],obj->value[4],TARGET_OBJ);
break;
}
}
/* poison */
if ( obj->value[3] == TRAP_NEEDLE || obj->value[3] == TRAP_GASSER )
{
/* get the char */
if ( obj->value[3] == TRAP_NEEDLE )
{
AFFECT_DATA af;
trap_damage( ch, obj );
/*
af.type = gsn_poison;
af.duration = obj->value[4];
af.location = APPLY_STR;
af.modifier = -3;
af.bitvector = AFF_PLAGUE;
affect_join( ch, &af );*/
}
/* get the room */
if ( obj->value[3] == TRAP_GASSER )
{
AFFECT_DATA af;
trap_damage( ch, obj );
/* if save, they held their breath
af.type = gsn_poison;
af.duration = obj->value[4];
af.location = APPLY_REF;
af.modifier = -3;
af.bitvector = AFF_PLAGUE;
affect_join( ch, &af );*/
}
}
if ( obj->value[3] == TRAP_FIRE )
{
OBJ_DATA *aObj, *aObj_next;
trap_damage( ch, obj );
/* if the box explodes or erupts in flame, remove it */
for (aObj = ch->carrying; aObj != NULL; aObj = aObj_next)
{
aObj_next = aObj->next_content;
fire_effect(aObj,obj->value[4],obj->value[4],TARGET_OBJ);
break;
}
obj_from_char( obj );
extract_obj( obj );
return;
}
/* end traps */
/* in your skills file, add this */
void trap_damage( CHAR_DATA *ch, OBJ_DATA *obj )
{
int dam;
bool die = FALSE;
dam = obj->value[4];
if ( obj->value[3] == TRAP_BOOMER )
{
dam *= 3;
ch->hit -= UMIN( dam, ch->max_hit);
if ( ch->hit <= 0 )
die = TRUE;
act( "A sudden explosion erupts, knocking $n back and shattering $p to splinters!", ch, obj, NULL, TO_ROOM );
act( "A sudden explosion erupts, knocking you back and shattering $p to splinters!", ch, obj, NULL, TO_CHAR );
}
if ( obj->value[3] == TRAP_GASSER )
{
dam *= 4;
ch->hit -= UMIN( dam, ch->max_hit);
if ( ch->hit <= 0 )
die = TRUE;
act( "A cloud of noxious gas pours from a $p $n is holding.", ch, obj, NULL, TO_ROOM );
act( "A cloud of noxious gas pours from $p.", ch, obj, NULL, TO_CHAR );
}
if ( obj->value[3] == TRAP_NEEDLE )
{
dam *= 2;
ch->hit -= UMIN( dam, ch->max_hit);
if ( ch->hit <= 0 )
die = TRUE;
act( "$n jerks $s hand away from $p with a muttered curse.", ch, obj, NULL, TO_ROOM );
act( "A thin needle from $p pricks your hand!", ch, obj, NULL, TO_CHAR );
}
if ( obj->value[3] == TRAP_BLADE )
{
dam *= 3;
ch->hit -= UMIN( dam, ch->max_hit);
if ( ch->hit <= 0 )
die = TRUE;
act( "A thin blade slices out from $p $n is holding, slashing $s hand!", ch, obj, NULL, TO_ROOM );
act( "A thin blade slices out from $p, slashing your hand!", ch, obj, NULL, TO_CHAR );
}
if ( obj->value[3] == TRAP_MANA )
{
dam *= 4;
ch->mana -= UMIN( dam, ch->max_mana);
if ( ch->hit <= 0 )
die = TRUE;
act( "$n's eyes roll back into $s skull.", ch, obj, NULL, TO_ROOM );
act( "You feel your eyes roll back into your skull.", ch, obj, NULL, TO_ROOM );
}
if ( obj->value[3] == TRAP_FIRE )
{
dam *= 5;
ch->hit -= UMIN( dam, ch->max_hit);
if ( ch->hit <= 0 )
die = TRUE;
act( "A spray of fire leaps out to sear $n, burning $p like kindling!", ch, obj, NULL, TO_ROOM );
act( "A spray of fire leaps out to sear you, burning $p like kindling!", ch, obj, NULL, TO_CHAR );
}
if ( obj->value[3] == TRAP_ACID )
{
dam *= 5;
ch->hit -= UMIN( dam, ch->max_hit);
if ( ch->hit <= 0 )
die = TRUE;
act( "A spray of acid from $p catches $n in the face!", ch, obj, NULL, TO_ROOM );
act( "A spray of acid from $p catches you in the face!", ch, obj, NULL, TO_CHAR );
}
if ( die )
{
stc( "You have been {RKILLED!!{x\n\r\n\r", ch );
raw_kill( ch );
}
return;
}
void do_unarm( CHAR_DATA *ch, char *argument )
{
OBJ_DATA *obj;
int rank, base, oppose;
bool fail = FALSE;
/* search obj for traps */
if ( ( obj = get_obj_carry( ch, argument, ch ) ) == NULL )
{
stc( "Unarm what? You don't see that here.\n\r", ch );
return;
}
if ( obj->item_type != ITEM_TREASURECHEST )
{
stc( "That's not a treasure chest.\n\r", ch );
return;
}
rank = ch->pcdata->learned[gsn_unarm_traps];
rank += get_curr_stat( ch, STAT_DEX );
rank += get_curr_stat( ch, STAT_REF );
base = number_range( 1, 100 );
oppose = obj->value[4];
base += oppose;
if ( number_range( 1, rank ) < number_range( 1, base ) && obj->value[3] > TRAP_NONE )
{
act( "$n fiddles with $p for a moment, concentrating intently.", ch, obj, NULL, TO_ROOM );
act( "You attempt to unarm the trap on $p, but manage to spring it instead!", ch, obj, NULL, TO_CHAR );
if ( obj->value[3] == TRAP_BOOMER )
{
trap_damage( ch, obj );
/* if the box explodes or erupts in flame, remove it */
check_improve( ch, gsn_unarm_traps, FALSE, 3 );
obj_from_char( obj );
extract_obj( obj );
}
/* blade needs to sever limbs in the future */
if ( obj->value[3] == TRAP_BLADE || obj->value[3] == TRAP_MANA )
{
trap_damage( ch, obj );
}
/* acid - nasty stuff */
if ( obj->value[3] == TRAP_ACID )
{
OBJ_DATA *aObj, *aObj_next;
trap_damage( ch, obj );
check_improve( ch, gsn_unarm_traps, FALSE, 3 );
for (aObj = ch->carrying; aObj != NULL; aObj = aObj_next)
{
aObj_next = aObj->next_content;
acid_effect(aObj,obj->value[4],obj->value[4],TARGET_OBJ);
break;
}
}
/* poison */
if ( obj->value[3] == TRAP_NEEDLE || obj->value[3] == TRAP_GASSER )
{
/* get the char */
if ( obj->value[3] == TRAP_NEEDLE )
{
AFFECT_DATA af;
trap_damage( ch, obj );
check_improve( ch, gsn_unarm_traps, FALSE, 3 );
/*
af.type = gsn_poison;
af.duration = obj->value[4];
af.location = APPLY_STR;
af.modifier = -3;
af.bitvector = AFF_PLAGUE;
affect_join( ch, &af );*/
}
/* get the room */
if ( obj->value[3] == TRAP_GASSER )
{
AFFECT_DATA af;
trap_damage( ch, obj );
check_improve( ch, gsn_unarm_traps, FALSE, 3 );
/* if save, they held their breath
af.type = gsn_poison;
af.duration = obj->value[4];
af.location = APPLY_REF;
af.modifier = -3;
af.bitvector = AFF_PLAGUE;
affect_join( ch, &af );*/
}
}
if ( obj->value[3] == TRAP_FIRE )
{
OBJ_DATA *aObj, *aObj_next;
trap_damage( ch, obj );
/* if the box explodes or erupts in flame, remove it */
for (aObj = ch->carrying; aObj != NULL; aObj = aObj_next)
{
aObj_next = aObj->next_content;
fire_effect(aObj,obj->value[4],obj->value[4],TARGET_OBJ);
break;
}
check_improve( ch, gsn_unarm_traps, FALSE, 3 );
obj_from_char( obj );
extract_obj( obj );
}
}
else if ( number_range( 1, rank / 2 ) < number_range( 1, base ) && obj->value[3] > TRAP_NONE )
{
act( "$n fiddles with $p for a moment, concentrating intently.", ch, obj, NULL, TO_ROOM );
act( "You attempt to unarm the trap on $p, but can't quite figure out the mechanism.", ch, obj, NULL, TO_CHAR );
check_improve( ch, gsn_unarm_traps, FALSE, 6 );
return;
}
else if ( obj->value[3] == TRAP_NONE )
{
act( "$p doesn't appear to be trapped.", ch, obj, NULL, TO_CHAR );
return;
}
/* success */
else
{
act( "$n fiddles with $p for a moment, concentrating intently.", ch, obj, NULL, TO_ROOM );
act( "You fiddle with the trap on $p until you manage to render the mechanism useless!", ch, obj, NULL, TO_CHAR );
check_improve( ch, gsn_unarm_traps, TRUE, 6 );
obj->value[3] = TRAP_NONE;
return;
}
return;
}
void do_search( CHAR_DATA *ch, char *argument )
{
CHAR_DATA *vch;
OBJ_DATA *obj;
int chance, num_found, rank, base, oppose;
bool found;
char arg[MIL];
argument = one_argument( argument, arg );
/* init the variables */
if ( IS_NPC( ch ) )
chance = 75;
else
chance = get_skill(ch,gsn_search);
num_found = 0;
found = FALSE;
/*if ( ch->level < skill_table[gsn_search].skill_level[ch->class] )
{
stc("{cMight as well search for the needle in the haystack.\n\r", ch );
return;
}*/
if ( IS_NPC( ch ) )
{
/* npcs dont get checked for skill */
if ( arg[0] == '\0' )
{
act( "$n searches around the area for a moment.", ch, NULL, NULL, TO_ROOM );
for ( vch = ch->in_room->people; vch != NULL; vch = vch->next )
{
/* hunt up some hiders */
if (vch->in_room != ch->in_room)
continue;
if (vch == ch)
continue;
/* do this partly to keep people from finding wizi imms, and
* to allow mobs to be unsearchable */
if (vch->level >= LEVEL_HERO && ch->level < LEVEL_HERO)
continue;
/* formulate the chance */
if (ch->level >= vch->level)
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_INT) >= get_curr_stat(vch,STAT_INT) )
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_DEX) >= get_curr_stat(vch,STAT_DEX) )
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_WIS) >= get_curr_stat(vch,STAT_WIS) )
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_INS) >= get_curr_stat(vch,STAT_INS) )
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_REF) >= get_curr_stat(vch,STAT_REF) )
chance += 1;
else
chance -= 2;
/* AWW has Wolfkin - remove the following two lines if not used */
if (IS_SET( ch->spec_flags, SPEC_WOLFBROTHER))
{
chance += 5;
}
/* Always a chance to fail */
if (chance > 99) chance = 99;
/* ok, now show the found people */
if (number_percent() > chance)
continue;
if (is_affected(vch, gsn_invis)
|| is_affected(vch, gsn_sneak)
|| IS_AFFECTED(vch, AFF_SNEAK)
|| IS_AFFECTED(vch, AFF_INVISIBLE)
|| IS_AFFECTED(vch, AFF_HIDE)
|| is_affected(vch, gsn_hide))
{
printf_to_char(ch,"You see %s.\n\r",vch->name);
printf_to_char(vch,"%s has spotted you!\n\r",ch->name);
affect_strip ( vch, gsn_invis );
affect_strip ( vch, gsn_sneak );
REMOVE_BIT ( vch->affected_by, AFF_HIDE );
REMOVE_BIT ( vch->affected_by, AFF_INVISIBLE );
REMOVE_BIT ( vch->affected_by, AFF_SNEAK );
found = TRUE;
num_found += 1;
check_improve(ch,gsn_search,TRUE,9);
}
}
/* AWW uses hidden portals. Remove this loop if not needed. */
for ( obj = ch->in_room->contents; obj; obj = obj->next_content )
{
if (obj->item_type == ITEM_PORTAL)
{
printf_to_char(ch,"You see %s.\n\r",obj->short_descr);
found = TRUE;
num_found += 1;
}
}
if (!found)
{
stc("You didn't find anyone here.\n\r",ch);
printf_to_char(ch,"Chance is %d.\n\r",chance);
}
/* make em wait longer for each person found */
WAIT_STATE(ch,PULSE_VIOLENCE * num_found);
return;
}
}
if ( !IS_NPC( ch ) )
{
if ( get_skill( ch, gsn_search ) <= 0 )
{
stc("You dont know enough about searching.\n\r",ch);
return;
}
}
if ( arg[0] == '\0' )
{
for ( vch = ch->in_room->people; vch != NULL; vch = vch->next )
{
/* hunt up some hiders */
if (vch->in_room != ch->in_room)
continue;
if (vch == ch)
continue;
/* do this partly to keep people from finding wizi imms, and
* to allow mobs to be unsearchable */
if (vch->level >= LEVEL_HERO && ch->level < LEVEL_HERO)
continue;
/* formulate the chance */
if (ch->level >= vch->level)
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_INT) >= get_curr_stat(vch,STAT_INT) )
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_DEX) >= get_curr_stat(vch,STAT_DEX) )
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_WIS) >= get_curr_stat(vch,STAT_WIS) )
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_INS) >= get_curr_stat(vch,STAT_INS) )
chance += 1;
else
chance -= 2;
if ( get_curr_stat(ch,STAT_REF) >= get_curr_stat(vch,STAT_REF) )
chance += 1;
else
chance -= 2;
/* AWW has Wolfkin - remove the following two lines if not used */
if (IS_SET( ch->spec_flags, SPEC_WOLFBROTHER))
{
chance += 5;
}
/* Always a chance to fail */
if (chance > 99) chance = 99;
/* ok, now show the found people */
if (number_percent() > chance)
continue;
if (is_affected(vch, gsn_invis)
|| is_affected(vch, gsn_sneak)
|| IS_AFFECTED(vch, AFF_SNEAK)
|| IS_AFFECTED(vch, AFF_INVISIBLE)
|| IS_AFFECTED(vch, AFF_HIDE)
|| is_affected(vch, gsn_hide))
{
printf_to_char(ch,"You see %s.\n\r",vch->name);
printf_to_char(vch,"%s has spotted you!\n\r",ch->name);
affect_strip ( vch, gsn_invis );
affect_strip ( vch, gsn_sneak );
REMOVE_BIT ( vch->affected_by, AFF_HIDE );
REMOVE_BIT ( vch->affected_by, AFF_INVISIBLE );
REMOVE_BIT ( vch->affected_by, AFF_SNEAK );
found = TRUE;
num_found += 1;
check_improve(ch,gsn_search,TRUE,9);
}
}
/* AWW uses hidden portals. Remove this loop if not needed. */
for ( obj = ch->in_room->contents; obj; obj = obj->next_content )
{
if (obj->item_type == ITEM_PORTAL)
{
printf_to_char(ch,"You see %s.\n\r",obj->short_descr);
found = TRUE;
num_found += 1;
}
}
if (!found)
{
stc("You didn't find anyone here.\n\r",ch);
printf_to_char(ch,"Chance is %d.\n\r",chance);
}
/* make em wait longer for each person found */
WAIT_STATE(ch,PULSE_VIOLENCE * num_found);
return;
}
/* search obj for traps */
if ( ( obj = get_obj_carry( ch, arg, ch ) ) == NULL )
{
stc( "Search what? You don't see that here.\n\r", ch );
return;
}
if ( obj->item_type != ITEM_TREASURECHEST )
{
stc( "That's not a treasure chest.\n\r", ch );
return;
}
rank = ch->pcdata->learned[gsn_unarm_traps];
rank += get_curr_stat( ch, STAT_INT );
base = number_range( 1, 100 );
oppose = obj->value[4];
base += oppose;
if ( number_range( 1, rank ) < number_range( 1, base ) )
{
stc( "It doesn't appear to be trapped.\n\r", ch );
return;
}
else if ( obj->value[3] == TRAP_NONE )
{
stc( "It doesn't appear to be trapped.\n\r", ch );
return;
}
else
{
ptc( ch, "You see a %s.\n\r", obj->value[3] == TRAP_BOOMER ? "small black cube inside the lock" :
obj->value[3] == TRAP_GASSER ? "small green cannister hidden within the lock" :
obj->value[3] == TRAP_NEEDLE ? "small needle dripping with a green liquid inside the lock" :
obj->value[3] == TRAP_BLADE ? "razor sharp blade hidden within the lock" :
obj->value[3] == TRAP_MANA ? "small shimmering sphere tucked inside the lock" :
obj->value[3] == TRAP_FIRE ? "reddish-gold casement placed behind the lock" :
obj->value[3] == TRAP_ACID ? "bluish-green vial rigged to burst inside the lock" :
"odd shape within the lock");
}
return;
}
以上是关于c_cpp 添加陷阱到宝箱的主要内容,如果未能解决你的问题,请参考以下文章