#include "StdAfx.h" #include "NetworkActorManager.h" #include "PythonCharacterManager.h" #include "PythonItem.h" #include "AbstractPlayer.h" void SNetworkActorData::UpdatePosition() { DWORD dwClientCurTime=ELTimer_GetMSec(); DWORD dwElapsedTime=dwClientCurTime-m_dwClientSrcTime; if (dwElapsedTime::iterator i; for (i=m_kNetActorDict.begin(); i!=m_kNetActorDict.end(); ++i) { SNetworkActorData& rkNetActorData=i->second; rkNetActorData.UpdatePosition(); CInstanceBase * pkInstFind = rkChrMgr.GetInstancePtr(rkNetActorData.m_dwVID); if (!pkInstFind) { if (__IsVisibleActor(rkNetActorData)) __AppendCharacterManagerActor(rkNetActorData); } } } CInstanceBase* CNetworkActorManager::__FindActor(SNetworkActorData& rkNetActorData, LONG lDstX, LONG lDstY) { CPythonCharacterManager& rkChrMgr=__GetCharacterManager(); CInstanceBase * pkInstFind = rkChrMgr.GetInstancePtr(rkNetActorData.m_dwVID); if (!pkInstFind) { if (__IsVisiblePos(lDstX, lDstY)) return __AppendCharacterManagerActor(rkNetActorData); return NULL; } return pkInstFind; } CInstanceBase* CNetworkActorManager::__FindActor(SNetworkActorData& rkNetActorData) { CPythonCharacterManager& rkChrMgr=__GetCharacterManager(); CInstanceBase * pkInstFind = rkChrMgr.GetInstancePtr(rkNetActorData.m_dwVID); if (!pkInstFind) { if (__IsVisibleActor(rkNetActorData)) return __AppendCharacterManagerActor(rkNetActorData); return NULL; } return pkInstFind; } void CNetworkActorManager::__RemoveAllGroundItems() { CPythonItem& rkItemMgr=CPythonItem::Instance(); rkItemMgr.DeleteAllItems(); } void CNetworkActorManager::__RemoveAllActors() { m_kNetActorDict.clear(); CPythonCharacterManager & rkChrMgr = CPythonCharacterManager::Instance(); rkChrMgr.DeleteAllInstances(); } void CNetworkActorManager::__RemoveDynamicActors() { //copy it std::vector dwCharacterVIDList; CPythonCharacterManager& rkChrMgr=CPythonCharacterManager::Instance(); for(CPythonCharacterManager::CharacterIterator i = rkChrMgr.CharacterInstanceBegin(); i!=rkChrMgr.CharacterInstanceEnd(); ++i) { dwCharacterVIDList.push_back( (*i)->GetVirtualID() ); } for( int i = 0; i < dwCharacterVIDList.size(); ++i ) { CInstanceBase* pkInstEach = rkChrMgr.GetInstancePtr( dwCharacterVIDList[i] ); if( !pkInstEach ) continue; CActorInstance* rkActorEach=pkInstEach->GetGraphicThingInstancePtr(); if( rkActorEach->IsPC() || rkActorEach->IsNPC() || rkActorEach->IsEnemy() ) { rkChrMgr.DeleteInstance(dwCharacterVIDList[i]); std::map::iterator it =m_kNetActorDict.find(dwCharacterVIDList[i]); if (it != m_kNetActorDict.end()) { m_kNetActorDict.erase(it); } } } rkChrMgr.DestroyDeadInstanceList(); } void CNetworkActorManager::__UpdateMainActor() { CPythonCharacterManager & rkChrMgr = CPythonCharacterManager::Instance(); CInstanceBase* pkInstMain=rkChrMgr.GetMainInstancePtr(); if (!pkInstMain) return; TPixelPosition kPPosMain; pkInstMain->NEW_GetPixelPosition(&kPPosMain); m_lMainPosX=LONG(kPPosMain.x); m_lMainPosY=LONG(kPPosMain.y); } extern bool IsWall(unsigned race); bool CNetworkActorManager::__IsVisibleActor(const SNetworkActorData& c_rkNetActorData) { if (__IsMainActorVID(c_rkNetActorData.m_dwVID)) return true; // 2004.08.02.myevan.Ç×»ó º¸À̱â Ç÷¡±× if (c_rkNetActorData.m_kAffectFlags.IsSet(CInstanceBase::AFFECT_SHOW_ALWAYS)) return true; if (__IsVisiblePos(c_rkNetActorData.m_lCurX, c_rkNetActorData.m_lCurY)) return true; if (IsWall(c_rkNetActorData.m_dwRace)) return true; return false; } bool CNetworkActorManager::__IsVisiblePos(LONG lPosX, LONG lPosY) { LONG dx = lPosX-m_lMainPosX; LONG dy = lPosY-m_lMainPosY; LONG len = (LONG)sqrt(double(dx * dx + dy * dy)); extern int CHAR_STAGE_VIEW_BOUND; if (len < CHAR_STAGE_VIEW_BOUND) // °Å¸®Á¦ÇÑ cm return true; return false; } bool CNetworkActorManager::__IsMainActorVID(DWORD dwVID) { if (dwVID == m_dwMainVID) return true; return false; } CPythonCharacterManager& CNetworkActorManager::__GetCharacterManager() { return CPythonCharacterManager::Instance(); } void CNetworkActorManager::__RemoveCharacterManagerActor(SNetworkActorData& rkNetActorData) { CPythonCharacterManager & rkChrMgr = CPythonCharacterManager::Instance(); if (__IsMainActorVID(rkNetActorData.m_dwVID)) { rkChrMgr.DeleteInstance(rkNetActorData.m_dwVID); } else { rkChrMgr.DeleteInstanceByFade(rkNetActorData.m_dwVID); } } CInstanceBase* CNetworkActorManager::__AppendCharacterManagerActor(SNetworkActorData& rkNetActorData) { Lognf(0, "CNetworkActorManager::__AppendCharacterManagerActor(%d, %s)", rkNetActorData.m_dwVID, rkNetActorData.m_stName.c_str()); DWORD dwVID=rkNetActorData.m_dwVID; CPythonCharacterManager & rkChrMgr = CPythonCharacterManager::Instance(); CInstanceBase::SCreateData kCreateData; kCreateData.m_bType=rkNetActorData.m_bType; kCreateData.m_dwLevel=rkNetActorData.m_dwLevel; kCreateData.m_dwGuildID=rkNetActorData.m_dwGuildID; kCreateData.m_dwEmpireID=rkNetActorData.m_dwEmpireID; kCreateData.m_dwVID=rkNetActorData.m_dwVID; kCreateData.m_dwMountVnum=rkNetActorData.m_dwMountVnum; kCreateData.m_dwRace=rkNetActorData.m_dwRace; kCreateData.m_fRot=rkNetActorData.m_fRot; kCreateData.m_lPosX=rkNetActorData.m_lCurX; kCreateData.m_lPosY=rkNetActorData.m_lCurY; kCreateData.m_stName=rkNetActorData.m_stName; kCreateData.m_dwStateFlags=rkNetActorData.m_dwStateFlags; kCreateData.m_dwMovSpd=rkNetActorData.m_dwMovSpd; kCreateData.m_dwAtkSpd=rkNetActorData.m_dwAtkSpd; kCreateData.m_sAlignment=rkNetActorData.m_sAlignment; kCreateData.m_byPKMode=rkNetActorData.m_byPKMode; kCreateData.m_kAffectFlags=rkNetActorData.m_kAffectFlags; kCreateData.m_dwArmor=rkNetActorData.m_dwArmor; kCreateData.m_dwWeapon=rkNetActorData.m_dwWeapon; kCreateData.m_dwHair=rkNetActorData.m_dwHair; kCreateData.m_isMain=__IsMainActorVID(dwVID); CInstanceBase* pOldInstance = rkChrMgr.GetInstancePtr(dwVID); if (pOldInstance) { TPixelPosition oldPos; pOldInstance->GetGraphicThingInstancePtr()->GetPixelPosition( &oldPos ); bool bIsMountingHorse = pOldInstance->IsMountingHorse(); if( (bIsMountingHorse && kCreateData.m_dwMountVnum == 0) || (!bIsMountingHorse && kCreateData.m_dwMountVnum != 0) ) { //Override Pos kCreateData.m_lPosX = oldPos.x; kCreateData.m_lPosY = -oldPos.y; } rkChrMgr.DeleteInstance(dwVID); } CInstanceBase* pNewInstance = rkChrMgr.CreateInstance(kCreateData); if (!pNewInstance) return NULL; if (kCreateData.m_isMain) { IAbstractPlayer & rkPlayer = IAbstractPlayer::GetSingleton(); rkPlayer.SetMainCharacterIndex(dwVID); m_lMainPosX=rkNetActorData.m_lCurX; m_lMainPosY=rkNetActorData.m_lCurY; } DWORD dwClientCurTime=ELTimer_GetMSec(); DWORD dwElapsedTime=dwClientCurTime-rkNetActorData.m_dwClientSrcTime; if (dwElapsedTimePushTCPState(rkNetActorData.m_dwServerSrcTime+dwElapsedTime, kPPosDst, rkNetActorData.m_fRot, CInstanceBase::FUNC_MOVE, 0); } return pNewInstance; } void CNetworkActorManager::AppendActor(const SNetworkActorData& c_rkNetActorData) { if (__IsMainActorVID(c_rkNetActorData.m_dwVID)) { bool bChangeMountStatus = false; CInstanceBase* pMainInstance = CPythonCharacterManager::Instance().GetInstancePtr(c_rkNetActorData.m_dwVID); if( pMainInstance ) { bool bIsMountingHorse = pMainInstance->IsMountingHorse(); bChangeMountStatus = (bIsMountingHorse && c_rkNetActorData.m_dwMountVnum == 0) || (!bIsMountingHorse && c_rkNetActorData.m_dwMountVnum != 0); } if( !bChangeMountStatus ) { //__RemoveAllActors(); __RemoveDynamicActors(); __RemoveAllGroundItems(); } } SNetworkActorData& rkNetActorData=m_kNetActorDict[c_rkNetActorData.m_dwVID]; rkNetActorData=c_rkNetActorData; if (__IsVisibleActor(rkNetActorData)) { if (!__AppendCharacterManagerActor(rkNetActorData)) m_kNetActorDict.erase(c_rkNetActorData.m_dwVID); } } void CNetworkActorManager::RemoveActor(DWORD dwVID) { std::map::iterator f=m_kNetActorDict.find(dwVID); if (m_kNetActorDict.end()==f) { #ifdef _DEBUG TraceError("CNetworkActorManager::RemoveActor(dwVID=%d) - NOT EXIST VID", dwVID); #endif return; } SNetworkActorData& rkNetActorData=f->second; __RemoveCharacterManagerActor(rkNetActorData); m_kNetActorDict.erase(f); } void CNetworkActorManager::UpdateActor(const SNetworkUpdateActorData& c_rkNetUpdateActorData) { std::map::iterator f=m_kNetActorDict.find(c_rkNetUpdateActorData.m_dwVID); if (m_kNetActorDict.end()==f) { #ifdef _DEBUG TraceError("CNetworkActorManager::UpdateActor(dwVID=%d) - NOT EXIST VID", c_rkNetUpdateActorData.m_dwVID); #endif return; } SNetworkActorData& rkNetActorData=f->second; CInstanceBase* pkInstFind=__FindActor(rkNetActorData); if (pkInstFind) { pkInstFind->ChangeArmor(c_rkNetUpdateActorData.m_dwArmor); pkInstFind->ChangeWeapon(c_rkNetUpdateActorData.m_dwWeapon); pkInstFind->ChangeHair(c_rkNetUpdateActorData.m_dwHair); pkInstFind->ChangeGuild(c_rkNetUpdateActorData.m_dwGuildID); pkInstFind->SetAffectFlagContainer(c_rkNetUpdateActorData.m_kAffectFlags); pkInstFind->SetMoveSpeed(c_rkNetUpdateActorData.m_dwMovSpd); pkInstFind->SetAttackSpeed(c_rkNetUpdateActorData.m_dwAtkSpd); pkInstFind->SetAlignment(c_rkNetUpdateActorData.m_sAlignment); pkInstFind->SetPKMode(c_rkNetUpdateActorData.m_byPKMode); pkInstFind->SetStateFlags(c_rkNetUpdateActorData.m_dwStateFlags); //if( c_rkNetUpdateActorData.m_dwMountVnum != 0 ) //{ // pkInstFind->MountHorse(c_rkNetUpdateActorData.m_dwMountVnum); //} //else //{ // if( pkInstFind->IsMountingHorse() ) // { // pkInstFind->DismountHorse(); // } //} } rkNetActorData.m_kAffectFlags=c_rkNetUpdateActorData.m_kAffectFlags; rkNetActorData.m_dwGuildID=c_rkNetUpdateActorData.m_dwGuildID; //rkNetActorData.m_dwLevel=c_rkNetUpdateActorData.m_dwLevel; rkNetActorData.m_dwMovSpd=c_rkNetUpdateActorData.m_dwMovSpd; rkNetActorData.m_dwAtkSpd=c_rkNetUpdateActorData.m_dwAtkSpd; rkNetActorData.m_dwArmor=c_rkNetUpdateActorData.m_dwArmor; rkNetActorData.m_dwWeapon=c_rkNetUpdateActorData.m_dwWeapon; rkNetActorData.m_dwHair=c_rkNetUpdateActorData.m_dwHair; rkNetActorData.m_sAlignment=c_rkNetUpdateActorData.m_sAlignment; rkNetActorData.m_byPKMode=c_rkNetUpdateActorData.m_byPKMode; } void CNetworkActorManager::MoveActor(const SNetworkMoveActorData& c_rkNetMoveActorData) { std::map::iterator f=m_kNetActorDict.find(c_rkNetMoveActorData.m_dwVID); if (m_kNetActorDict.end()==f) { #ifdef _DEBUG TraceError("CNetworkActorManager::MoveActor(dwVID=%d) - NOT EXIST VID", c_rkNetMoveActorData.m_dwVID); #endif return; } SNetworkActorData& rkNetActorData=f->second; CInstanceBase* pkInstFind=__FindActor(rkNetActorData, c_rkNetMoveActorData.m_lPosX, c_rkNetMoveActorData.m_lPosY); if (pkInstFind) { TPixelPosition kPPosDst; kPPosDst.x=float(c_rkNetMoveActorData.m_lPosX); kPPosDst.y=float(c_rkNetMoveActorData.m_lPosY); kPPosDst.z=0.0f; pkInstFind->PushTCPState(c_rkNetMoveActorData.m_dwTime, kPPosDst, c_rkNetMoveActorData.m_fRot, c_rkNetMoveActorData.m_dwFunc, c_rkNetMoveActorData.m_dwArg); } rkNetActorData.SetDstPosition(c_rkNetMoveActorData.m_dwTime, c_rkNetMoveActorData.m_lPosX, c_rkNetMoveActorData.m_lPosY, c_rkNetMoveActorData.m_dwDuration); rkNetActorData.m_fRot=c_rkNetMoveActorData.m_fRot; } void CNetworkActorManager::SyncActor(DWORD dwVID, LONG lPosX, LONG lPosY) { std::map::iterator f=m_kNetActorDict.find(dwVID); if (m_kNetActorDict.end()==f) { #ifdef _DEBUG TraceError("CNetworkActorManager::SyncActor(dwVID=%d) - NOT EXIST VID", dwVID); #endif return; } SNetworkActorData& rkNetActorData=f->second; CInstanceBase* pkInstFind=__FindActor(rkNetActorData); if (pkInstFind) { pkInstFind->NEW_SyncPixelPosition(lPosX, lPosY); } rkNetActorData.SetPosition(lPosX, lPosY); } void CNetworkActorManager::SetActorOwner(DWORD dwOwnerVID, DWORD dwVictimVID) { std::map::iterator f=m_kNetActorDict.find(dwVictimVID); if (m_kNetActorDict.end()==f) { #ifdef _DEBUG TraceError("CNetworkActorManager::SetActorOwner(dwOwnerVID=%d, dwVictimVID=%d) - NOT EXIST VID", dwOwnerVID, dwVictimVID); #endif return; } SNetworkActorData& rkNetActorData=f->second; rkNetActorData.m_dwOwnerVID=dwOwnerVID; CInstanceBase* pkInstFind=__FindActor(rkNetActorData); if (pkInstFind) { pkInstFind->NEW_SetOwner(rkNetActorData.m_dwOwnerVID); } }