📄 npc.cpp
字号:
}
for(int i = 0; i < 2; i++)
{
if(abs(ptPath[i].x - pt.x) <= m_byRange && abs(ptPath[i].y - pt.y) <= m_byRange) return FALSE;
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////////
// Target 狼 泅犁 困摹甫 掘绰促.
//
BOOL CNpc::GetTargetPos(COM *pCom, CPoint &pt)
{
USER* pUser = GetUser(pCom, m_Target.id - USER_BAND);
if(!pUser) return FALSE;
pt.x = pUser->m_curx;
pt.y = pUser->m_cury;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////////
// Target 苞 NPC 埃俊 辨茫扁甫 促矫茄促.
//
BOOL CNpc::ResetPath(COM* pCom)
{
CPoint pt;
GetTargetPos(pCom, pt);
m_Target.x = pt.x;
m_Target.y = pt.y;
return GetTargetPath(pCom);
}
/////////////////////////////////////////////////////////////////////////////////
// Step 荐 父怒 鸥南阑 氢秦 捞悼茄促.
//
BOOL CNpc::StepMove(COM* pCom, int nStep)
{
// if(m_tNpcType == NPCTYPE_GUILD_DOOR) return FALSE; // 捞悼救窍霸...
if(!m_pPath && !m_bRandMove) return FALSE;
if(m_NpcState != NPC_MOVING && m_NpcState != NPC_TRACING && m_NpcState != NPC_BACK) return FALSE;
int min_x;
int min_y;
int will_x;
int will_y;
CPoint ptPre;
MAP* pMap = g_zone[m_ZoneIndex];
if( !pMap ) return FALSE;
if( !pMap->m_pMap ) return FALSE;
for(int i = 0; i < nStep; i++)
{
if( m_bRandMove )
{
if( !m_arRandMove.GetSize() ) return FALSE;
min_x = m_min_x;
min_y = m_min_y;
will_x = min_x + m_arRandMove[0].x;
will_y = min_y + m_arRandMove[0].y;
m_arRandMove.RemoveAt( 0 );
if( will_x >= pMap->m_sizeMap.cx || will_x < 0 || will_y >= pMap->m_sizeMap.cy || will_y < 0 )
{
m_vEndPoint.x = m_sCurX - min_x;
m_vEndPoint.y = m_sCurY - min_y;
return FALSE;
}
if( pMap->m_pMap[will_x][will_y].m_bMove != 0 || pMap->m_pMap[will_x][will_y].m_lUser != 0 )
{
m_vEndPoint.x = m_sCurX - min_x;
m_vEndPoint.y = m_sCurY - min_y;
return FALSE;
}
ptPre.x = m_sCurX;
ptPre.y = m_sCurY;
m_sCurX = will_x;
m_sCurY = will_y;
// 矫具 犁拌魂...
SightRecalc( pCom );
break;
}
else if(m_pPath->Parent)
{
m_pPath = m_pPath->Parent;
min_x = m_min_x;
min_y = m_min_y;
will_x = min_x + m_pPath->x;
will_y = min_y + m_pPath->y;
if(will_x >= pMap->m_sizeMap.cx || will_x < 0 || will_y >= pMap->m_sizeMap.cy || will_y < 0)
{
m_vEndPoint.x = m_sCurX - min_x;
m_vEndPoint.y = m_sCurY - min_y;
return FALSE;
}
if(pMap->m_pMap[will_x][will_y].m_bMove != 0 || pMap->m_pMap[will_x][will_y].m_lUser != 0)
{
m_vEndPoint.x = m_sCurX - min_x;
m_vEndPoint.y = m_sCurY - min_y;
return FALSE;
}
ptPre.x = m_sCurX;
ptPre.y = m_sCurY;
m_sCurX = will_x;
m_sCurY = will_y;
//矫具 犁拌魂...
SightRecalc(pCom);
break;
}
return FALSE;
}
if(SetUid(m_sCurX, m_sCurY, m_sNid + NPC_BAND))
{
pMap->m_pMap[ptPre.x][ptPre.y].m_lUser = 0;
return TRUE;
}
else return FALSE;
// return SetUid(m_sCurX, m_sCurY, m_sNid + NPC_BAND);
}
//////////////////////////////////////////////////////////////////////////////
// Target 俊 措茄 傍拜 贸府
//
int CNpc::Attack(COM *pCom)
{
if(!pCom) return 10000;
int ret = 0;
int nStandingTime = m_sStandTime;
// 醚扁拌凯 老锭绰 鸥百苞狼 芭府拌魂阑 崔府秦具 茄促.
// if(m_tNpcType != NPCTYPE_GUARD && m_tNpcType != NPCTYPE_GUILD_GUARD)// 版厚捍捞 酒聪搁 矫具 拌魂
// {
if(IsCloseTarget(pCom, m_byRange) == FALSE)// Check Code (窜瘤 规绢利牢 螟搁俊辑 持篮 内靛)
{
if(m_tNpcType == NPCTYPE_GUARD || m_tNpcType == NPCTYPE_GUILD_GUARD)
{
m_NpcState = NPC_STANDING;
return 0;
}
m_NpcState = NPC_TRACING; // 傍拜窍绊 档噶啊绰 蜡历甫 蝶扼 棱扁困秦(馆览阑 粱歹 狐福霸)
return 0; // IsCloseTarget()俊 蜡历 x, y蔼阑 盎脚窍绊 Delay = 0栏肺 淋
}
// }
short sTempHP = 0;
CNpc* pNpc = NULL;
USER* pUser = NULL;
CByteArray arSkillAction1, arSkillAction2;
int nHit = 0;
int nAvoid = 0;
BOOL bIsHit = FALSE;
BOOL bIsCritical = FALSE;
int nDamage = 0;
int nDefense = 0;
int iRandom = 0;
// int iDefenseDex = 0;
// double determine = 0;
int determine = 0;
int iDexHitRate = 0, iLevelHitRate = 0;
int nID = m_Target.id; // Target 阑 备茄促.
// 疙吝咯何 魄窜 函荐 檬扁拳
bIsHit = FALSE;
// 雀乔蔼/疙吝魄沥/单固瘤 拌魂 -----------------------------------------//
if(nID >= USER_BAND && nID < NPC_BAND) // Target 捞 User 牢 版快
{
pUser = GetUser(pCom, nID - USER_BAND);
if(pUser == NULL || pUser->m_state != STATE_GAMESTARTED)// User 啊 Invalid 茄 版快
{
InitTarget();
m_NpcState = NPC_STANDING;
return nStandingTime;
}
if(pUser->m_bLive == USER_DEAD) // User 啊 捞固 磷篮版快
{
InitTarget();
m_NpcState = NPC_STANDING;
return nStandingTime;
}
if(pUser->m_dwNoDamageTime != 0) // User 啊 公利鸥烙俊 乐阑版快
{
InitTarget();
m_NpcState = NPC_STANDING;
return nStandingTime;
}
if(pUser->m_bPShopOpen == TRUE) // User has personal shop
{
InitTarget();
m_NpcState = NPC_STANDING;
return nStandingTime;
}
/* 困俊辑 捞固 眉农 窃
if(pUser->m_state == STATE_DISCONNECTED)
{
InitTarget();
m_NpcState = NPC_STANDING;
return nStandingTime;
}
*/
if(m_tNpcType == NPCTYPE_GUILD_GUARD)
{
if(m_tGuildWar == GUILD_WARRING && pUser->m_dwGuild > 0)
{
if(m_pGuardStore)
{
if(pUser->m_dwGuild == m_pGuardStore->m_iGuildSid) return nStandingTime;
}
else if(m_pGuardFortress)
{
if(pUser->m_dwGuild == m_pGuardFortress->m_iGuildSid) return nStandingTime;
}
}
}
// 篮葱 惑怕捞搁 版厚捍阑 力寇茄 葛电 各俊 秦寸
// if(m_tNpcType != NPCTYPE_GUARD && pUser->m_dwHideTime > 0)
// {
// InitTarget();
// m_NpcState = NPC_MOVING;
// return nStandingTime;
// }
if(pUser->m_tIsOP == 1)
{
InitTarget();
m_NpcState = NPC_MOVING;
return nStandingTime;
}
// 雀乔蔼 拌魂
nAvoid = pUser->GetAvoid();
// 疙吝咯何 魄窜
iRandom = (int)((double)XdY(1, 1000) / 10 + 0.5);
iDexHitRate = (int)( 30.0 * ( (double)m_sDEX/(m_sDEX + pUser->m_sMagicDEX) ) + 15.0 );
iLevelHitRate = (int)( 70.0 * ( (double)m_byClassLevel/(pUser->m_sLevel + m_byClassLevel) ) + 15.0);
determine = iDexHitRate + iLevelHitRate - nAvoid;
/*
iDefenseDex = pUser->m_sMagicDEX;
if(iDefenseDex < 0) iDefenseDex = 0; //规绢 内靛
determine = 200 * ((double)m_sDEX / (m_sDEX + iDefenseDex)) * ((double)m_byClassLevel / (m_byClassLevel + pUser->m_sLevel));
determine = determine - nAvoid;
*/
if(determine < ATTACK_MIN) determine = ATTACK_MIN; // 弥家 20
else if(determine > ATTACK_MAX) determine = ATTACK_MAX; // 弥措
if(iRandom < determine) bIsHit = TRUE; // 疙吝
// 傍拜 固胶
if(bIsHit == FALSE)
{
SendAttackMiss(pCom, nID);
return m_sAttackDelay;;
}
// 疙吝捞搁 //Damage 贸府 ----------------------------------------------------------------//
nDamage = GetFinalDamage(pUser); // 弥辆 措固瘤
if(nDamage < 0) nDamage = 0;
if(pUser->m_tAbnormalKind == ABNORMAL_BYTE_COLD) nDamage += 10; // 惑措祈捞 趁扁 捞惑捞搁 单固瘤 眠啊
if(nDamage > 0) pUser->SetDamage(nDamage);
// 规绢螟 郴备档 皑家
pUser->SendDamagedItem(nDamage);
// if(pUser->m_bLive == USER_DEAD || pUser->m_sHP <= 0)//@@@ 唱吝俊 绊魔
if(pUser->m_lDeadUsed == 1)
{
InitTarget();
m_NpcState = NPC_STANDING;
m_Delay = m_sStandTime;
if(m_NpcVirtualState == NPC_STANDING)
{
if(m_sPid == 179) pUser->GetLevelDownExp(FALSE, -1, TRUE,m_strName);//傍侩 阁胶磐老版快 版氰摹 1%皑家
else pUser->GetLevelDownExp(FALSE, -1, FALSE,m_strName);// 版氰摹客 弊寇 函拳樊甫 馆康茄促.
}
if(m_tNpcType == NPCTYPE_GUARD) pUser->SendCityRank(1); // 版厚捍俊霸 磷栏搁 PK 墨款飘 1 皑家
// 泅犁 版厚捍篮 畴富 傍拜父 窍骨肺 捞镑俊父 眠啊
// Add by JJS 2002.05.24
}
//yskang 0.3 SendAttackSuccess(pCom, nID, arSkillAction1, arSkillAction2, pUser->m_sHP, pUser->m_sMagicMaxHP);
SendAttackSuccess(pCom, nID, bIsCritical, pUser->m_sHP, pUser->m_sMagicMaxHP);//yskang 0.3
}
return m_sAttackDelay;
}
CNpc* CNpc::GetNpc(int nid)
{
CNpc* pNpc = NULL;
int nSize = g_arNpc.GetSize();
if(nid < 0 || nid >= nSize) return NULL;
for( int i = 0; i < g_arNpc.GetSize(); i++)
{
pNpc = g_arNpc[i];
if( !pNpc ) continue;
if( pNpc->m_sNid == nid )
{
return pNpc;
}
}
return NULL;
}
////////////////////////////////////////////////////////////////////////////
// NPC 狼 傍拜仿阑 掘绢柯促.
//
int CNpc::GetAttack()
{
int X = m_byAX;
int Y = m_byAZ;
return XdY(X, Y);
}
////////////////////////////////////////////////////////////////////////////
// NPC 狼 规绢仿阑 掘绢柯促.
//
int CNpc::GetDefense()
{
return m_iDefense;
}
/////////////////////////////////////////////////////////////////////////////
// Damage 拌魂, 父距 m_sHP 啊 0 捞窍捞搁 荤噶贸府
//
BOOL CNpc::SetDamage(int nDamage)
{
if(m_NpcState == NPC_DEAD) return TRUE;
if(m_sHP <= 0) return TRUE;
if(nDamage <= 0) return TRUE;
m_sHP -= nDamage;
if( m_sHP <= 0 )
{
m_sHP = 0;
return FALSE;
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
// NPC 荤噶贸府
//
void CNpc::Dead()
{
long lNpcUid = m_sNid + NPC_BAND;
if(m_pOrgMap[m_sCurX][m_sCurY].m_lUser == lNpcUid)
{
::InterlockedExchange(&m_pOrgMap[m_sCurX][m_sCurY].m_lUser, (LONG)0);
}
m_sHP = 0;
m_NpcState = NPC_DEAD;
if(m_bSummon)
{
m_bSummonDead = TRUE;
m_bSummon = FALSE;
}
if(m_NpcVirtualState == NPC_MOVING) m_NpcVirtualState = NPC_WAIT;
m_Delay = m_sRegenTime;
m_bFirstLive = FALSE;
}
//////////////////////////////////////////////////////////////////////////////
// NPC 荤噶贸府矫 版氰摹 盒硅甫 拌魂茄促.(老馆 蜡历客 滚叼 荤侩磊备盒)
//
void CNpc::SendExpToUserList(COM *pCom)
{
int i;
int exp = 0;//, eventExp = 0;
int totalDamage = 0;
int firstDamage = 0;
DWORD plusExp = 0;
if(m_NpcVirtualState == NPC_WAIT) return; // 啊惑傍埃俊辑 版氰摹 绝促.
if(m_tNpcType >= NPCTYPE_GUILD_NPC) return;
// if(m_tNpcType == NPCTYPE_GUILD_NPC || m_tNpcType == NPCTYPE_GUILD_DOOR) return;
// if(m_tNpcType == NPCTYPE_GUILD_GUARD) return; // 辨靛傈俊辑 磷篮 版厚捍篮 版氰摹甫 救霖促.
// SYSTEMTIME gTime;
// GetLocalTime(&gTime);
USER *pUser = NULL;
IsUserInSight(pCom); // 泅犁 伎裹困救俊 乐蠢衬?(各阑 扁霖栏肺 茄 拳搁 : 敲贰弊 悸泼)
if(m_DamagedUserList[0].iUid >= 0 && m_DamagedUserList[0].nDamage > 0) // 霉锅掳俊 蜡历啊 乐促搁 2硅
{
firstDamage = m_DamagedUserList[0].nDamage;
m_DamagedUserList[0].nDamage = m_DamagedUserList[0].nDamage * 2;
}
for(i = 0; i < NPC_HAVE_USER_LIST; i++) // 老窜 府胶飘甫 八祸茄促.
{
if(m_DamagedUserList[i].iUid < 0 || m_DamagedUserList[i].nDamage<= 0) continue; // 救傈内靛
if(m_DamagedUserList[i].bIs == TRUE) pUser = GetUser(pCom, m_DamagedUserList[i].iUid);
if(pUser == NULL || pUser->m_state != STATE_GAMESTARTED) continue;
totalDamage = m_DamagedUserList[i].nDamage;
if ( (m_sExp / 5) <= 0 ) continue;
if ( totalDamage == 0 ) continue;
if(((m_TotalDamage + firstDamage) /5) <= 0) continue;
exp =((m_sExp / 5) * totalDamage)/((m_TotalDamage + firstDamage) / 5);
pUser->m_iCityValue += m_sInclination;
if(pUser->m_iCityValue > 2000000000) pUser->m_iCityValue = 2000000000; // 弥措蔼捞 绝绢辑 烙狼肺 沥沁促.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -