?? handler.c
字號:
/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "merc.h"
AFFECT_DATA * affect_free;
/*
* Local functions.
*/
void affect_modify args( ( CHAR_DATA *ch, AFFECT_DATA *paf, bool fAdd ) );
/*
* Retrieve a character's trusted level for permission checking.
*/
int get_trust( CHAR_DATA *ch )
{
if ( ch->desc != NULL && ch->desc->original != NULL )
ch = ch->desc->original;
if ( ch->trust != 0 )
return ch->trust;
if ( IS_NPC(ch) && ch->level >= LEVEL_HERO )
return LEVEL_HERO - 1;
else
return ch->level;
}
/*
* Retrieve a character's age.
*/
int get_age( CHAR_DATA *ch )
{
return 17 + ( ch->played + (int) (current_time - ch->logon) ) / 14400;
/* 12240 assumes 30 second hours, 24 hours a day, 20 day - Kahn */
}
/*
* Retrieve character's current strength.
*/
int get_curr_str( CHAR_DATA *ch )
{
int max;
if ( IS_NPC(ch) )
return 13;
if ( class_table[ch->class].attr_prime == APPLY_STR )
max = 25;
else
max = 22;
return URANGE( 3, ch->pcdata->perm_str + ch->pcdata->mod_str, max );
}
/*
* Retrieve character's current intelligence.
*/
int get_curr_int( CHAR_DATA *ch )
{
int max;
if ( IS_NPC(ch) )
return 13;
if ( class_table[ch->class].attr_prime == APPLY_INT )
max = 25;
else
max = 22;
return URANGE( 3, ch->pcdata->perm_int + ch->pcdata->mod_int, max );
}
/*
* Retrieve character's current wisdom.
*/
int get_curr_wis( CHAR_DATA *ch )
{
int max;
if ( IS_NPC(ch) )
return 13;
if ( class_table[ch->class].attr_prime == APPLY_WIS )
max = 25;
else
max = 22;
return URANGE( 3, ch->pcdata->perm_wis + ch->pcdata->mod_wis, max );
}
/*
* Retrieve character's current dexterity.
*/
int get_curr_dex( CHAR_DATA *ch )
{
int max;
if ( IS_NPC(ch) )
return 13;
if ( class_table[ch->class].attr_prime == APPLY_DEX )
max = 25;
else
max = 22;
return URANGE( 3, ch->pcdata->perm_dex + ch->pcdata->mod_dex, max );
}
/*
* Retrieve character's current constitution.
*/
int get_curr_con( CHAR_DATA *ch )
{
int max;
if ( IS_NPC(ch) )
return 13;
if ( class_table[ch->class].attr_prime == APPLY_CON )
max = 25;
else
max = 22;
return URANGE( 3, ch->pcdata->perm_con + ch->pcdata->mod_con, max );
}
/*
* Retrieve a character's carry capacity.
*/
int can_carry_n( CHAR_DATA *ch )
{
if ( !IS_NPC(ch) && ch->level >= LEVEL_IMMORTAL )
return 1000;
if ( IS_NPC(ch) && IS_SET(ch->act, ACT_PET) )
return 0;
return MAX_WEAR + 2 * get_curr_dex( ch ) / 2;
}
/*
* Retrieve a character's carry capacity.
*/
int can_carry_w( CHAR_DATA *ch )
{
if ( !IS_NPC(ch) && ch->level >= LEVEL_IMMORTAL )
return 1000000;
if ( IS_NPC(ch) && IS_SET(ch->act, ACT_PET) )
return 0;
return str_app[get_curr_str(ch)].carry;
}
/*
* See if a string is one of the names of an object.
*/
/*
* New is_name sent in by Alander.
*/
bool is_name( const char *str, char *namelist )
{
char name[MAX_INPUT_LENGTH];
for ( ; ; )
{
namelist = one_argument( namelist, name );
if ( name[0] == '\0' )
return FALSE;
if ( !str_cmp( str, name ) )
return TRUE;
}
}
/*
* Apply or remove an affect to a character.
*/
void affect_modify( CHAR_DATA *ch, AFFECT_DATA *paf, bool fAdd )
{
OBJ_DATA *wield;
int mod;
mod = paf->modifier;
if ( fAdd )
{
SET_BIT( ch->affected_by, paf->bitvector );
}
else
{
REMOVE_BIT( ch->affected_by, paf->bitvector );
mod = 0 - mod;
}
if ( IS_NPC(ch) )
return;
switch ( paf->location )
{
default:
bug( "Affect_modify: unknown location %d.", paf->location );
return;
case APPLY_NONE: break;
case APPLY_STR: ch->pcdata->mod_str += mod; break;
case APPLY_DEX: ch->pcdata->mod_dex += mod; break;
case APPLY_INT: ch->pcdata->mod_int += mod; break;
case APPLY_WIS: ch->pcdata->mod_wis += mod; break;
case APPLY_CON: ch->pcdata->mod_con += mod; break;
case APPLY_SEX: ch->sex += mod;
// @@@ This next bit is from the net...
if ( ch->sex < 0 || ch->sex > 2 )
ch->sex = 0;
break;
case APPLY_CLASS: break;
case APPLY_LEVEL: break;
case APPLY_AGE: break;
case APPLY_HEIGHT: break;
case APPLY_WEIGHT: break;
case APPLY_MANA: ch->max_mana += mod; break;
case APPLY_HIT: ch->max_hit += mod; break;
case APPLY_MOVE: ch->max_move += mod; break;
case APPLY_GOLD: break;
case APPLY_EXP: break;
case APPLY_AC: ch->armor += mod; break;
case APPLY_HITROLL: ch->hitroll += mod; break;
case APPLY_DAMROLL: ch->damroll += mod; break;
case APPLY_SAVING_PARA: ch->saving_throw += mod; break;
case APPLY_SAVING_ROD: ch->saving_throw += mod; break;
case APPLY_SAVING_PETRI: ch->saving_throw += mod; break;
case APPLY_SAVING_BREATH: ch->saving_throw += mod; break;
case APPLY_SAVING_SPELL: ch->saving_throw += mod; break;
// Don't fault on TFC zones
case APPLY_CHARISMA: break;
case APPLY_LUC: break; case APPLY_NOSTEAL: break;
case APPLY_NOSLEEP: break;
case APPLY_NOSUMMON: break;
case APPLY_NOCHARM: break;
case APPLY_NOSEXCHANGE: break;
case APPLY_TRUESEE: break;
case APPLY_NOINFO: break;
}
/*
* Check for weapon wielding.
* Guard against recursion (for weapons with affects).
*/
if ( ( wield = get_eq_char( ch, WEAR_WIELD ) ) != NULL
&& get_obj_weight(wield) > str_app[get_curr_str(ch)].wield )
{
static int depth;
if ( depth == 0 )
{
depth++;
act( "You drop $p.", ch, wield, NULL, TO_CHAR );
act( "$n drops $p.", ch, wield, NULL, TO_ROOM );
obj_from_char( wield );
obj_to_room( wield, ch->in_room );
depth--;
}
}
return;
}
/*
* Give an affect to a char.
*/
void affect_to_char( CHAR_DATA *ch, AFFECT_DATA *paf )
{
AFFECT_DATA *paf_new;
if ( affect_free == NULL )
{
paf_new = alloc_perm( sizeof(*paf_new) );
}
else
{
paf_new = affect_free;
affect_free = affect_free->next;
}
*paf_new = *paf;
paf_new->next = ch->affected;
ch->affected = paf_new;
affect_modify( ch, paf_new, TRUE );
return;
}
/*
* Remove an affect from a char.
*/
void affect_remove( CHAR_DATA *ch, AFFECT_DATA *paf )
{
if ( ch->affected == NULL )
{
bug( "Affect_remove: no affect.", 0 );
return;
}
affect_modify( ch, paf, FALSE );
if ( paf == ch->affected )
{
ch->affected = paf->next;
}
else
{
AFFECT_DATA *prev;
for ( prev = ch->affected; prev != NULL; prev = prev->next )
{
if ( prev->next == paf )
{
prev->next = paf->next;
break;
}
}
if ( prev == NULL )
{
bug( "Affect_remove: cannot find paf.", 0 );
return;
}
}
paf->next = affect_free;
affect_free = paf->next;
return;
}
/*
* Strip all affects of a given sn.
*/
void affect_strip( CHAR_DATA *ch, int sn )
{
AFFECT_DATA *paf;
AFFECT_DATA *paf_next;
for ( paf = ch->affected; paf != NULL; paf = paf_next )
{
paf_next = paf->next;
if ( paf->type == sn )
affect_remove( ch, paf );
}
return;
}
/*
* Return true if a char is affected by a spell.
*/
bool is_affected( CHAR_DATA *ch, int sn )
{
AFFECT_DATA *paf;
for ( paf = ch->affected; paf != NULL; paf = paf->next )
{
if ( paf->type == sn )
return TRUE;
}
return FALSE;
}
/*
* Add or enhance an affect.
*/
void affect_join( CHAR_DATA *ch, AFFECT_DATA *paf )
{
AFFECT_DATA *paf_old;
bool found;
found = FALSE;
for ( paf_old = ch->affected; paf_old != NULL; paf_old = paf_old->next )
{
if ( paf_old->type == paf->type )
{
paf->duration += paf_old->duration;
paf->modifier += paf_old->modifier;
affect_remove( ch, paf_old );
break;
}
}
affect_to_char( ch, paf );
return;
}
/*
* Move a char out of a room.
*/
void char_from_room( CHAR_DATA *ch )
{
OBJ_DATA *obj;
if ( ch->in_room == NULL )
{
bug( "Char_from_room: NULL.", 0 );
return;
}
if ( !IS_NPC(ch) )
--ch->in_room->area->nplayer;
if ( ( obj = get_eq_char( ch, WEAR_LIGHT ) ) != NULL
&& obj->item_type == ITEM_LIGHT
&& obj->value[2] != 0
&& ch->in_room->light > 0 )
--ch->in_room->light;
if ( ch == ch->in_room->people )
{
ch->in_room->people = ch->next_in_room;
}
else
{
CHAR_DATA *prev;
for ( prev = ch->in_room->people; prev; prev = prev->next_in_room )
{
if ( prev->next_in_room == ch )
{
prev->next_in_room = ch->next_in_room;
break;
}
}
if ( prev == NULL )
bug( "Char_from_room: ch not found.", 0 );
}
ch->in_room = NULL;
ch->next_in_room = NULL;
return;
}
/*
* Move a char into a room.
*/
void char_to_room( CHAR_DATA *ch, ROOM_INDEX_DATA *pRoomIndex )
{
OBJ_DATA *obj;
if ( pRoomIndex == NULL )
{
bug( "Char_to_room: NULL.", 0 );
return;
}
ch->in_room = pRoomIndex;
ch->next_in_room = pRoomIndex->people;
pRoomIndex->people = ch;
if ( !IS_NPC(ch) )
++ch->in_room->area->nplayer;
if ( ( obj = get_eq_char( ch, WEAR_LIGHT ) ) != NULL
&& obj->item_type == ITEM_LIGHT
&& obj->value[2] != 0 )
++ch->in_room->light;
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -