📄 castleshrineinfomanager.cpp
字号:
#include <stdio.h>#include "CastleShrineInfoManager.h"#include "StringStream.h"#include "DB.h"#include "ZoneItemPosition.h"#include "Zone.h"#include "ZoneUtil.h"#include "MonsterCorpse.h"#include "Item.h"#include "ItemFactoryManager.h"#include "EffectShrineGuard.h"#include "EffectShrineHoly.h"#include "EffectShrineShield.h"#include "War.h"#include "WarSystem.h"#include "RelicUtil.h"#include "CastleInfoManager.h"#include "GlobalItemPosition.h"#include "GlobalItemPositionLoader.h"#include "ZoneGroupManager.h"#include "Player.h"#include "GuildWar.h"#include "PlayerCreature.h"#include "CreatureUtil.h"#include "StringPool.h"#include "Gpackets/GCSystemMessage.h"#include "Gpackets/GCRemoveEffect.h"#include "Gpackets/GCAddEffect.h"#include "Gpackets/GCAddEffectToTile.h"#include "Gpackets/GCDeleteInventoryItem.h"#include "CastleSymbol.h"string CastleShrineSet::toString() const throw(){ __BEGIN_TRY StringStream msg; msg << "ShrineSet(" << "ShrineID:" << (int)m_ShrineID << "," << m_GuardShrine.toString() << "," << m_HolyShrine.toString() << ",ItemType:" << (int)m_ItemType << ")"; return msg.toString(); __END_CATCH}CastleShrineInfoManager::~CastleShrineInfoManager(){ clear();}void CastleShrineInfoManager::clear(){ HashMapShrineSetItor itr = m_ShrineSets.begin(); for ( ; itr != m_ShrineSets.end() ; itr++ ) { SAFE_DELETE( itr->second ); } m_ShrineSets.clear();}void CastleShrineInfoManager::init() throw (Error){ __BEGIN_TRY load(); addAllShrineToZone(); __END_CATCH}void CastleShrineInfoManager::load() throw (Error){ __BEGIN_TRY Statement* pStmt = NULL; Result* pResult = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pResult = pStmt->executeQuery( "SELECT ID, Name, ItemType, GuardZoneID, GuardX, GuardY, GuardMType, HolyZoneID, HolyX, HolyY, HolyMType FROM CastleShrineInfo" ); while ( pResult->next() ) { int i = 0; CastleShrineSet* pShrineSet = new CastleShrineSet(); pShrineSet->m_ShrineID = pResult->getInt( ++i ); pShrineSet->m_GuardShrine.setName( pResult->getString( ++i ) ); pShrineSet->m_HolyShrine.setName( pShrineSet->m_GuardShrine.getName() ); pShrineSet->m_ItemType = pResult->getInt( ++i ); pShrineSet->m_GuardShrine.setZoneID( pResult->getInt( ++i ) ); pShrineSet->m_GuardShrine.setX( pResult->getInt( ++i ) ); pShrineSet->m_GuardShrine.setY( pResult->getInt( ++i ) ); pShrineSet->m_GuardShrine.setMonsterType( pResult->getInt( ++i ) ); pShrineSet->m_HolyShrine.setZoneID( pResult->getInt( ++i ) ); pShrineSet->m_HolyShrine.setX( pResult->getInt( ++i ) ); pShrineSet->m_HolyShrine.setY( pResult->getInt( ++i ) ); pShrineSet->m_HolyShrine.setMonsterType( pResult->getInt( ++i ) ); pShrineSet->m_GuardShrine.setShrineType( ShrineInfo::SHRINE_GUARD ); pShrineSet->m_HolyShrine.setShrineType( ShrineInfo::SHRINE_HOLY ); // ItemType苞 Shrine ID绰 鞍酒具 茄促. 鞍瘤 臼阑 版快 DB汲沥 坷幅肺 肺爹苞沥俊辑 阜绰促. if ( pShrineSet->m_ItemType != pShrineSet->m_ShrineID ) { cout << "ShrineID 客 ItemType捞 嘎瘤 臼嚼聪促. DB汲沥阑 痢八窍技夸." << endl; Assert( false ); } addShrineSet( pShrineSet ); } } END_DB( pStmt ) __END_CATCH}ZoneID_t CastleShrineInfoManager::getGuardShrineZoneID( ZoneID_t castleZoneID ) const throw(Error){ __BEGIN_TRY HashMapShrineSetConstItor itr = m_ShrineSets.begin(); // castleZoneID狼 shrineID甫 八祸且荐啊 绝绢辑 窍唱窍唱 厚背茄促. -_-; for (; itr!=m_ShrineSets.end(); itr++) { CastleShrineSet* pShrineSet = itr->second; ZoneID_t guardZoneID = pShrineSet->m_GuardShrine.getZoneID(); ZoneID_t guardCastleZoneID; if (g_pCastleInfoManager->getCastleZoneID(guardZoneID, guardCastleZoneID)) { if (castleZoneID==guardCastleZoneID) { return guardZoneID; } } } StringStream msg; msg << "CastleZoneID客 包访等 GuardZoneID啊 绝促[" << (int)castleZoneID << "]"; throw Error(msg.toString()); __END_CATCH}void CastleShrineInfoManager::addAllShrineToZone() throw(Error){ __BEGIN_TRY HashMapShrineSetItor itr = m_ShrineSets.begin(); for ( ; itr != m_ShrineSets.end() ; itr++ ) { CastleShrineSet* pShrineSet = itr->second; if ( pShrineSet == NULL ) continue; Item* pItem = addShrineToZone( pShrineSet->m_GuardShrine, pShrineSet->m_ItemType ); if (pItem==NULL) { pShrineSet->setCastleSymbolItemID( 0 ); } else { pShrineSet->setCastleSymbolItemID( pItem->getItemID() ); } addShrineToZone( pShrineSet->m_HolyShrine, pShrineSet->m_ItemType ); } __END_CATCH}Item* CastleShrineInfoManager::addShrineToZone( ShrineInfo& shrineInfo, ItemType_t itemType ) throw(Error){ __BEGIN_TRY // 己窜阑 持阑 粮阑 啊廉柯促. Zone* pZone = getZoneByZoneID( shrineInfo.getZoneID() ); Assert( pZone != NULL ); MonsterCorpse* pShrine = new MonsterCorpse( shrineInfo.getMonsterType(), shrineInfo.getName(), 2 ); Assert( pShrine != NULL ); pShrine->setShrine( true ); pShrine->setZone( pZone ); pZone->getObjectRegistry().registerObject( pShrine ); shrineInfo.setObjectID( pShrine->getObjectID() ); cout << "AddShrine[" << (int)shrineInfo.getZoneID() << "] " << (shrineInfo.getShrineType()==ShrineInfo::SHRINE_GUARD? "Guard":"Holy") << ", mtype=" << shrineInfo.getMonsterType() << ", oid=" << pShrine->getObjectID() << endl; Item* pItem = NULL;/* if ( shrineInfo.getShrineType() == ShrineInfo::SHRINE_GUARD ) { pShrine->setFlag( Effect::EFFECT_CLASS_SHRINE_GUARD ); EffectShrineGuard* pEffect = new EffectShrineGuard(pShrine); pEffect->setShrineID( itemType ); pEffect->setTick( 60 * 10 ); pShrine->getEffectManager().addEffect( pEffect ); } else if ( shrineInfo.getShrineType() == ShrineInfo::SHRINE_HOLY ) { pShrine->setFlag( Effect::EFFECT_CLASS_SHRINE_HOLY ); EffectShrineHoly* pEffect = new EffectShrineHoly(pShrine); pEffect->setShrineID( itemType ); pEffect->setTick( 60 * 10 ); pShrine->getEffectManager().addEffect( pEffect ); }*/ TPOINT tp = pZone->addItem( pShrine, shrineInfo.getX(), shrineInfo.getY(), true ); Assert( tp.x != -1 ); // 己狼 惑隆阑 眠啊且 鞘夸啊 乐促搁 眠啊茄促. if ( shrineInfo.getShrineType() == ShrineInfo::SHRINE_GUARD ) { //if ( AddBible[ itemType ] ) { list<OptionType_t> optionNULL; pItem = g_pItemFactoryManager->createItem( Item::ITEM_CLASS_CASTLE_SYMBOL, itemType, optionNULL ); Assert( pItem != NULL ); char strZoneID[10]; sprintf(strZoneID, "%d", (int)pZone->getZoneID()); pZone->registerObject( pItem ); pItem->create( strZoneID, STORAGE_CORPSE, pShrine->getObjectID(), 0, 0 ); pShrine->addTreasure( pItem ); } // 荐龋己窜捞扼绰吧 钎矫秦敌促. pShrine->setFlag( Effect::EFFECT_CLASS_CASTLE_SHRINE_GUARD ); // 葛电 荐龋己窜俊 Shield Effect 嘿牢促 pShrine->setFlag( Effect::EFFECT_CLASS_SHRINE_SHIELD ); EffectShrineShield* pEffect = new EffectShrineShield(pShrine); pEffect->setShrineID( itemType ); pEffect->setTick( 60 * 10 ); pShrine->getEffectManager().addEffect( pEffect ); } else { // 己瘤己窜捞扼绰吧 钎矫秦敌促. pShrine->setFlag( Effect::EFFECT_CLASS_CASTLE_SHRINE_HOLY ); } // 己窜 谅钎甫 货肺 技泼茄促. shrineInfo.setX( tp.x ); shrineInfo.setY( tp.y ); return pItem; __END_CATCH}void CastleShrineInfoManager::addShrineSet( CastleShrineSet* pShrineSet ) throw(Error){ __BEGIN_TRY if ( pShrineSet == NULL ) return; ShrineID_t shrineID = pShrineSet->m_ShrineID; HashMapShrineSetItor itr = m_ShrineSets.find( shrineID ); if ( itr != m_ShrineSets.end() ) { filelog( "ShrineInfoError.log", "CastleShrineInfoManager::addShrineSet DuplicatedException : %d", (int)shrineID ); return; } m_ShrineSets[ shrineID ] = pShrineSet; __END_CATCH}void CastleShrineInfoManager::deleteShrineSet( ShrineID_t shrineID ) throw(Error){ __BEGIN_TRY HashMapShrineSetItor itr = m_ShrineSets.find( shrineID ); if ( itr != m_ShrineSets.end() ) { SAFE_DELETE( itr->second ); m_ShrineSets.erase( shrineID ); } __END_CATCH}CastleShrineSet* CastleShrineInfoManager::getShrineSet( ShrineID_t shrineID ) const throw(Error){ __BEGIN_TRY HashMapShrineSetConstItor itr = m_ShrineSets.find( shrineID ); if ( itr != m_ShrineSets.end() ) { return itr->second; } return NULL; __END_CATCH}bool CastleShrineInfoManager::isMatchHolyShrine(Item* pItem, MonsterCorpse* pMonsterCorpse) const throw(Error){ __BEGIN_TRY if ( pItem->getItemClass() != Item::ITEM_CLASS_CASTLE_SYMBOL ) return false; ItemType_t itemType = pItem->getItemType(); ShrineID_t shrineID = itemType; // ShrineID = ItemType(of CastleSymbol) CastleShrineSet* pShrineSet = getShrineSet( shrineID ); if( pShrineSet == NULL ) { // 捞 己狼 惑隆俊 秦寸窍绰 Shrine Set捞 绝促. return false; } // 捞 己狼 惑隆俊 秦寸窍绰 Shrine set狼 己瘤己窜狼 MonsterType捞 // 逞绢柯 MonsterCorpse狼 MonsterType苞 鞍绊 ObjectID档 鞍栏搁 true return pShrineSet->m_HolyShrine.getMonsterType() == pMonsterCorpse->getMonsterType() && pShrineSet->m_HolyShrine.getObjectID() == pMonsterCorpse->getObjectID(); __END_CATCH}bool CastleShrineInfoManager::isDefenderOfGuardShrine( PlayerCreature* pPC, MonsterCorpse* pShrine ) const throw(Error){ __BEGIN_TRY Zone* pZone = pShrine->getZone(); Assert( pZone != NULL ); // 己捞 酒聪搁 秽~ /* if ( !pZone->isCastle() ) { return false; } */ ZoneID_t guardZoneID = pZone->getZoneID(); ZoneID_t castleZoneID; bool isCastle = g_pCastleInfoManager->getCastleZoneID( guardZoneID, castleZoneID ); Assert(isCastle==true); War* pWar = g_pWarSystem->getActiveWar( castleZoneID ); if ( pWar == NULL ) return false; CastleInfo* pCastleInfo = g_pCastleInfoManager->getCastleInfo( castleZoneID ); if ( pCastleInfo == NULL ) return false; /* if ( pWar->getWarType() == WAR_RACE ) { // 辆练 傈里 吝俊绰 己狼 家蜡 辆练苞 鞍篮 辆练捞搁 defender 捞促. if ( pPC->getRace() == pCastleInfo->getRace() ) return true; } else */ if ( pWar->getWarType() == WAR_GUILD ) { GuildWar* pGuildWar = dynamic_cast<GuildWar*>(pWar); Assert(pGuildWar!=NULL); if ( pCastleInfo->isCommon() ) { // 傍侩己牢 版快绰 傍拜辨靛父 酒聪搁 defender捞促. return pPC->getGuildID()!=pGuildWar->getChallangerGuildID(); } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -