📄 npcutil.c
字号:
#include "version.h"
#include <string.h>
#include "common.h"
#include "char.h"
#include "char_base.h"
#include "configfile.h"
#include "object.h"
#include "item.h"
#include "map_deal.h"
#include "npcutil.h"
#include "npc_door.h"
#include "readmap.h"
#include "npccreate.h"
#include "enemy.h"
// CoolFish: Family 2001/7/29
#include "family.h"
#include "saacproto_cli.h"
#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) )
extern struct FM_POINTLIST fmpointlist;
#ifdef _PERSONAL_FAME // Arminius 8.30: 家族个人声望
// Arminius: 我把声望值减半
int FMAdvTbl[] = { // 家族冒险 Table
0, // 0
15, // 1
5, // 2
0, // 3
10, // 4
5, // 5
0, // 6
0, // 7
30, // 8
0, // 9
0, // 10
0, // 11
68, // 12
68, // 13
0, // 14
15, // 15
120, // 16
90, // 17
0, // 18
120, // 19
0, // 20
0, // 21
60, // 22
0, // 23
0, // 24
0, // 25
60, // 26
0, // 27
0, // 28
0, // 29
0, // 30
60, // 31
0, // 32
0, // 33
30, // 34
225, // 35
0, // 36
0, // 37
60, // 38
135, // 39
600, // 40
0, // 41
360, // 42
0, // 43
0, // 44
480, // 45
840, // 46
0, // 47
600, // 48
600, // 49
600, // 50
600, // 51
600, // 52
600, // 53
720, // 54
0, // 55
0, // 56
0, // 57
0, // 58
0, // 59
0, // 60
0, // 61
0, // 62
120, // 63
900, // 64
0, // 65
0, // 66
0, // 67
0, // 68
0, // 69
0, // 70
15000, // 71
20000, // 72
0, // 73
0, // 74
0, // 75
0, // 76
0, // 77
0, // 78
0, // 79
0, // 80
1200, // 81
3000, // 82
0, // 83
1500, // 84
0, // 85
0, // 86
100, // 87
0, // 88
400, // 89
0, // 90
0, //91
0, // 92
0, // 93
0, // 94
0, // 95
0, // 96
100, // 97
0, // 98
0, // 99
0, // 100
0, //101
0, //102
0, //103
0, //104
600, // 105
0, // 106
100, // 107
0, // 108
0, // 109
400, // 110
500, // 111
1000, // 112
100, // 113
300, // 114
0, // 115
500, // 116
15000, // 117
0, // 118
0, // 119
0, // 120
0, // 121
0, // 122
0, // 123
0, // 124
400, // 125
300, // 126
0, // 127
0, // 128
0, // 129
0, // 130
0, // 131
0, // 132
500, // 133
};
#endif
BOOL NPC_Util_AddOneTitle( int charindex, int titleindex )
{
int i;
Char *c ;
if( !CHAR_CHECKINDEX( charindex ) )return FALSE;
c = CHAR_getCharPointer( charindex );
// CoolFish: +1 2001/11/05
if (!c) return FALSE;
for(i=0;i<CHAR_TITLEMAXHAVE;i++){
if( c->indexOfHaveTitle[i] == -1 ){
c->indexOfHaveTitle[i] = titleindex;
return TRUE;
}
}
return FALSE;
}
BOOL NPC_Util_HaveTitle( int charindex , int titleindex )
{
int i;
Char *c;
if( !CHAR_CHECKINDEX( charindex ) )return -1;
c = CHAR_getCharPointer( charindex );
// CoolFish: +1 2001/11/05
if (!c) return FALSE;
for(i=0;i<CHAR_TITLEMAXHAVE;i++){
if( c->indexOfHaveTitle[i] == titleindex ){
return TRUE;
}
}
return FALSE;
}
BOOL NPC_Util_Nearby( int x1 , int y1, int x2 , int y2 )
{
if( ABS( x1 - x2 ) <= 1 &&
ABS( y1 - y2 ) <= 1 ){
return TRUE;
} else {
return FALSE;
}
}
BOOL NPC_Util_CharNearby(int ind1,int ind2)
{
if( !CHAR_CHECKINDEX(ind1)) return FALSE;
if( !CHAR_CHECKINDEX(ind2)) return FALSE;
if( CHAR_getInt( ind1 , CHAR_FLOOR ) !=
CHAR_getInt( ind2 , CHAR_FLOOR ) ){
return FALSE;
}
return NPC_Util_Nearby( CHAR_getInt( ind1,CHAR_X),
CHAR_getInt( ind1,CHAR_Y),
CHAR_getInt( ind2,CHAR_X),
CHAR_getInt( ind2,CHAR_Y));
}
static struct ynset
{
int value;
char string[32];
}yntable[] ={
{ 0 , "no" },
{ 0 , "No" },
{ 0 , "NO" },
{ 0 , "NO" },
{ 0 , "No" },
{ 0 , "no" },
{ 0 , "否" },
{ 0 , "否" },
{ 1 , "yes" },
{ 1 , "Yes" },
{ 1 , "YES" },
{ 1 , "YES" },
{ 1 , "Yes" },
{ 1 , "yes" },
{ 1 , "是" },
{ 1 , "是" },
};
int NPC_Util_YN(char *input )
{
int i;
for(i=0;;i++){
int j;
if( input[i] == '\0' ){
return -1;
}
for(j=0;j<arraysizeof(yntable);j++){
if( input[i] == yntable[j].string[0] &&
strncmp( input+i, yntable[j].string,
strlen(yntable[j].string))==0){
return yntable[j].value;
}
}
}
return -1;
}
int NPC_Util_getDirFromTwoPoint( POINT* pstart, POINT* pend )
{
/* y*x */
static int dirtable[3][3]={
{7, 0, 1},
{6,-1, 2},
{5, 4, 3},
};
int difx, dify;
difx = pend->x - pstart->x;
dify = pend->y - pstart->y;
if( difx < 0 )difx=-1;
else if( difx > 0 )difx=1;
if( dify < 0 )dify=-1;
else if( dify > 0 )dify=1;
return dirtable[dify+1][difx+1];
}
int NPC_Util_countHaveItem( int meindex , int itemid )
{
int i, count=0, itemindex;
if( !CHAR_CHECKINDEX(meindex))return -1;
for( i=0 ; i<CHAR_MAXITEMHAVE ; i++ ){
itemindex = CHAR_getItemIndex( meindex , i );
if( !ITEM_CHECKINDEX( itemindex)) continue;
if( ITEM_getInt( meindex, ITEM_ID) == itemid ) count++;
}
return count;
}
BOOL NPC_Util_isBackContact( int frontindex , int backindex )
{
int dir;
int x,y;
dir = (CHAR_getInt( frontindex , CHAR_DIR ) + 4 ) % 8;
VALIDATEDIR(dir);
CHAR_getCoordinationDir( dir ,
CHAR_getInt( frontindex , CHAR_X ),
CHAR_getInt( frontindex , CHAR_Y ),
1 ,
&x , &y );
if( x == CHAR_getInt( backindex , CHAR_X )
&& y == CHAR_getInt( backindex , CHAR_Y )
&& CHAR_getInt( backindex , CHAR_DIR )
== CHAR_getInt( frontindex , CHAR_DIR ) )
return TRUE;
else
return FALSE;
}
BOOL NPC_Util_isFaceToFace( int index1, int index2, int distance )
{
int i;
if(CHAR_getInt(index1,CHAR_FLOOR) != CHAR_getInt(index2,CHAR_FLOOR)){
return FALSE;
}
if(CHAR_getInt(index1,CHAR_X) == CHAR_getInt(index2,CHAR_X )
&& CHAR_getInt(index1,CHAR_Y) == CHAR_getInt(index2,CHAR_Y) ){
return FALSE;
}
for( i=1;i<=distance;i++ ){
int walked_x, walked_y;
CHAR_getCoordinationDir( CHAR_getInt(index1,CHAR_DIR)
, CHAR_getInt(index1,CHAR_X)
, CHAR_getInt(index1,CHAR_Y)
,i, &walked_x, &walked_y );
if( CHAR_getInt(index2,CHAR_X) == walked_x
&& CHAR_getInt(index2,CHAR_Y) == walked_y ){
CHAR_getCoordinationDir( CHAR_getInt(index2,CHAR_DIR)
, CHAR_getInt(index2,CHAR_X)
, CHAR_getInt(index2,CHAR_Y)
,i, &walked_x, &walked_y );
if( CHAR_getInt(index1,CHAR_X) == walked_x
&& CHAR_getInt(index1,CHAR_Y) == walked_y ){
return TRUE;
}else{
return FALSE;
}
}
}
return FALSE;
}
#ifdef _NPCSERVER_NEW
BOOL NPC_UtilObj_isFaceToFace( int npcobjindex, int objindex, int distance )
{
int i;
int npc_floor, npc_x, npc_y, npc_dir;
npc_floor = OBJECT_getFloor( npcobjindex);
npc_x = OBJECT_getX( npcobjindex);
npc_y = OBJECT_getY( npcobjindex);
npc_dir = OBJECT_getNpcdir( npcobjindex);
if( OBJECT_getFloor( objindex) != npc_floor )
return FALSE;
if( OBJECT_getX( objindex) == npc_x && OBJECT_getY( objindex) == npc_y )
return FALSE;
for( i=1; i<=distance; i++ ){
int walked_x, walked_y;
CHAR_getCoordinationDir( OBJECT_getNpcdir( objindex)
, OBJECT_getX( objindex), OBJECT_getY( objindex)
, i, &walked_x, &walked_y );
if( npc_x == walked_x && npc_y == walked_y ){
return TRUE;
}else{
return FALSE;
}
}
return FALSE;
}
#endif
BOOL NPC_Util_isFaceToChara( int index1, int index2, int distance )
{
int i;
if(CHAR_getInt(index1,CHAR_FLOOR) != CHAR_getInt(index2,CHAR_FLOOR)){
return FALSE;
}
if(CHAR_getInt(index1,CHAR_X) == CHAR_getInt(index2,CHAR_X )
&& CHAR_getInt(index1,CHAR_Y) == CHAR_getInt(index2,CHAR_Y) ){
/* 井今卅匀化中凶日FALSE */
return FALSE;
}
for( i=1;i<=distance;i++ ){
/* 引内}中匀仇户及平乓仿互汹中凶 及甄 毛菲户月 */
int walked_x, walked_y;
CHAR_getCoordinationDir( CHAR_getInt(index1,CHAR_DIR)
, CHAR_getInt(index1,CHAR_X)
, CHAR_getInt(index1,CHAR_Y)
,i, &walked_x, &walked_y );
if( CHAR_getInt(index2,CHAR_X) == walked_x
&& CHAR_getInt(index2,CHAR_Y) == walked_y )
{
return TRUE;
}else{
return FALSE;
}
}
/* 兮氏兮氏褐卅日卅井匀凶日FALSE */
return FALSE;
}
BOOL NPC_Util_charIsInFrontOfChar( int index1, int index2, int distance )
{
int i;
if(CHAR_getInt(index1,CHAR_FLOOR) != CHAR_getInt(index2,CHAR_FLOOR)){
return FALSE;
}
if(CHAR_getInt(index1,CHAR_X) == CHAR_getInt(index2,CHAR_X )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -