//------------------------------------------------------------------------------ // LottNPC.cpp // (C) 2009 Webzen Sunstudio //------------------------------------------------------------------------------ #include "SunClientPrecompiledHeader.h" #include "LottoNPC.h" #include "NPC.h" #include "uiLottoMan/uiLottoMan.h" #include "ResourceManager.h" #include "objectmanager.h" //------------------------------------------------------------------------------ /** */ LottoNPC::LottoNPC( void ) :m_bNumberAni(FALSE), m_bLottoActive(TRUE), m_iOldNumber(0) { SetObjectType(LOTTO_NPC_OBJECT); memset(&m_ResInfo,NULL,sizeof(m_ResInfo)); memset(&m_ppRenderPart,NULL,sizeof(m_ppRenderPart)); memset(&m_ppNumberUnit,NULL,sizeof(m_ppNumberUnit)); memset(&m_arBonPosition,-1,sizeof(m_arBonPosition)); memset(&m_arCurNumber,-1,sizeof(m_arCurNumber)); memset(&m_arOldNumber,-1,sizeof(m_arOldNumber)); } //------------------------------------------------------------------------------ /** */ LottoNPC::~LottoNPC( void ) { } //------------------------------------------------------------------------------ /** */ BOOL LottoNPC::Create( DWORD dwObjectKey, DWORD dwID) { BOOL bRet = NPC::Create(dwObjectKey,dwID); //step1:¼ýÀÚ¿ÀºêÁ§Æ® ¸®¼Ò½ºÄÚµå(¼ýÀÚÆÇ+¼ýÀÚÀ¯´Ö) m_ResInfo.m_rNumberCode = ENGINE_RESOURCE_ID_OFFSET + 5045; m_ResInfo.m_rBaseCode = ENGINE_RESOURCE_ID_OFFSET + 5044; //step2:À§¿¡ ¸®¼Ò½ºÄڵ带 ·Îµå LoadNumberObject(); //step3:¼ýÀ򮂦§±â¿¡ ±×·ÁÁÖ±âÀ§¿¡ ÆÇ¶§±âÀÇ ¼ýÀÚº»À§Ä¡ ÃßÃâ ExtractBoneIndex(); //step4:µðÆúÆ®·Î ¼ýÀÚÃʱâÈ­ RefreshNumber(); //step5:¼­¹ö¿¡¼­´Â °»½Å½Ã¿¡¸¸ ¼ýÀÚÁ¤º¸¸¦º¸³»±â¶§¹®¿¡ ¸ÊÀÔÀå npcÃʱâÈ­½Ã Ŭ¶ó¿¡¼­ Á¤º¸ ¿äÃ»ÇØÁØ´Ù. uiLottoMan* pLottoMan = GET_DIALOG_MANAGER(uiLottoMan, UIMAN_LOTTO_MAN); if(pLottoMan) { pLottoMan->SEND_LOTTO_INFO_SYN(false); } //step6:·Î¶Ç¸Å´ÏÀú¿¡ ·Î¶Ç¿ÀºêÁ§Æ®Å°¸¦µî·ÏÇÑ(·Î¶ÇÁ¤º¸°»½Å(¼ýÀÚ)´Â ¸Å´ÏÀú¸¦ÅëÇØ ÀÌ·ïÁø´Ù) uiLottoMan* pLoginMan = GET_DIALOG_MANAGER(uiLottoMan, UIMAN_LOTTO_MAN); if(pLoginMan) { pLoginMan->RegisterLottoKey(this->GetObjectKey()); } SetShadowDraw(TRUE); if(m_pBasePart) { m_pBasePart->EnableShadowCast(TRUE); m_pBasePart->EnableShadowReceive(TRUE); } InitMeshHeight(); return bRet; } //------------------------------------------------------------------------------ /** ¸®¼Ò½ºÇØÁ¦ */ void LottoNPC::Destroy( void ) { FreeNumberObject(); NPC::Destroy(); } //------------------------------------------------------------------------------ /** ¸®¼Ò½º·Îµå */ void LottoNPC::LoadNumberObject() { //step1:º£À̽º ÆÄÃ÷(¼ýÀ򮂦§±â) m_pBasePart = ResourceManager::Instance()->AllocResourceUnitDraw(m_ResInfo.m_rBaseCode); int i=0; //step2:wzu(À¯´ÖÆÄÀϷεå) for( i = 0 ; i < NUM_MAX_UNIT ; ++i ) { m_ppNumberUnit[i] = ResourceManager::Instance()->AllocResourceUnit(m_ResInfo.m_rNumberCode+i); assert(m_ppNumberUnit[i] && "¸®¼Ò½º°¡ ¾ø½À´Ï´Ù."); } //step3:À¯´ÖÀ» ±×·ÁÁÙ UnitDraw·Îµå for( i = 0;iFreeResourceUnitDraw(m_pBasePart); } //step2:wzu(À¯´ÖÆÄÀϷεå) int i=0; for( ; i < NUM_MAX_UNIT ; ++i ) { ResourceManager::Instance()->FreeResourceUnit(m_ResInfo.m_rNumberCode+i); m_ppNumberUnit[i]= NULL; } //step3:À¯´ÖÀ» ±×·ÁÁÙ UnitDraw·Îµå for( i = 0 ; i < MAX_BONE_POS ; ++i ) { if(m_ppRenderPart[i]) { g_pSunRenderer->DestroyResourceForWzUnitDraw(m_ppRenderPart[i]); Func_ContactWzd( CW_DELETE_WZUNITDRAW, m_ppRenderPart[i] ); m_ppRenderPart[i] =NULL; } } } //------------------------------------------------------------------------------ /** ·Î¶Ç Ȱ¼º.ºñȰ¼º */ void LottoNPC::SetLottoActive(BOOL bActive) { if(bActive==m_bLottoActive) { return; } m_bLottoActive = bActive; uiLottoMan* pLottoMan= GET_DIALOG_MANAGER(uiLottoMan, UIMAN_LOTTO_MAN); if(!pLottoMan) { return; } //ºñȰ¼º(Á¤»ê):Ãß֊ÆÃ¸Þ½ÃÁö¿ÍÇÔ²² ¼ýÀÚÆÇÀÌ ¼ýÀÚ°¡ °è¼Ó¹Ù²ï´Ù if(m_bLottoActive) { m_iOldNumber=-1; SetDrawNumber(pLottoMan->GetLottoInfo()->m_i64TotalAccum); } else { //5286 %dȸ ·Î¶Ç Ãß÷ÀÌ ½ÃÀ۵Ǿú½À´Ï´Ù. TCHAR szTemp[INTERFACE_STRING_LENGTH]; TCHAR szMessage[INTERFACE_STRING_LENGTH]; g_InterfaceManager.GetInterfaceString(5286, szTemp); Snprintf(szMessage, INTERFACE_STRING_LENGTH, szTemp,pLottoMan->GetLottoInfo()->m_wLottoDrawNum); AddChatMessage(szMessage); for(int a=0;aSetPosition(pExtraInfo->m_fNPCPos[0],pExtraInfo->m_fNPCPos[1],pExtraInfo->m_fNPCPos[2]); } } //------------------------------------------------------------------------------ /** ¾÷µ¥ÀÌÆ® */ BOOL LottoNPC::Process( DWORD dwTick ) { //±âº» ¼ýÀÚÆÇ±×¸®±â if(!m_pBasePart) { return FALSE; } g_pSunRenderer->ProgressUnitFrame( m_pBasePart,0.0f); g_pSunRenderer->AnimateUnit(m_pBasePart); //¼ýÀÚÆÇÀ§ÀÇ ¼ýÀÚµé for( int i = 0 ; i < MAX_BONE_POS ; ++i ) { if(!m_ppRenderPart[i]) { continue; } g_pSunRenderer->ProgressUnitFrame(m_ppRenderPart[i],0.0f); if(m_arBonPosition[i]==-1) { continue; } WzMatrix *pBoneMatrix = m_pBasePart->GetTransformBuffer(); //º»À§Ä¡ ¼ýÀÚ¸¦ ºÎÄ£´Ù if(pBoneMatrix) { g_pSunRenderer->AnimateUnit(m_ppRenderPart[i],0,&pBoneMatrix[m_arBonPosition[i]]); } } SetBillBoard(); BOOL bRet = Character::Process(dwTick); //ºñȰ¼º»óÅÂÀϰæ¿ì(Á¤»êÁß) if(!m_bLottoActive) { SetChatDisplayTime(1000); AnimationNumberChaos(dwTick); RefreshNumber(); } else { //¼ýÀھִϸÞÀÌ¼Ç if(m_bNumberAni) { AnimationNumber(dwTick); RefreshNumber(); } } return bRet; } //------------------------------------------------------------------------------ /** ·£´õ¸µ */ BOOL LottoNPC::Render() { //¼ýÀÚÆÇ if(!m_pBasePart) { return FALSE; } g_pSunRenderer->RenderUnit( m_pBasePart); //¼ýÀÚµé for( int i = 0 ; i < MAX_BONE_POS ; ++i ) { if(!m_ppRenderPart[i]) { continue; } g_pSunRenderer->RenderUnit( m_ppRenderPart[i] ); } return NPC::Render(); } //------------------------------------------------------------------------------ /** º»À妽ºÃßÃâ(°¢ÀÚ¸´¼ö ¼ýÀÚÀ§Ä¡) */ void LottoNPC::ExtractBoneIndex() { if(!m_pBasePart) { return; } CWzUnit* pUnit = m_pBasePart->GetWzUnit(); //À¯´Ö¾øÀ¸¸é ¸®ÅÏ if(!pUnit) { return; } TCHAR szNumber[30]; for(int i=0;iGetBoneInfo(StrToWzID(szNumber)); m_arBonPosition[i] = (pInfo ? (pInfo->m_iNode):(-1)); } } //------------------------------------------------------------------------------ /** ¼ýÀھִϸÞÀ̼Ç(¼ýÀÚ°¡ ¶Ç·Î·Ï¿Ã¶ó°¡´Â È¿°ú) */ void LottoNPC::AnimationNumber(DWORD dwTick) { static DWORD dwUpdateTick = 0; //ÀÏÁ¤°£°Ý¸¶´Ù °»½ÅÇÑ´Ù. dwUpdateTick+=dwTick; if(dwUpdateTick < 50) { return; } dwUpdateTick = 0; int nFindTopIndex = -1; //ÃÖ»óÀ§¼ýÀÚ¸¦ ã´Â´Ù. int i=0; for(;i9) { m_arOldNumber[i] = 0; } break; } } } //¸¶Áö¸·À¸¸£ Á¦¿ÜÇÑ ³ª¸ÓÁö´Â ++½ÃÄÑÁØ´Ù. for( i=nFindTopIndex+1;i9) { m_arOldNumber[i] = 0; } } //´õÀÌ»ó ¾Ö´ÏÇÒ°Ô ¾ø´Ù¸é ¾Ö´ÏÁ¾·á if(nFindTopIndex==-1) { memcpy(&m_arOldNumber,&m_arCurNumber,sizeof(m_arCurNumber)); m_bNumberAni = FALSE; } } //------------------------------------------------------------------------------ /** ¼ýÀھִϸÞÀ̼Ç(±ÔÄ¢¾øÀÌ ¸ðµçÀÚ¸´¼ö°¡ °è¼Óµ·´Ù) */ void LottoNPC::AnimationNumberChaos(DWORD dwTick) { static DWORD dwUpdateTickChaos = 0; //ÀÏÁ¤°£°Ý¸¶´Ù °»½ÅÇÑ´Ù. dwUpdateTickChaos+=dwTick; if(dwUpdateTickChaos < 100) { return; } dwUpdateTickChaos = 0; for(int i=0;i9) { m_arOldNumber[i] = 0; } } } //------------------------------------------------------------------------------ /** ¼ýÀÚ¸¦ ¹®ÀÚ·Î º¯È¯ÇØ °¢ÀÚ¸´¼ö¸¦ ºÐ¸®ÇØ ¹è¿­¿¡ ´ã´Â´Ù */ void LottoNPC::SetparateNumber(INT64 Number) { //¹Ù²îÁö¾Ê¾Ò´Ù¸é ¸®ÅÏ! if(m_iOldNumber==Number && Number!=0) { m_bNumberAni = FALSE; return; } m_iOldNumber = Number; TCHAR szNumber[100]={0}; _i64toa(Number,szNumber,10); int iLen = strlen(szNumber); util::_tstring str(szNumber); memset(m_arCurNumber,-1,sizeof(m_arCurNumber)); //ÀÚ¿¬½º·´°Ô ¿Ã¶ó°¡´Â ¾Ö´Ï¸¦ À§ÇØ if(Number!=0) { for(int a=0;a(NUM_MAX_UNIT-2) ) { m_ppRenderPart[i]->SetWzUnit(m_ppNumberUnit[0],FALSE); } else { m_ppRenderPart[i]->SetWzUnit(m_ppNumberUnit[m_arOldNumber[i]+1],FALSE); } } } //------------------------------------------------------------------------------ /** ¼ýÀÚÆÇ ºôº¸µå */ void LottoNPC::SetBillBoard() { static WzVector vOldAxisCam; //Ä«¸Þ¶ó Çà·Ä¾ò±â WzMatrix wmViewMat; g_pSunRenderer->GetViewMatrix(&wmViewMat); //XÃà¿¡´ëÇÑ ºôº¸µù WzVector vAxisOrg,vAxisCam; //Ä«¸Þ¶ó ¸ÞÆ®¸¯½ºÀÇ Right(xÃà)¼ººÐ ÃßÃâ SetVector(&vAxisCam,wmViewMat._11, wmViewMat._21,wmViewMat._31); //°ªÀÌ ¹Ù²î¾úÀ»´ë¸¸ ÇÑ´Ù. if(vAxisCam==vOldAxisCam) { return; } SetVector(&vAxisOrg,1.0f,0.0f,0.0f); //ȸÀüÃà¾ò±â WzVector vRotAxis; VectorCrossProduct( &vRotAxis, &vAxisOrg, &vAxisCam); VectorNormalize( &vRotAxis, &vRotAxis); //ÃÖÁ¾È¸Àü¸ÞÆ®¸¯½º¾ò±â WzMatrix wmFinalRot; MatrixRotation(&wmFinalRot, &vRotAxis, acosf( VectorDotProduct( &vAxisOrg, &vAxisCam))); m_pBasePart->SetRotationByMatrix(&wmFinalRot); vOldAxisCam = vAxisCam; }