📄 npc.cpp
字号:
// Npc.cpp: implementation of the CNpc class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "server.h"
#include "USER.h"
#include "Npc.h"
#include "Extern.h"
#include "MAP.h"
#include "BufferEx.h"
#include "Mcommon.h"
#include "scdefine.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern CRITICAL_SECTION m_CS_EventItemLogFileWrite;
//////////////////////////////////////////////////////////////////////
// Fortress Paket Variable
extern CRITICAL_SECTION m_CS_FortressData;
extern CPtrList RecvFortressData;
extern long nFortressDataCount;
//int surround_x[8] = {-2, -1, 0, 1, 2, 1, 0, -1};
//int surround_y[8] = {0, -1, -2, -1, 0, 1, 2, 1};
int surround_x[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int surround_y[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int g_iMoonEvent = 1;
//#define STEP_DELAY //440
#define UPDATE_EVENT_INVEN_TIME 12
//////////////////////////////////////////////////////////////////////
// Inline Function
//
inline int CNpc::GetUid(int x, int y )
{
MAP* pMap = g_zone[m_ZoneIndex];
return pMap->m_pMap[x][y].m_lUser;
}
inline BOOL CNpc::SetUid(int x, int y, int id)
{
MAP* pMap = g_zone[m_ZoneIndex];
if(pMap->m_pMap[x][y].m_bMove != 0) return FALSE;
if(pMap->m_pMap[x][y].m_lUser != 0 && pMap->m_pMap[x][y].m_lUser != id ) return FALSE;
pMap->m_pMap[x][y].m_lUser = id;
return TRUE;
}
BOOL CNpc::SetUidNPC(int x, int y, int id)
{
MAP* pMap = g_zone[m_ZoneIndex];
if(pMap->m_pMap[x][y].m_bMove != 0) return FALSE;
if(pMap->m_pMap[x][y].m_lUser != 0 && pMap->m_pMap[x][y].m_lUser != id ) return FALSE;
pMap->m_pMap[x][y].m_lUser = id;
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CNpc::CNpc()
{
m_NpcVirtualState = NPC_STANDING;
m_NpcState = NPC_LIVE;
InitTarget();
m_ItemUserLevel = 0;
// m_Delay = 0; // 促澜 惑怕肺 傈捞登扁 鳖瘤狼 矫埃( mili/sec )
// m_dwLastThreadTime = 0;
m_Delay = 0;
m_dwLastThreadTime = GetTickCount();
m_sClientSpeed = 0; // 努扼捞攫飘 局聪甫 困茄 捞悼 厚啦
m_dwStepDelay = 0; // 促澜 浦哦鳖瘤狼 矫埃 掉饭捞
m_tNpcAttType = 0; // 傍拜 己氢
m_tNpcLongType = 0; // 盔芭府(1), 辟芭府(0)
m_tNpcGroupType = 0; // 档框阑 林绰衬(1), 救林绰衬?(0)
// m_tNpcTraceType = 0; // 场鳖瘤 蝶扼埃促(1), 矫具俊辑 绝绢瘤搁 弊父(0)
m_pPath = NULL;
m_pOrgMap = NULL;
// m_pMap = NULL;
m_lMapUsed = 0; // 甘 皋葛府焊龋
m_bFirstLive = TRUE;
m_tWeaponClass = BRAWL;
m_dwDelayCriticalDamage = 0;
m_dwLastAbnormalTime = GetTickCount();
::ZeroMemory(m_pMap, sizeof(m_pMap));// 老瞒盔 甘栏肺 檬扁拳茄促.
m_tAbnormalKind = 0;
m_dwAbnormalTime = 0;
m_presx = -1;
m_presy = -1;
m_lEventNpc = 0;
m_pGuardStore = NULL; // 辨靛傈阑困秦 秦寸 惑痢阑 啊瘤绊 柯促.
m_pGuardFortress = NULL;
m_tRepairDamaged = 0;
m_tNCircle = NPC_NCIRCLE_DEF_STATE;
m_lFortressState = 0;
m_lDamage = 0;
m_bSummon = FALSE;
m_sSummonOrgZ = m_sOrgZ;
m_sSummonOrgX = m_sOrgX;
m_sSummonOrgY = m_sOrgY;
m_SummonZoneIndex = m_ZoneIndex;
m_bSummonDead = FALSE;
m_lNowSummoning = 0;
m_lKillUid = -1;
m_sQuestSay = 0;
InitSkill();
InitUserList();
}
CNpc::~CNpc()
{
ClearPathFindData();
InitUserList();
}
//////////////////////////////////////////////////////////////////////
// NPC 胶懦沥焊甫 檬扁拳 茄促.
//
void CNpc::InitSkill()
{
for(int i = 0; i < SKILL_NUM; i++)
{
m_NpcSkill[i].sSid = 0;
m_NpcSkill[i].tLevel = 0;
m_NpcSkill[i].tOnOff = 0;
}
}
///////////////////////////////////////////////////////////////////////
// 辨茫扁 单捞磐甫 瘤款促.
//
void CNpc::ClearPathFindData()
{
::ZeroMemory(m_pMap, sizeof(m_pMap)); // 老瞒盔 甘阑 困秦
/* int i;
if(m_pMap)
{
int **tmp = m_pMap;
m_pMap = NULL;
for(i = 0; i < m_vMapSize.cx; i++)
{
delete[] tmp[i];
}
delete[] tmp;
}
*/
}
///////////////////////////////////////////////////////////////////////
// NPC 啊 贸澜 积扁芭唱 磷菌促啊 混酒朝 锭狼 贸府
//
BOOL CNpc::SetLive(COM* pCom)
{
NpcTrace(_T("SetLive()"));
if(m_tRepairDamaged > 0) return FALSE; // 傍己傈吝 颊惑 罐疽促搁 荐府瞪锭鳖瘤 弊措肺 蜡瘤登绢具窃...
if(m_pGuardFortress && m_tGuildWar == GUILD_WARRING)
{
if(!m_bFirstLive) return FALSE;
}
else m_tGuildWar = GUILD_WAR_AFFTER; // 葛电 各阑 辨靛傈俊 措秦辑 檬扁拳茄促...
if(m_bSummonDead) // 家券夌菌带 各俊 措秦辑
{
m_ZoneIndex = m_TableZoneIndex;
m_sCurZ = m_sOrgZ = m_sTableOrgZ;
m_sOrgX = m_sTableOrgX;
m_sOrgY = m_sTableOrgY;
m_pOrgMap = g_zone[m_ZoneIndex]->m_pMap; // MapInfo 沥焊 悸泼
m_bSummonDead = FALSE;
}
// NPC狼 HP, PP 檬扁拳 ----------------------//
int i = 0, j = 0;
m_sHP = m_sMaxHP;
m_sPP = m_sMaxPP;
int iTryLiveCount = 0;
InitTarget();
InitUserList(); // 鸥百阑困茄 府胶飘甫 檬扁拳.
// NPC 檬扁困摹 搬沥 ------------------------//
MAP* pMap = g_zone[m_ZoneIndex];
m_nInitMinX = m_sOrgX - m_sMinX; if(m_nInitMinX < 1) m_nInitMinX = 1;
m_nInitMinY = m_sOrgY - m_sMinY; if(m_nInitMinY < 1) m_nInitMinY = 1;
m_nInitMaxX = m_sOrgX + m_sMaxX; if(m_nInitMaxX >= pMap->m_sizeMap.cx) m_nInitMaxX = pMap->m_sizeMap.cx - 1;
m_nInitMaxY = m_sOrgY + m_sMaxY; if(m_nInitMaxY >= pMap->m_sizeMap.cy) m_nInitMaxY = pMap->m_sizeMap.cy - 1;
CPoint pt;
CPoint ptTemp;
int modify_index = 0;
char modify_send[2048];
// if(m_lEventNpc == 0 && m_sEvent == 1000) return TRUE;//@@@@@@@@@@@@@@@@@@@@@@ Test Code(烙矫肺 各阑 家券窍扁困秦)
if(m_lEventNpc == 1 && !m_bFirstLive)
{
// 蜡历俊霸 NPC 沥焊傈价...
// 捞蜡 : 磷篮 葛嚼阑 焊咯拎具窍扁锭巩俊 促澜 府哩瞪 瞒肥啊 棵锭 INFO_DELETE甫 焊辰促.
::ZeroMemory(modify_send, sizeof(modify_send));
for(int i = 0; i < NPC_NUM; i++)
{
if(g_arEventNpcThread[0]->m_ThreadInfo.pNpc[i] != NULL)
{
if(g_arEventNpcThread[0]->m_ThreadInfo.pNpc[i]->m_sNid == m_sNid)
{
FillNpcInfo(modify_send, modify_index, INFO_DELETE);
SendInsight(pCom, modify_send, modify_index);
g_arEventNpcThread[0]->m_ThreadInfo.pNpc[i] = NULL;
InterlockedExchange(&m_lEventNpc, (LONG)0);
InterlockedExchange(&g_arEventNpcThread[0]->m_ThreadInfo.m_lNpcUsed[i], (LONG)0);
return TRUE;
}
}
}
return TRUE;
}
if(m_tNpcType != NPCTYPE_MONSTER && m_bFirstLive)//NPCTYPE_DOOR || m_tNpcType == NPCTYPE_GUARD)
{
m_nInitX = m_sCurX = m_sOrgX;
m_nInitY = m_sCurY = m_sOrgY;
pMap->m_pMap[m_sCurX][m_sCurY].m_lUser = m_sNid + NPC_BAND;
// TRACE("NPC DOOR %s(nid = %d) - %d %d\n", m_strName, m_sNid, m_sCurX, m_sCurY);
CPoint temp = ConvertToClient(m_sCurX, m_sCurY);
TRACE("NPC DOOR %s(nid = %d) - %d %d\n", m_strName, m_sNid, temp.x, temp.y);
}
else
{
while(1)
{
i++;
if(m_lEventNpc == 1) // 家券各老版快 登档废捞搁 贸澜 瘤沥茄 谅钎肺
{
if(pMap->m_pMap[m_sOrgX][m_sOrgY].m_bMove == 0)
{
pt.x = m_sOrgX;
pt.y = m_sOrgY;
m_nInitX = m_sCurX = pt.x;
m_nInitY = m_sCurY = pt.y;
//ptTemp = ConvertToClient(m_sCurX, m_sCurY);
break;
}
else
{
pt = FindNearRandomPoint(m_sOrgX, m_sOrgY);
if(pt.x <= 0 || pt.y <= 0)
{
pt.x = myrand(m_nInitMinX, m_nInitMaxX);
pt.y = myrand(m_nInitMinY, m_nInitMaxY);
}
}
}
else
{
pt.x = myrand(m_nInitMinX, m_nInitMaxX);
pt.y = myrand(m_nInitMinY, m_nInitMaxY);
// Test Code By Youn Gyu 02-08-13 (泅犁绰 林函 25伎肺父 力茄)
if( m_sCurZ != 1 && m_sCurZ != 1005 ) // 老窜 带怜父 茫绰促.
{
if(m_tNpcType == NPCTYPE_MONSTER)
{
if( !CheckUserForNpc_Live(pt.x, pt.y) )
{
iTryLiveCount += 1;
if(iTryLiveCount >= 20) return FALSE;
else continue;
}
}
}
//TRACE("MONSTER %s(nid = %d) - %d %d\n", m_strName, m_sNid, m_sCurX, m_sCurY);
}
if(pt.x < 0 || pt.x >= pMap->m_sizeMap.cx) continue;
if(pt.y < 0 || pt.y >= pMap->m_sizeMap.cy) continue;
if(pMap->m_pMap[pt.x][pt.y].m_bMove != 0 || pMap->m_pMap[pt.x][pt.y].m_lUser != 0)
{
if(i >= 100)
{
m_nInitX = m_sCurX = m_sOrgX;
m_nInitY = m_sCurY = m_sOrgY;
// TRACE("sid = %d, loop = %d My standing point is invalid x = %d, y = %d\n", m_sSid, i, pt.x, pt.y);
InterlockedIncrement(&g_CurrentNPCError);
return FALSE;
// break;
/* DeleteNPC();// 昏力啊 酒丛...
TRACE("sid = %d, loop = %d My standing point is invalid x = %d, y = %d\n", m_sSid, i, pt.x, pt.y);
return FALSE;
*/
}
continue;
}
m_nInitX = m_sCurX = pt.x;
m_nInitY = m_sCurY = pt.y;
// ptTemp = ConvertToClient(m_sCurX, m_sCurY);
break;
}
}
SetUid(m_sCurX, m_sCurY, m_sNid + NPC_BAND);
if(m_sDimension > 0) SetMapTypeBeforeGuildWar(pCom); // 甘阑 悸泼茄促.
// 惑怕捞惑 沥焊 檬扁拳
m_dwLastAbnormalTime = GetTickCount();
m_tAbnormalKind = 0;
m_dwAbnormalTime = 0;
// 傍己傈俊辑 NPC HP啊 荐府啊 救登绢 乐栏搁
// if(m_pGuardFortress) SetFortressState();
if(m_bFirstLive) // NPC 啊 贸澜 混酒唱绰 版快
{
NpcTypeParser();
m_tWeaponClass = GetWeaponClass();
m_bFirstLive = FALSE;
InterlockedIncrement(&g_CurrentNPC);
}
// 各阑 付瘤阜栏肺 磷牢 蜡历狼 uid 檬扁拳
m_lKillUid = -1;
// Test Code
// CString strTemp = m_strName;
// if(strTemp == "凝" || strTemp == "弊饭捞飘候遣")m_sHP = 1;
// 蜡历俊霸 NPC 沥焊傈价...
modify_index = 0;
::ZeroMemory(modify_send, sizeof(modify_send));
FillNpcInfo(modify_send, modify_index, INFO_MODIFY);
SendInsight(pCom, modify_send, modify_index);
m_presx = -1;
m_presy = -1;
SightRecalc(pCom);
return TRUE;
}
///////////////////////////////////////////////////////////////////
// NPC 扁夯利牢 己氢阑 盒幅, 悸泼茄促.
//
void CNpc::NpcTypeParser()
{
MYSHORT sAI;
BYTE upTemp = 0; // 惑困 8厚飘
BYTE dwTemp = 0; // 窍困 8厚飘
sAI.i = (short)m_sAI;
upTemp = sAI.b[0];
dwTemp = sAI.b[1];
// temp = m_sAI;//m_byAI
m_tNpcAttType = upTemp >> 7;
upTemp = upTemp << 1;
m_tNpcLongType = upTemp >> 7;
upTemp = upTemp << 1;
m_tNpcGroupType = upTemp >> 7;
m_iNormalATRatio = m_byIronSkin;
m_iSpecialATRatio = m_byReAttack;
m_iMagicATRatio = m_bySubAttack;
m_tSPATRange = m_byWildShot;
/*
switch( (int)m_byVitalC )
{
case 0: // 老馆父
m_bCanNormalAT = TRUE;
m_bCanMagicAT = FALSE;
m_bCanSPAT = FALSE;
break;
case 1: // 概流父
m_bCanNormalAT = FALSE;
m_bCanMagicAT = TRUE;
m_bCanSPAT = FALSE;
break;
case 2: // 老馆, 漂荐
m_bCanNormalAT = TRUE;
m_bCanMagicAT = FALSE;
m_bCanSPAT = TRUE;
m_tSPATRange = m_byWildShot;
m_tSPATAI = m_byExcitedRate;
break;
case 3: // 概流, 漂荐
m_bCanNormalAT = FALSE;
m_bCanMagicAT = TRUE;
m_bCanSPAT = TRUE;
m_tSPATRange = m_byWildShot;
m_tSPATAI = m_byExcitedRate;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -