📄 area.cpp
字号:
#include "..\stdafx.h"
#include "..\LowerLayers\packed.h"
#include "..\LowerLayers\servertable.h"
#include "..\LowerLayers\mylog.h"
#include "CItem.h"
#include "Chatting.h"
#include "UserManager.h"
#include "BattleManager.h"
extern void SendCharacterCondition( CHARLIST*, int);
extern void UserAddBasicData( t_connection c[], int from, int to, t_server_user_add *p );
SORT_DATA PC_TABLE[DRAGON_MAX_CONNECTIONS_ + 1];
SORT_DATA NPC_TABLE[MAX_NPC_LIST];
SORT_DATA ITEM_TABLE[MAX_ITEM_LIST];
CMD_AREA CMD_AREA_TABLE[MAX_CMD_AREA];
int PC_COUNT = 0;
int NPC_COUNT = 0;
int ITEM_COUNT = 0;
int CMD_AREA_COUNT = 0;
// 2000/11/09, chan78 :: New CastMe2Other()
void CastMe2Other(int cn, t_packet *packet)
{
t_packet* a = packet;
if (connections[cn].dwAgentConnectionIndex)
{
for (int i = 0; i < MAX_AREA_BUFFER; ++i)
{
if (connections[cn].area_tbl[i].bAlive == TRUE)
{
if (connections[cn].area_tbl[i].Type == 1)
{
if (connections[connections[cn].area_tbl[i].ID].dwAgentConnectionIndex)
{
DWORD dwTargetAgentConnectionIndex = connections[connections[cn].area_tbl[i].ID].dwAgentConnectionIndex;
DWORD dwTargetID = connections[connections[cn].area_tbl[i].ID].dwIDForAgent;
if (g_pServerTable->GetPackedMsg( dwTargetAgentConnectionIndex))
{
if (g_pServerTable->GetPackedMsg(dwTargetAgentConnectionIndex)->GetUserNum() == 0)
{
g_pServerTable->GetPackedMsg(dwTargetAgentConnectionIndex)->SetMsg((char*)packet, sizeof(t_header) + packet->h.header.size);
}
g_pServerTable->GetPackedMsg(dwTargetAgentConnectionIndex)->AddUser(dwTargetID);
}
else
{
MyLog(LOG_FATAL, "Oops!!!(CI:%d, CN:%d)'s ->GetPackedMsg() is NULL", dwTargetAgentConnectionIndex, dwTargetID);
}
}
}
}
}
}
g_pServerTable->SendPackedMsg();
return;
}
void CastNPC2Other(int npc, t_packet *packet)
{ // NPC甫 啊瘤绊 乐绰 葛电 PC俊霸 谎妨霖促.
for (int i = 0; i < PC_COUNT; ++i)
{
for (int j = 0; j < MAX_AREA_BUFFER; ++j)
{
if (connections[PC_TABLE[i].ID].area_tbl[j].bAlive == TRUE)
{
if (connections[PC_TABLE[i].ID].area_tbl[j].Type == 2 && connections[PC_TABLE[i].ID].area_tbl[j].ID == npc && connections[PC_TABLE[i].ID].dwAgentConnectionIndex)
{
if (g_pServerTable->GetPackedMsg(connections[PC_TABLE[i].ID].dwAgentConnectionIndex))
{
if (g_pServerTable->GetPackedMsg(connections[PC_TABLE[i].ID].dwAgentConnectionIndex)->GetUserNum() == 0)
{
g_pServerTable->GetPackedMsg(connections[PC_TABLE[i].ID].dwAgentConnectionIndex)->SetMsg((char*)packet, sizeof(t_header) + packet->h.header.size);
}
g_pServerTable->GetPackedMsg(connections[PC_TABLE[i].ID].dwAgentConnectionIndex)->AddUser(connections[PC_TABLE[i].ID].dwIDForAgent);
}
else
{
MyLog(LOG_FATAL, "Oops!!!(CI:%d, CN:%d)'s ->GetPackedMsg() is NULL", PC_TABLE[i].ID, connections[PC_TABLE[i].ID].dwAgentConnectionIndex);
}
}
}
}
}
g_pServerTable->SendPackedMsg();
return;
}
// Modified by chan78 at 2000/11/09
void SendModifyPositionNPC( t_connection c[], int ch )
{
t_packet packet;
packet.h.header.type = CMD_MODIFY_POSITION;
packet.h.header.size = sizeof( t_server_modify_position );
packet.u.server_modify_position.server_id = ch + 10000;
packet.u.server_modify_position.gox = NPCList[ch].MoveGox;
packet.u.server_modify_position.goy = NPCList[ch].MoveGoy;
for (int i = 0; i < PC_COUNT; ++i)
{
for (int j = 0; j < MAX_AREA_BUFFER; ++j)
{
if (c[PC_TABLE[i].ID].area_tbl[j].bAlive == TRUE)
{
if (c[PC_TABLE[i].ID].area_tbl[j].Type == 2 && c[PC_TABLE[i].ID].area_tbl[j].ID == ch && c[PC_TABLE[i].ID].dwAgentConnectionIndex != 0)
{
if (g_pServerTable->GetPackedMsg(c[PC_TABLE[i].ID].dwAgentConnectionIndex))
{
if (g_pServerTable->GetPackedMsg(c[PC_TABLE[i].ID].dwAgentConnectionIndex)->GetUserNum() == 0)
{
g_pServerTable->GetPackedMsg(c[PC_TABLE[i].ID].dwAgentConnectionIndex)->SetMsg( (char*)&packet, (sizeof(t_header)+packet.h.header.size));
}
g_pServerTable->GetPackedMsg(c[PC_TABLE[i].ID].dwAgentConnectionIndex)->AddUser(c[PC_TABLE[i].ID].dwIDForAgent);
}
else
{
MyLog(LOG_FATAL, "Oops!!!(CI:%d, CN:%d)'s ->GetPackedMsg() is NULL", PC_TABLE[i].ID, connections[PC_TABLE[i].ID].dwAgentConnectionIndex);
}
}
}
}
}
g_pServerTable->SendPackedMsg();
}
// Modified by chan78 at 2000/11/09
void RecvNPCModifyPos( int cn, int id, int mx, int my )
{
id -= 10000;
if (id < NPC_LIST_START || id >= MAX_NPC_LIST)
{
return;
}
if (!connections[cn].dwAgentConnectionIndex || connections[cn].state < CONNECT_JOIN)
{
return;
}
if (NPCList[id].ctrlpc != cn)
{
return;
}
NPCList[id].MoveGox = NPCList[id].MoveSx = mx;
NPCList[id].MoveGoy = NPCList[id].MoveSy = my;
NPCList[id].MoveGox = mx*TILE_SIZE;
NPCList[id].MoveGoy = my*TILE_SIZE;
NPCList[id].MoveLength = NPCList[id].MovePathCount= 0;
SetArea(MOVE_NPC_AREA, id);
return;// 0906 KHS
t_packet packet;
packet.h.header.type = CMD_MODIFY_POSITION;
packet.h.header.size = sizeof(t_server_modify_position);
packet.u.server_modify_position.server_id = id + 10000;
packet.u.server_modify_position.gox = NPCList[id].MoveGox;
packet.u.server_modify_position.goy = NPCList[id].MoveGoy;
for (int i = 0; i < PC_COUNT; ++i)
{
for (int j = 0; j < MAX_AREA_BUFFER; ++j)
{
if (connections[PC_TABLE[i].ID].area_tbl[j].bAlive == TRUE)
{
if (connections[PC_TABLE[i].ID].area_tbl[j].Type == 2 && connections[PC_TABLE[i].ID].area_tbl[j].ID == id && connections[PC_TABLE[i].ID].dwAgentConnectionIndex)
{
if (g_pServerTable->GetPackedMsg(connections[PC_TABLE[i].ID].dwAgentConnectionIndex))
{
if (g_pServerTable->GetPackedMsg(connections[PC_TABLE[i].ID].dwAgentConnectionIndex)->GetUserNum() == 0)
{
g_pServerTable->GetPackedMsg(connections[PC_TABLE[i].ID].dwAgentConnectionIndex)->SetMsg( (char*)&packet, (sizeof(t_header)+packet.h.header.size));
}
g_pServerTable->GetPackedMsg(connections[PC_TABLE[i].ID].dwAgentConnectionIndex)->AddUser(connections[PC_TABLE[i].ID].dwIDForAgent);
}
else
{
MyLog(LOG_FATAL, "Oops!!!(CI:%d, CN:%d)'s ->GetPackedMsg() is NULL", PC_TABLE[i].ID, connections[PC_TABLE[i].ID].dwAgentConnectionIndex);
}
}
}
}
}
g_pServerTable->SendPackedMsg();
}
// Modified by chan78 at 2000/11/09
void SendMoveNPCArea(t_connection c[], int npc )
{
t_packet packet;
int i, j;
if( PC_COUNT <= 0 ) return;
packet.h.header.type = CMD_MOVE;
if( SettingMoveData_( npc+10000, &NPCList[npc], &packet ) == 0 ) return;
for(i = 0; i < PC_COUNT; i ++)
{
for(j = 0; j < MAX_AREA_BUFFER; j ++)
{
if(c[PC_TABLE[i].ID].area_tbl[j].bAlive == TRUE)
{
if(c[PC_TABLE[i].ID].area_tbl[j].Type == 2 && c[PC_TABLE[i].ID].area_tbl[j].ID == npc && c[PC_TABLE[i].ID].dwAgentConnectionIndex)
{
if( g_pServerTable->GetPackedMsg( c[PC_TABLE[i].ID].dwAgentConnectionIndex ) )
{
if( g_pServerTable->GetPackedMsg( c[PC_TABLE[i].ID].dwAgentConnectionIndex )->GetUserNum() == 0 )
{
g_pServerTable->GetPackedMsg( c[PC_TABLE[i].ID].dwAgentConnectionIndex )->SetMsg( (char*)&packet, (sizeof(t_header)+packet.h.header.size) );
}
g_pServerTable->GetPackedMsg( c[PC_TABLE[i].ID].dwAgentConnectionIndex )->AddUser( c[PC_TABLE[i].ID].dwIDForAgent );
}
else
{ //010815 lsw 皋技瘤 炼陛 荐沥
MyLog( LOG_FATAL, "SendMoveNPCArea Failed.(CI:%d, CN:%d)'s ->GetPackedMsg() is NULL Agent has problem", PC_TABLE[i].ID, connections[PC_TABLE[i].ID].dwAgentConnectionIndex );
}
}
}
}
}
g_pServerTable->SendPackedMsg();
};
void SendAttackNPCArea( t_connection c[], int npc )
{
g_pBattleManager->SendNpcAttack(npc);
}
// Modified by chan78 at 2000/11/09
void JustMessage( char *txt, ... )
{
return;
char Str[TEXT_LENGTH];
memset(Str, 0, TEXT_LENGTH);
va_list val;
va_start(val, txt);
vsprintf(Str, txt, val);
va_end(val);
int length = strlen( Str );
if(length <= 0 || length >= TEXT_LENGTH) return;
t_packet packet;
packet.h.header.size = sizeof(t_server_chat_data)-TEXT_LENGTH+length;
packet.h.header.type = CMD_CHAT_DATA;
packet.u.server_chat_data.length = (unsigned char)length;
packet.u.server_chat_data.type = (unsigned char)CHATTYPE_NORMAL;
memset(packet.u.server_chat_data.text, 0, TEXT_LENGTH);
memcpy(packet.u.server_chat_data.text, Str, length);
for (int i = DRAGON_CONNECTIONS_START; i < DRAGON_MAX_CONNECTIONS; ++i)
{
if(connections[i].dwAgentConnectionIndex && connections[i].state >= CONNECT_JOIN)
{
packet.u.server_chat_data.server_id = i;
if( g_pServerTable->GetPackedMsg( connections[i].dwAgentConnectionIndex ) )
{
if( g_pServerTable->GetPackedMsg( connections[i].dwAgentConnectionIndex )->GetUserNum() == 0 )
{
g_pServerTable->GetPackedMsg( connections[i].dwAgentConnectionIndex )->SetMsg( (char*)&packet, (sizeof(t_header)+packet.h.header.size) );
}
g_pServerTable->GetPackedMsg( connections[i].dwAgentConnectionIndex )->AddUser( connections[i].dwIDForAgent );
}
else
{
MyLog( LOG_FATAL, "Oops!!!(CI:%d, CN:%d)'s ->GetPackedMsg() is NULL", PC_TABLE[i].ID, connections[PC_TABLE[i].ID].dwAgentConnectionIndex );
}
}
}
g_pServerTable->SendPackedMsg();
}
void SendNPCChatArea( int npc, char *String, ... )
{
va_list val;
char Str[ TEXT_LENGTH];
t_packet packet;
if( String == NULL ) return;
va_start( val, String );
vsprintf( Str, String, val );
va_end( val );
int length = strlen( Str );
if( length == 0 ) return;
packet.h.header.type = CMD_CHAT_DATA;
{
packet.u.server_chat_data.server_id = npc+10000;
packet.u.server_chat_data.type = (unsigned char)CHATTYPE_NORMAL;
packet.u.server_chat_data.length = (unsigned char)length;
memcpy(packet.u.server_chat_data.text, Str, length);
}
packet.h.header.size = sizeof(t_server_chat_data)-TEXT_LENGTH+length;
CastNPC2Other( npc, &packet );
}
// Modified by chan78 at 2000/11/09
void SendChatArea(const int cn, t_packet *packet)
{
const int type = (int)packet->u.client_chat_data.type;
packet->u.client_chat_data.text[TEXT_LENGTH-1] = 0;//趣矫唱 窍绰 惑炔 锭巩俊 付瘤阜阑 澄巩磊肺 盲款促
const int iLen = ::strlen(packet->u.client_chat_data.text);
if(iLen <= 0 || iLen >= TEXT_LENGTH)
{
return;
}
packet->h.header.type = CMD_CHAT_DATA;
packet->h.header.size = sizeof(t_server_chat_data)-TEXT_LENGTH+iLen+1;
packet->u.server_chat_data.server_id = cn;
packet->u.server_chat_data.type = type;
packet->u.server_chat_data.length = iLen;///促青洒 困俊辑 255肺 阜绰促
t_connection *pConnect = &connections[cn];
for( int i = 0; i < MAX_AREA_BUFFER; i++ )
{
if( TRUE != pConnect->area_tbl[i].bAlive){continue;}
if( pConnect->area_tbl[i].Type == 1
&& pConnect->dwAgentConnectionIndex)
{
const DWORD dwTargetAgentConnectionIndex = connections[pConnect->area_tbl[i].ID].dwAgentConnectionIndex;
const DWORD dwTargetID = connections[pConnect->area_tbl[i].ID].dwIDForAgent;
// Modified by chan78 at 2000/12/13 :: 菩摹凳...
if( g_pServerTable->GetPackedMsg( dwTargetAgentConnectionIndex ) )
{
if( g_pServerTable->GetPackedMsg( dwTargetAgentConnectionIndex )->GetUserNum() == 0 )
{
g_pServerTable->GetPackedMsg( dwTargetAgentConnectionIndex )->SetMsg( (char*)packet, (sizeof(t_header)+packet->h.header.size) );
}
g_pServerTable->GetPackedMsg( dwTargetAgentConnectionIndex )->AddUser( dwTargetID );
}
else
{
// MyLog( LOG_FATAL, "Oops!!!(CI:%d, CN:%d)'s ->GetPackedMsg() is NULL", PC_TABLE[i].ID, connections[PC_TABLE[i].ID].dwAgentConnectionIndex );
MyLog( LOG_FATAL, "Oops!!!(CI:%d, CN:%d)'s ->GetPackedMsg() is NULL", dwTargetAgentConnectionIndex, dwTargetID );
}
}
}
g_pServerTable->SendPackedMsg();
}
extern int g_AI_Select; // LTS AI
void RemoveNPCControlData(int cn,int NPC_ID) // LTS NPC BUG
{
for (int i = 0; i < MAX_PC_CONTROL_NPC; ++i)
{
if (connections[cn].chrlst.ctrlnpc[i] == NPC_ID)
{
connections[cn].chrlst.ctrlnpc[i] = -1;
NPCList[NPC_ID].ctrlpc = -1; //巩力啊 积辨瘤 葛弗促.
return;
}
}
}
void AddNPCControlData(int cn,int NPC_ID) // LTS NPC BUG
{
}
void CheckNPCControlData(int cn,int NPC_ID) // LTS NPC BUG // 2锅掳 牢磊 规陛 磷篮 NPC
{
for (int i = 0; i < NPC_COUNT; ++i)
{ // 郴康开俊 AI且寸 给罐篮仇甸...阑 犁且寸
if (NPC_TABLE[i].X >= connections[cn].chrlst.X-ADD_AREA_X &&
NPC_TABLE[i].X <= connections[cn].chrlst.X+ADD_AREA_X &&
NPC_TABLE[i].Y >= connections[cn].chrlst.Y-ADD_AREA_Y &&
NPC_TABLE[i].Y <= connections[cn].chrlst.Y+ADD_AREA_Y)
{
if (!NPCList[NPC_TABLE[i].ID].IsDead())
{
if (NPCList[NPC_TABLE[i].ID].ctrlpc == -1)
{
AddNPCControlData(cn,NPC_TABLE[i].ID);
}
}
}
}
}
extern void CheckDungeonObject( int id, short int cn ); // 020620 YGI
int SendAddArea(t_connection c[], int cn, int type, int id)
{
t_packet packet;
if (type == 1)
{
if (c[id].chrlst.bAlive == REMOVE_)
{
return 0;
}
packet.h.header.type = CMD_USER_ADD;
packet.h.header.size = sizeof(t_server_user_add);
UserAddBasicData(c, id, cn, &packet.u.server_user_add); // NPC_Pattern.cpp
QueuePacket(c, cn, &packet, 1);
if (c[id].chrlst.MovePathCount) // 泅犁 捞悼窍绊 乐绰 吝捞搁....
{
if (SettingMoveData_(id, &c[id].chrlst, &packet))
{
packet.h.header.type = CMD_MOVE;
QueuePacket(c, cn, &packet, 1);
}
}
}
else if (type == 2)
{
if (NPCList[id].bAlive == REMOVE_)
{
return 0;
}
packet.h.header.type = CMD_NPC_ADD;
packet.h.header.size = sizeof(t_server_npc_add);
NPCAddBasicData(id, &packet.u.server_npc_add);
QueuePacket(c, cn, &packet, 1);
if (NPCList[id].patterntype == NPC_PATTERN_TAME_)
{
SendHostName(cn, &NPCList[id]);
}
if (NPCList[id].MovePathCount) // 泅犁 捞悼窍绊 乐绰 吝捞搁.... // LTS NPC BUG
{
if (SettingMoveData_(id + 10000, &NPCList[id], &packet))
{
packet.h.header.type = CMD_MOVE;
QueuePacket(c, cn, &packet, 1);
}
}
if (NPCList[id].patterntype != NPC_PATTERN_NO_MOVE_)
{
if (NPCList[id].ctrlpc == -1)
{
if (!NPCList[id].ChairNum) // LTS AI2 // 辑滚 淬寸 AI捞搁 牧飘费 且 鞘夸啊 绝促.
{
for (int i = 0 ; i < MAX_PC_CONTROL_NPC; ++i)
{
if (c[cn].chrlst.ctrlnpc[i] == -1)
{
SendNPCControlData(cn, id);
c[cn].chrlst.ctrlnpc[i] = id;
NPCList[ id].ctrlpc = cn;
break;
}
}
}
}
}
}
else if (type == 3)
{
if (ItemList[ id].bAlive == 0)
{
return 0;
}
//捞 酒贰啊 促 官差菌嚼聪促... this lsw
t_server_item_add* pi = &packet.u.server_item_add;
pi->item_id = id;
pi->item.item_no = ItemList[id].item_no;
pi->item.attr[0] = ItemList[id].attr[0];
pi->item.attr[1] = ItemList[id].attr[1];
pi->item.attr[2] = ItemList[id].attr[2];
pi->item.attr[3] = ItemList[id].attr[3];
pi->item.attr[4] = ItemList[id].attr[4];
pi->item.attr[5] = ItemList[id].attr[5];
pi->offx = ItemList[id].offx;
pi->offy = ItemList[id].offy;
pi->x = ItemList[id].x;
pi->y = ItemList[id].y;
// 020620 YGI
CheckDungeonObject(id,cn);
BYTE itempack[50];
int iZipSize= Zip((BYTE*)pi, sizeof(t_server_item_add), itempack, 100);
t_server_item_add_ziped* pii = &packet.u.server_item_add_ziped;
pii->zipedpack[0] = iZipSize;
packet.h.header.type = CMD_ITEM_ADD_ZIPED; //拘绵等 酒捞袍 菩哦
packet.h.header.size = iZipSize + 1;
memcpy(pii->zipedpack,itempack,iZipSize);
QueuePacket(c, cn, &packet, 1);
}
return 1;
}
int Zip( BYTE *pbIn, int iSize, BYTE *pbOut, int iMax)
{ // this lsw 菩哦 拘绵(?) 窃荐 //努扼捞攫飘俊绰 unzip 窃荐 鞘夸
int iStatusSize = (iSize - 1)/8 + 1;
pbOut[0] = iStatusSize;
BYTE cFlag = 0x01;
int iStatusPos = 1; // output buf狼 flag index
int iOutPos = iStatusSize + 1; // output buf狼 index
memset(&pbOut[1], 0, iStatusSize);
for (int i = 0; i < iSize; ++i)
{
if (pbIn[i])
{
pbOut[iStatusPos] |= cFlag;
pbOut[iOutPos++] = pbIn[i];
}
cFlag = cFlag << 1;
if (!cFlag)
{
cFlag = 0x01;
++iStatusPos;
}
}
return iOutPos;
}
int SendRemoveArea(t_connection c[], int cn, int type, int id)
{
switch (type)
{
case 1:
{
t_packet packet;
packet.h.header.type = CMD_USER_REMOVE;
packet.h.header.size = sizeof(t_server_user_remove);
packet.u.server_user_remove.server_id = id;
QueuePacket(c, cn, &packet, 1);
break;
}
case 2:
{
t_packet packet;
packet.h.header.type = CMD_NPC_REMOVE;
packet.h.header.size = sizeof(t_server_npc_remove);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -