📄 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};#endifBOOL 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;}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 ) && 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 ){ return TRUE; } } return FALSE;}void NPC_Util_AnnounceFloor( int floorid , char *msg ){ int i; int playernum = CHAR_getPlayerMaxNum(); for(i=0;i<playernum;i++){ if( CHAR_getCharUse(i) && CHAR_getInt( i , CHAR_WHICHTYPE) == CHAR_TYPEPLAYER && CHAR_getInt( i , CHAR_FLOOR ) == floorid ){ CHAR_talkToCli( i , -1 , msg , CHAR_COLORWHITE ); } }}BOOL NPC_Util_moveItemToChar( int charindex, int itemindex, BOOL net ){ int emptyindex, oind ,cind; emptyindex = CHAR_findEmptyItemBox( charindex ); if( emptyindex < 0 ) return FALSE; if( !ITEM_CHECKINDEX( itemindex ) )return FALSE; oind = ITEM_getWorkInt( itemindex , ITEM_WORKOBJINDEX ); cind = ITEM_getWorkInt( itemindex , ITEM_WORKCHARAINDEX ); if( oind >= 0 ){ CHAR_ObjectDelete( oind ); CHAR_setItemIndex( charindex, emptyindex, itemindex ); ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1 ); ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, charindex ); if( net ) CHAR_sendItemDataOne( charindex, emptyindex); return TRUE; }else if( cind >= 0 ){ int itemgrp[2]; int itemindexinchara; if( cind == charindex )return FALSE; itemindexinchara = NPC_Util_SearchItemInChar( cind , itemindex); if( itemindexinchara == -1 )return FALSE; CHAR_setItemIndex( cind , itemindexinchara , -1 ); CHAR_complianceParameter(cind); itemgrp[0] = itemindexinchara; CHAR_setItemIndex( charindex , emptyindex , itemindex ); itemgrp[1] = emptyindex; if( net ) CHAR_sendItemData( charindex, itemgrp, arraysizeof(itemgrp)); ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1 ); ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, charindex ); return TRUE; } return FALSE;}BOOL NPC_Util_moveItemToMap( int itemindex , int fl , int x , int y, BOOL net ){ int oind,cind; if( !ITEM_CHECKINDEX( itemindex ) ) return FALSE; oind = ITEM_getWorkInt( itemindex , ITEM_WORKOBJINDEX ); cind = ITEM_getWorkInt( itemindex , ITEM_WORKCHARAINDEX ); if( oind >= 0 ){ return MAP_objmove( oind , OBJECT_getFloor(oind), OBJECT_getX(oind), OBJECT_getY(oind), fl,x,y); } else if( cind >= 0 ){ int itemindexinchara = NPC_Util_SearchItemInChar(cind,itemindex); if( itemindexinchara == -1 ) return FALSE; CHAR_setItemIndex( cind , itemindexinchara , -1 ); CHAR_complianceParameter(cind); if( net ) CHAR_sendItemDataOne( cind, itemindexinchara); if( CHAR_DropItemAbsolute( itemindex, fl,x,y,TRUE) < 0 ){ return FALSE; } else { return TRUE; } } return FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -