📄 battlerecord.cpp
字号:
#include "stdafx.h"
#include "BattleRecord.h"
#include "Field.h"
#include "NPC.h"
#include "AIParamParser.h"
//--------------------------------------------------------------------------------------------------------------
//
// BATTLE_RECORD
//
//--------------------------------------------------------------------------------------------------------------
BATTLE_RECORD::BATTLE_RECORD()
{
Init();
}
BATTLE_RECORD::~BATTLE_RECORD()
{
}
VOID
BATTLE_RECORD::Init()
{
m_ObjectKey = 0;
m_wLevel = 0;
m_AttackPoint = 0;
m_dwTotalPoint = 0;
m_CreateTick = GetTickCount();
m_bFirstAttacker = FALSE;
}
VOID
BATTLE_RECORD::Update()
{
AIParamInfo& stAIParamInfo = AIParamParser::Instance()->GetInfo();
// 啊父洒 乐栏搁 痢荐啊 临绢靛绰 瓤苞
if( m_AttackPoint <= stAIParamInfo.m_wMIN_DAMAGE_POINT )
{
m_AttackPoint = 0;
}
else
{
m_AttackPoint -= (int)((float)m_AttackPoint * (float)stAIParamInfo.m_byDAMAGE_POINT_REDUCE_RATIO / 100.0f);
}
// TotalPoint档 林扁利栏肺 皑家 矫挪促
DecTotalPoint((DWORD)((float)m_dwTotalPoint*0.1f));
}
//--------------------------------------------------------------------------------------------------------------
//
// BattleRecord
//
//--------------------------------------------------------------------------------------------------------------
BattleRecord::BattleRecord()
: m_LastUpdateTick(0)
{
}
BattleRecord::~BattleRecord()
{
}
VOID
BattleRecord::Init()
{
m_Records.clear();
m_LastUpdateTick = 0;
m_dwTotalLevel = 0;
}
BOOL
BattleRecord::IsExist( DWORD objectKey ) const
{
BATTLE_RECORDS::const_iterator iRecord = m_Records.find( objectKey );
if ( iRecord != m_Records.end() )
{
return TRUE;
}
return FALSE;
}
BATTLE_RECORD*
BattleRecord::Get( DWORD objectKey )
{
BATTLE_RECORDS::iterator iRecord = m_Records.find( objectKey );
if ( iRecord != m_Records.end() )
{
return &iRecord->second;
}
return NULL;
}
const BATTLE_RECORD*
BattleRecord::Get( DWORD objectKey ) const
{
BATTLE_RECORDS::const_iterator iRecord = m_Records.find( objectKey );
if ( iRecord != m_Records.end() )
{
return &iRecord->second;
}
return NULL;
}
BATTLE_RECORD*
BattleRecord::Add( Character *pAttacker, BOOL bFirstAttacker )
{
DWORD dwObjectKey = pAttacker->GetObjectKey();
BATTLE_RECORD* pRecord = Get( dwObjectKey );
if( pRecord == NULL )
{
pRecord = &m_Records[dwObjectKey];
pRecord->SetObjectKey( dwObjectKey );
pRecord->SetLevel( pAttacker->GetLevel() );
m_dwTotalLevel += pAttacker->GetLevel();
}
if( bFirstAttacker )
{
pRecord->SetFirstAttackerFlag( TRUE );
}
return pRecord;
}
BOOL
BattleRecord::Remove( DWORD objectKey )
{
BATTLE_RECORDS::iterator iRecord = m_Records.find( objectKey );
if ( iRecord != m_Records.end() )
{
BATTLE_RECORD* pRecord = &iRecord->second;
if( m_dwTotalLevel >= pRecord->GetLevel() ) m_dwTotalLevel -= pRecord->GetLevel();
else m_dwTotalLevel = 0;
m_Records.erase( iRecord );
return TRUE;
}
return FALSE;
}
VOID
BattleRecord::Update( DWORD dwCurTick )
{
AIParamInfo& stAIParamInfo = AIParamParser::Instance()->GetInfo();
DWORD dwDiffTick = dwCurTick - m_LastUpdateTick;
if( dwDiffTick > stAIParamInfo.m_wBATTLE_RECORD_UPDATE_TIME )
{
// 老沥矫埃付促 AttackPoint俊 函拳甫 霖促.
BATTLE_RECORDS::iterator iRecord = m_Records.begin();
for (; iRecord != m_Records.end(); iRecord++ )
{
BATTLE_RECORD& record = iRecord->second;
record.Update();
}
m_LastUpdateTick = dwCurTick;
}
}
VOID BattleRecord::IncTotalPoint( DWORD objectKey, DWORD point )
{
BATTLE_RECORD *pRecord = Get( objectKey );
if( !pRecord ) return;
pRecord->IncTotalPoint( point );
}
//---------------------------------------------------------------------------------------------
// 阿辆 亲格俊 措茄 器牢撇甫 概变促.
//---------------------------------------------------------------------------------------------
VOID BattleRecord::CalcTotalPoint( NPC *pNPC )
{
Field *pField = pNPC->GetField();
if( !pField ) return;
BATTLE_RECORDS::iterator it;
Character *pCurChar;
DWORD dwTotalDamage = 0;
AIParamInfo& stAIParamInfo = AIParamParser::Instance()->GetInfo();
// 霖厚 累诀
for( it = m_Records.begin(); it != m_Records.end(); ++it )
{
pCurChar = pField->FindCharacter( it->first );
BATTLE_RECORD &record = it->second;
// 某腐磐啊 鞘靛惑俊 绝栏搁 饭内靛 昏力
if( !pCurChar )
{
if( m_dwTotalLevel >= record.GetLevel() ) m_dwTotalLevel -= record.GetLevel();
else m_dwTotalLevel = 0;
m_Records.erase( it-- );
continue;
}
// 恐 府悸阑 沁绰瘤? ぱ_ぱ;;
// 器牢飘 府悸
//record.ResetTotalPoint();
// 敲饭捞绢甸狼 醚 穿利 单固瘤甫 备秦敌促.
dwTotalDamage += record.GetAttackPoint();
}
if( m_Records.empty() ) return;
//---------------------------------------------------------------------------------------------
// 利 府胶飘甫 鉴雀窍搁辑 阿 亲格俊 秦寸窍绰 器牢飘甫 罐阑 某腐磐甫 茫绰促.
//---------------------------------------------------------------------------------------------
// 檬扁蔼 汲沥
LEVELTYPE lvLowestLevel = MAX_LEVEL;
float fLowestHPRate = 1.0f;
float fShortestDistance = 1000.0f;
DWORD dwHighestAttackPoint = 0;
it = m_Records.begin();
DWORD dwLowestLevelCharKey = it->first;
DWORD dwFirstAttackerKey = it->first;
DWORD dwLowestHPCharKey = it->first;
DWORD dwShortestDistanceCharKey = it->first;
DWORD dwHighestAttackPointCharKey = it->first;
for( ; it != m_Records.end(); ++it )
{
pCurChar = pField->FindCharacter( it->first );
if( !pCurChar ) continue;
BATTLE_RECORD &record = it->second;
// 歹 撤篮 饭骇阑 啊脸绰瘤 八荤
if( pCurChar->GetLevel() < lvLowestLevel )
{
dwLowestLevelCharKey = it->first;
lvLowestLevel = pCurChar->GetLevel();
}
// 弥檬 傍拜磊牢瘤 八荤
if( record.IsFirstAttacker() )
{
dwFirstAttackerKey = it->first;
}
// HP 厚啦捞 歹 撤篮瘤 八荤
if( (float)pCurChar->GetHP() / pCurChar->GetMaxHP() < fLowestHPRate )
{
dwLowestHPCharKey = it->first;
fLowestHPRate = (float)( pCurChar->GetHP() / pCurChar->GetMaxHP() );
}
// 捞 某腐苞狼 芭府啊 歹 啊鳖款瘤 八荤
float fDist = pNPC->GetDist( pCurChar );
if( fDist < fShortestDistance )
{
dwShortestDistanceCharKey = it->first;
fShortestDistance = fDist;
}
// 醚 穿利单固瘤吝 磊脚捞 冈牢 穿利单固瘤 厚啦父怒 器牢飘甫 霖促.
record.IncTotalPoint( (DWORD)( (float)record.GetAttackPoint() * stAIParamInfo.m_wDAMAGE_POINT / dwTotalDamage ) );
}
// 亲格喊 器牢飘 林扁
DWORD dwRecordSize = m_Records.size();
if( 0 == dwRecordSize )
{
// 0栏肺 唱穿搁 救凳!!
SUNLOG( eCRITICAL_LOG, "[BattleRecord::CalcTotalPoint] dwRecordSize = 0 ");
return;
}
IncTotalPoint( dwFirstAttackerKey, stAIParamInfo.m_wFIRST_ATTACK_POINT );
IncTotalPoint( dwShortestDistanceCharKey, stAIParamInfo.m_wNEAR_DISTANCE_POINT );
IncTotalPoint( dwLowestLevelCharKey, stAIParamInfo.m_wLOW_LEVEL_POINT );
IncTotalPoint( dwLowestHPCharKey, stAIParamInfo.m_wLOW_HP_POINT );
}
// 利 府胶飘俊辑 TotalPoint啊 啊厘 臭篮 逞阑 府畔茄促.
Character* BattleRecord::SelectBestTarget( NPC *pNPC )
{
// 饭内靛啊 窍唱档 绝栏搁 府畔
if( m_Records.empty() ) return NULL;
// 泅犁 鸥百虐
DWORD dwTargetKey = 0;
if( pNPC->GetTargetChar() )
{
dwTargetKey = pNPC->GetTargetChar()->GetObjectKey();
}
CalcTotalPoint( pNPC );
Field *pField = pNPC->GetField();
if( !pField ) return NULL;
// TotalPoint啊 啊厘 臭篮 某腐磐甫 急琶窍瘤 臼阑 犬伏 拌魂
int iRandomKey = -1;
if( random(0, 100) <= 10 )//捞 厚啦 蔼篮 瞒饶俊 AIParameter肺 哗郴具窃
{
int iRecodeSize = m_Records.size();
if( iRecodeSize > 0)
{
iRandomKey = rand()%iRecodeSize;
}
else
iRandomKey = -1;
}
DWORD dwHighestPoint = 0;
int iCnt = 0;
BATTLE_RECORDS::iterator it = m_Records.begin();
DWORD dwBestTargetKey = it->first;
for( ; it != m_Records.end(); ++it )
{
BATTLE_RECORD &record = it->second;
//罚待己 碍拳甫 困茄 抗寇贸府 风凭
if(iRandomKey >= 0 && iCnt == iRandomKey)
{
dwBestTargetKey = it->first;
record.SetTotalPoint(1200);//捞 蔼篮 瞒饶俊 AIParameter肺 哗郴具窃
break;
}
if( record.GetTotalPoint() > dwHighestPoint )
{
dwBestTargetKey = it->first;
dwHighestPoint = record.GetTotalPoint();
}
iCnt++;
}
// 叼滚彪侩 皋技瘤
/* if( dwTargetKey != dwBestTargetKey )
{
BATTLE_RECORD *pRecord = Get( dwTargetKey );
if( pRecord )
{
SUNLOG( eFULL_LOG, "[BattleRecord::SelectBestTarget] PreTarget[%d] TotalPoint[%d] ", dwTargetKey, pRecord->GetTotalPoint() );
}
SUNLOG( eFULL_LOG, "[BattleRecord::SelectBestTarget] NewTarget[%d] TotalPoint[%d] ", dwBestTargetKey, dwHighestPoint );
}*/
return pField->FindCharacter( dwBestTargetKey );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -