📄 npc_pattern.cpp
字号:
}
else if( nx < px )
{
if( ny > py ) { dir = 1; }
else if( ny < py ) { dir = 3; }
else { dir = 2; }
}
else
{
if( ny > py ) { dir = 0; }
else { dir = 4; }
}
if ( bOdd == 0){ n->MoveDirTbl[ (c/2) ] = dir << 4; }
else { n->MoveDirTbl[ (c/2) ] += dir; }
c++;
bOdd = !bOdd;
px = nx;
py = ny;
}
n->MoveLength = c;
n->pathcount = 0;
n->MoveGox = tx * TILE_SIZE + 16 -5 + Random(10);
n->goy = ty * TILE_SIZE + 16 -5 + Random(10);
n->WalkTime = g_ClientTime; // ::timeGetTime();
n->MoveType = 0;
return 1;
}
return 0;
}
return 0;
} */
/*
int NPC_MakePath( CHARACTER *n, int tx, int ty, int how = 0 )
{
return NPC_MakePathBumn( n, tx, ty, how );
}
*/
int NPC_MakePathBumn( CHARACTER *n, int tx, int ty, int how = 0 )
{
CHARACTER t;
// 010515 KHS
if( n->eventnpc ) return 0;
if( CheckDestinationOk( tx * TILE_SIZE, ty * TILE_SIZE ) == 0 ) return 0;
memcpy( &t, n , sizeof( CHARACTER ) );
t.moveFlag = TRUE;
t.movetype = 0;
t.gox = tx * TILE_SIZE + 16;
t.goy = ty * TILE_SIZE + 16;
t.destx = tx, t.desty = ty;
n->MoveP = 0;
if ( PathBuild( &t ) )
{
t.moveFlag = FALSE;
t.movetype += 100;
SendMoveData( &t );
t.movetype -= 100;
//n->sendmove = 1;
return 1;
}
//n->sendmove = 0;
return 0;
}
int NPC_MakePathGuard( CHARACTER *n, int tx, int ty, int how )
{
CHARACTER t;
// 010515 KHS
if( n->eventnpc ) return 0;
if( CheckDestinationOk( tx * TILE_SIZE, ty * TILE_SIZE ) == 0 ) return 0;
memcpy( &t, n , sizeof( CHARACTER ) );
t.moveFlag = TRUE;
t.movetype = 0;
t.gox = tx * TILE_SIZE + 16;
t.goy = ty * TILE_SIZE + 16;
t.destx = tx, t.desty = ty;
t.MoveP = 0;
if ( PathBuild( &t ) )
{
t.moveFlag = FALSE;
t.movetype += 100;
SendMoveData( &t );
t.movetype -= 100;
return 1;
}
return 0;
}
int NPC_MakePathMaul( CHARACTER *n, int tx, int ty, int how )
{
CHARACTER t;
// 010515 KHS
if( n->eventnpc ) return 0;
if( CheckDestinationOk( tx * TILE_SIZE, ty * TILE_SIZE ) == 0 ) return 0;
memcpy( &t, n , sizeof( CHARACTER ) );
t.moveFlag = TRUE;
t.movetype = 0;
t.gox = tx * TILE_SIZE + 16;
t.goy = ty * TILE_SIZE + 16;
t.destx = tx, t.desty = ty;
t.MoveP = 0;
if ( PathBuild( &t ) )
{
t.moveFlag = FALSE;
t.movetype += 100;
SendMoveData( &t );
t.movetype -= 100;
return 1;
}
return 0;
}
/*
int NPC_MakePathBumn( CHARACTER *n, int tx, int ty, int how )
{
int dir;
int oldx, oldy;
int num;
int i;
n->tx = tx;
n->ty = ty;
n->how = how;
if( n->pathcount < 2 )
{
int x = n->x / TILE_SIZE;
int y = n->y / TILE_SIZE;
dir = NPC_GetDir( x, y, tx, ty );
for( i = 0 ; i < how ; i ++)
{
oldx = x; oldy = y;
switch( dir )
{
case 0 : y ++; break;
case 1 : x --; y ++; break;
case 2 : x --; break;
case 3 : x --; y --; break;
case 4 : y --; break;
case 5 : x ++; y --; break;
case 6 : x ++; break;
case 7 : x ++; y ++; break;
}
if( FreeTile( n->x / TILE_SIZE, n->y / TILE_SIZE, x, y ) )
{
if ( i%2 == 0){ n->MoveDirTbl[ (i/2) ] = dir << 4; }
else { n->MoveDirTbl[ (i/2) ] += dir; }
}
else
{
x = oldx;
y = oldy;
break;
}
}
/ n->MoveLength = i;
n->pathcount = 0;
n->MoveGox = x * TILE_SIZE + 16;
n->goy = y * TILE_SIZE + 16;
n->WalkTime = g_ClientTime; // ::timeGetTime();
n->MoveType = 0;
printf( "NPC Move... \n");
}
return i;
}
*/
inline bool NPC_IsMoving(CHARACTER* n)
{ //< CSD-040107
return (n->desttime > g_ClientTime) ? true:false;
} //> CSD-040107
int NPC_Hostile( CHARACTER *n )
{
return n->peacests;
}
int NPC_StillAttack( CHARACTER *n)
{
if( n->attackcount > 6 +Random(5) )
{
n->attackcount = 0;
return 0;
}
return 1;
}
int NPC_IsAttackableRange( CHARACTER *n )
{
CHARACTER *ch;
int t;
int x;
int y;
int tx;
int ty;
if( n->targetid < 0 ) goto FAIL_;
ch = ReturnCharacterPoint( n->targetid );
if( ch == NULL ) goto FAIL_;
if( IsDead( ch ) ) goto FAIL_;
x = n->x;
y = n->y;
tx = ch->x;
ty = ch->y;
t = (tx-x)*(tx-x) + (ty-y)*(ty-y);
if( t < NPC_GetAttackRange(n) ) // ### 阁胶磐狼 荤沥芭府 鞘夸..
{
// ###父距 荤捞俊 绢恫霸 尝绢 乐栏搁 return 0;
return 1;
}
FAIL_:
return 0;
}
int NPC_IsInBossRange( CHARACTER *n )
{
if( n->bossid == -1 ) return 0;
LPCHARACTER boss = ReturnCharacterPoint( n->bossid );
if( boss == NULL ) return 0;
if( !IsDead( boss ) )
{
if( BoxAndDotCrash( boss->x / TILE_SIZE-4, boss->y / TILE_SIZE - 4, 8, 8, n->x / TILE_SIZE, n->y / TILE_SIZE ))
{
return 1;
}
}
return 0;
}
int NPC_IsInHostRange( CHARACTER *n )
{
if( n->HostId == -1 ) return 0;
CHARACTER *host = ReturnCharacterPoint( n->HostId );
if( host == NULL ) return 0;
if( strcmp( host->name, n->HostName ) ) return 0; // ID客 捞抚捞 崔扼......
if( !IsDead( host ) )
{
if( BoxAndDotCrash( host->x / TILE_SIZE-4, host->y / TILE_SIZE - 4, 8, 8, n->x / TILE_SIZE, n->y / TILE_SIZE ))
{
return 1;
}
}
return 0;
}
// 泅犁 版厚捍捞 荤侩窍哥 pk茄 仇阑 茫绰促.
//
int NPC_IsWhoNearRedPC(CHARACTER *npc, int range)
{ //< CSD-040107
LPCHARACTER tempch = NULL;
#ifdef _NATION_APPLY_
const int nation = MapInfo[MapNumber].nation;
// 刚历 促弗 唱扼仇捞 乐栏搁 弊仇阑 傍拜茄促.
if (MapNumber != 30)
{
if (npc->nRace == GUARD)
{
tempch = Hero;
while (tempch)
{
if (!IsDead(tempch) && tempch->lv > 7 && !tempch->IsCounselor())
{
if (tempch->sprno == 1 || tempch->sprno == 0)
{
if (IsNK(tempch, nation) >= 5 || IsEnemyNation(tempch->name_status.nation, nation))
{
return tempch->id;
}
}
}
tempch = tempch->lpNext;
}
}
}
#endif
tempch = Hero;
while (tempch)
{
if (!IsDead(tempch))
{
if (IsNK(tempch) >= 5 || tempch->dummy_pk > 10)
{
return tempch->id;
}
}
tempch = tempch->lpNext;
}
return -1;
} //> CSD-040107
// NPC甫 焊绰 PC啊 乐绰啊?
int NPC_IsTherePC( CHARACTER *npc, int range )
{
LPCHARACTER tempch = Hero;
while( tempch )
{
if( !IsDead( tempch ))
if( tempch->type != SPRITETYPE_NPC && tempch->type != SPRITETYPE_MONSTER )
{
return tempch->id;
}
tempch = tempch->lpNext;
}
return -1;
}
int NPC_IsWhoNearOtherNationPc( int npc_nation, LPCHARACTER npc, int range )
{
int x = npc->x;
int y = npc->y;
int tx, ty;
DWORD tmin, min = 0xFFFFFFFF;
int findch = -1;
int sx, ex;
int sy, ey;
LPCHARACTER tempch;
int mx = x / TILE_SIZE;
int my = y / TILE_SIZE;
sx = mx - range; if( sx < 0 ) sx = 0;
ex = mx + range; if( ex >= g_Map.file.wWidth ) ex = g_Map.file.wWidth-1;
sy = my - range; if( sy < 0 ) sy = 0;
ey = my + range; if( ey >= g_Map.file.wHeight ) ey = g_Map.file.wHeight -1;
tempch = Hero;
while( tempch )
{
if( !IsDead( tempch ))
{
switch( tempch->sprno )
{
case 0 :
case 1 :
// case 18 :
// case 19 :
// case 20 :
if( npc_nation == tempch->name_status.nation ) break;
tx = tempch->x;
ty = tempch->y;
tmin = (tx-x)*(tx-x) + (ty-y)*(ty-y);
if( tmin < min )
{
min = tmin;
findch = tempch->id;
}
break;
}
}
tempch = tempch->lpNext;
}
return findch;
}
int NPC_IsWhoNearPC( CHARACTER *npc, int range )
{
int x = npc->x;
int y = npc->y;
int tx, ty;
DWORD tmin, min = 0xFFFFFFFF;
int findch = -1;
int sx, ex;
int sy, ey;
LPCHARACTER tempch;
int mx = x / TILE_SIZE;
int my = y / TILE_SIZE;
sx = mx - range; if( sx < 0 ) sx = 0;
ex = mx + range; if( ex >= g_Map.file.wWidth ) ex = g_Map.file.wWidth-1;
sy = my - range; if( sy < 0 ) sy = 0;
ey = my + range; if( ey >= g_Map.file.wHeight ) ey = g_Map.file.wHeight -1;
tempch = Hero;
while( tempch )
{
if (!IsDead(tempch) && !(tempch->condition&CON_STONE) && !(tempch->viewtype == VIEWTYPE_OBSERVE_))
{ //< CSD-TW-030606
switch( tempch->sprno )
{
case 0:
case 1:
{
tx = tempch->x;
ty = tempch->y;
tmin = (tx-x)*(tx-x) + (ty-y)*(ty-y);
if( tmin < min )
{
min = tmin;
findch = tempch->id;
}
break;
}
}
} //> CSD-TW-030606
tempch = tempch->lpNext;
}
return findch;
}
int NPC_WhoIsAttackMyBaby( CHARACTER *n )
{
LPCHARACTER tempch = Hero;
while( tempch )
{
if( !IsDead( tempch ) && n != tempch && tempch->type == SPRITETYPE_MONSTER )
{
if( tempch->bossid == n->id )
{
if( tempch->attacked != -1 )
{
tempch->attacked = -1;
return tempch->id;
}
}
}
tempch = tempch->lpNext;
}
return -1;
}
int NPC_WhoIsBoss( CHARACTER *n )
{
DWORD maxexp = 0;
int x = n->x, y = n->y;
int bossid = -1;
int ex, ey;
DWORD dis;
int c = 0;
// n->bossid = -1;
LPCHARACTER tempch = Hero;
while( tempch )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -