Changeset 272 for trunk/src/game/ObjectMgr.cpp
- Timestamp:
- 11/22/08 00:35:41 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/ObjectMgr.cpp
r263 r272 11 11 * This program is distributed in the hope that it will be useful, 12 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 * GNU General Public License for more details. 15 15 * 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307USA18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 */ 20 20 … … 22 22 #include "Database/DatabaseEnv.h" 23 23 #include "Database/SQLStorage.h" 24 #include "Database/SQLStorageImpl.h"25 24 26 25 #include "Log.h" … … 118 117 m_hiDoGuid = 1; 119 118 m_hiCorpseGuid = 1; 119 120 120 m_hiPetNumber = 1; 121 m_ItemTextId = 1;122 m_mailid = 1;123 m_auctionid = 1;124 m_guildId = 1;125 m_arenaTeamId = 1;126 121 127 122 mGuildBankTabPrice.resize(GUILD_BANK_MAX_TABS); … … 421 416 422 417 //prepare mail data... : 423 uint32 itemTextId = CreateItemText( msgAuctionWonBody.str() );418 uint32 itemTextId = this->CreateItemText( msgAuctionWonBody.str() ); 424 419 425 420 // set owner to bidder (to prevent delete item with sender char deleting) … … 472 467 sLog.outDebug("AuctionSalePending body string : %s", msgAuctionSalePendingBody.str().c_str()); 473 468 474 uint32 itemTextId = CreateItemText( msgAuctionSalePendingBody.str() );469 uint32 itemTextId = this->CreateItemText( msgAuctionSalePendingBody.str() ); 475 470 476 471 WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->owner, msgAuctionSalePendingSubject.str(), itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_AUCTION); … … 504 499 sLog.outDebug("AuctionSuccessful body string : %s", auctionSuccessfulBody.str().c_str()); 505 500 506 uint32 itemTextId = CreateItemText( auctionSuccessfulBody.str() );501 uint32 itemTextId = this->CreateItemText( auctionSuccessfulBody.str() ); 507 502 508 503 uint32 profit = auction->bid + auction->deposit - auctionCut; … … 551 546 // will delete item or place to receiver mail list 552 547 WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, GUID_LOPART(owner_guid), subject.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE); 548 553 549 } 554 550 // owner not found … … 568 564 void ObjectMgr::LoadCreatureLocales() 569 565 { 570 mCreatureLocaleMap.clear(); // need for reload case571 566 mCreatureLocaleMap.clear(); 567 572 568 QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,subname_loc1,name_loc2,subname_loc2,name_loc3,subname_loc3,name_loc4,subname_loc4,name_loc5,subname_loc5,name_loc6,subname_loc6,name_loc7,subname_loc7,name_loc8,subname_loc8 FROM locales_creature"); 573 569 … … 628 624 sLog.outString( ">> Loaded %u creature locale strings", mCreatureLocaleMap.size() ); 629 625 } 630 626 631 627 void ObjectMgr::LoadNpcOptionLocales() 632 628 { … … 697 693 } 698 694 699 struct SQLCreatureLoader : public SQLStorageLoaderBase<SQLCreatureLoader>700 {701 template<class D>702 void convert_from_str(uint32 field_pos, char *src, D &dst)703 {704 dst = D(objmgr.GetScriptId(src));705 }706 };707 708 695 void ObjectMgr::LoadCreatureTemplates() 709 696 { 710 SQLCreatureLoader loader; 711 loader.Load(sCreatureStorage); 697 sCreatureStorage.Load(); 712 698 713 699 sLog.outString( ">> Loaded %u creature definitions", sCreatureStorage.RecordCount ); … … 1527 1513 aItem->location = fields[11].GetUInt8(); 1528 1514 //check if sold item exists 1529 if ( GetAItem( aItem->item_guidlow ) )1515 if ( this->GetAItem( aItem->item_guidlow ) ) 1530 1516 { 1531 1517 GetAuctionsMap( aItem->location )->AddAuction(aItem); … … 1547 1533 void ObjectMgr::LoadItemLocales() 1548 1534 { 1549 mItemLocaleMap.clear(); // need for reload case1550 1535 mItemLocaleMap.clear(); 1536 1551 1537 QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,description_loc1,name_loc2,description_loc2,name_loc3,description_loc3,name_loc4,description_loc4,name_loc5,description_loc5,name_loc6,description_loc6,name_loc7,description_loc7,name_loc8,description_loc8 FROM locales_item"); 1552 1538 … … 1609 1595 } 1610 1596 1611 struct SQLItemLoader : public SQLStorageLoaderBase<SQLItemLoader>1612 {1613 template<class D>1614 void convert_from_str(uint32 field_pos, char *src, D &dst)1615 {1616 dst = D(objmgr.GetScriptId(src));1617 }1618 };1619 1620 1597 void ObjectMgr::LoadItemPrototypes() 1621 1598 { 1622 SQLItemLoader loader; 1623 loader.Load(sItemStorage); 1599 sItemStorage.Load (); 1624 1600 sLog.outString( ">> Loaded %u item prototypes", sItemStorage.RecordCount ); 1625 1601 sLog.outString(); … … 2531 2507 if (sWorld.getConfig(CONFIG_EXPANSION) < 1 && (race == RACE_BLOODELF || race == RACE_DRAENEI)) 2532 2508 continue; 2533 2509 2534 2510 // skip expansion classes if not playing with expansion 2535 2511 if (sWorld.getConfig(CONFIG_EXPANSION) < 2 && class_ == CLASS_DEATH_KNIGHT) … … 3580 3556 void ObjectMgr::LoadQuestLocales() 3581 3557 { 3582 mQuestLocaleMap.clear(); // need for reload case3558 mQuestLocaleMap.clear(); 3583 3559 3584 3560 QueryResult *result = WorldDatabase.Query("SELECT entry," … … 3774 3750 scripts.clear(); // need for reload support 3775 3751 3776 QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,data int, x, y, z, o FROM %s", tablename );3752 QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,datatext, x, y, z, o FROM %s", tablename ); 3777 3753 3778 3754 uint32 count = 0; … … 3796 3772 Field *fields = result->Fetch(); 3797 3773 ScriptInfo tmp; 3798 tmp.id 3799 tmp.delay 3800 tmp.command 3801 tmp.datalong 3774 tmp.id = fields[0].GetUInt32(); 3775 tmp.delay = fields[1].GetUInt32(); 3776 tmp.command = fields[2].GetUInt32(); 3777 tmp.datalong = fields[3].GetUInt32(); 3802 3778 tmp.datalong2 = fields[4].GetUInt32(); 3803 tmp.data int = fields[5].GetInt32();3804 tmp.x 3805 tmp.y 3806 tmp.z 3807 tmp.o 3779 tmp.datatext = fields[5].GetCppString(); 3780 tmp.x = fields[6].GetFloat(); 3781 tmp.y = fields[7].GetFloat(); 3782 tmp.z = fields[8].GetFloat(); 3783 tmp.o = fields[9].GetFloat(); 3808 3784 3809 3785 // generic command args check … … 3817 3793 continue; 3818 3794 } 3819 if(tmp.dataint==0)3820 {3821 sLog.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.dataint,tmp.id);3822 continue;3823 }3824 if(tmp.dataint < MIN_DB_SCRIPT_STRING_ID || tmp.dataint >= MAX_DB_SCRIPT_STRING_ID)3825 {3826 sLog.outErrorDb("Table `%s` has out of range text id (dataint = %i expected %u-%u) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.dataint,MIN_DB_SCRIPT_STRING_ID,MAX_DB_SCRIPT_STRING_ID,tmp.id);3827 continue;3828 }3829 3830 // if(!objmgr.GetMangosStringLocale(tmp.dataint)) will checked after db_script_string loading3831 3795 break; 3832 3796 } … … 4193 4157 void ObjectMgr::LoadPageTextLocales() 4194 4158 { 4195 mPageTextLocaleMap.clear(); // need for reload case4196 4159 mPageTextLocaleMap.clear(); 4160 4197 4161 QueryResult *result = WorldDatabase.Query("SELECT entry,text_loc1,text_loc2,text_loc3,text_loc4,text_loc5,text_loc6,text_loc7,text_loc8 FROM locales_page_text"); 4198 4162 … … 4243 4207 } 4244 4208 4245 struct SQLInstanceLoader : public SQLStorageLoaderBase<SQLInstanceLoader>4246 {4247 template<class D>4248 void convert_from_str(uint32 field_pos, char *src, D &dst)4249 {4250 dst = D(objmgr.GetScriptId(src));4251 }4252 };4253 4254 4209 void ObjectMgr::LoadInstanceTemplate() 4255 4210 { 4256 SQLInstanceLoader loader; 4257 loader.Load(sInstanceTemplate); 4211 sInstanceTemplate.Load(); 4258 4212 4259 4213 for(uint32 i = 0; i < sInstanceTemplate.MaxEntry; i++) … … 4371 4325 void ObjectMgr::LoadNpcTextLocales() 4372 4326 { 4373 mNpcTextLocaleMap.clear(); // need for reload case4374 4327 mNpcTextLocaleMap.clear(); 4328 4375 4329 QueryResult *result = WorldDatabase.Query("SELECT entry," 4376 4330 "Text0_0_loc1,Text0_1_loc1,Text1_0_loc1,Text1_1_loc1,Text2_0_loc1,Text2_1_loc1,Text3_0_loc1,Text3_1_loc1,Text4_0_loc1,Text4_1_loc1,Text5_0_loc1,Text5_1_loc1,Text6_0_loc1,Text6_1_loc1,Text7_0_loc1,Text7_1_loc1," … … 4669 4623 4670 4624 uint32 Trigger_ID = fields[0].GetUInt32(); 4671 const char *scriptName = fields[1].GetString();4625 std::string scriptName = fields[1].GetCppString(); 4672 4626 4673 4627 AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); … … 4677 4631 continue; 4678 4632 } 4679 mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName);4633 mAreaTriggerScripts[Trigger_ID] = scriptName; 4680 4634 } while( result->NextRow() ); 4681 4635 … … 4685 4639 sLog.outString( ">> Loaded %u areatrigger scripts", count ); 4686 4640 } 4687 4688 4641 uint32 ObjectMgr::GetNearestTaxiNode( float x, float y, float z, uint32 mapid ) 4689 4642 { … … 4744 4697 uint16 ObjectMgr::GetTaxiMount( uint32 id, uint32 team ) 4745 4698 { 4746 uint 16mount_entry = 0;4747 uint 16mount_id = 0;4699 uint32 mount_entry = 0; 4700 uint32 mount_id = 0; 4748 4701 4749 4702 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(id); 4750 if (node)4703 if (node) 4751 4704 { 4752 4705 if (team == ALLIANCE) mount_entry = node->alliance_mount_type; … … 4987 4940 } 4988 4941 4942 // find now nearest graveyard at same map 4989 4943 if(entryNear) 4990 4944 return entryNear; … … 5227 5181 { 5228 5182 m_hiCharGuid = (*result)[0].GetUInt32()+1; 5183 5229 5184 delete result; 5230 5185 } … … 5234 5189 { 5235 5190 m_hiCreatureGuid = (*result)[0].GetUInt32()+1; 5191 5236 5192 delete result; 5237 5193 } 5238 5194 5239 // pet guids are not saved to DB, set to 0 (pet guid != pet id) 5240 m_hiPetGuid = 0; 5195 result = CharacterDatabase.Query( "SELECT MAX(id) FROM character_pet" ); 5196 if( result ) 5197 { 5198 m_hiPetGuid = (*result)[0].GetUInt32()+1; 5199 5200 delete result; 5201 } 5241 5202 5242 5203 result = CharacterDatabase.Query( "SELECT MAX(guid) FROM item_instance" ); … … 5244 5205 { 5245 5206 m_hiItemGuid = (*result)[0].GetUInt32()+1; 5207 5246 5208 delete result; 5247 5209 } … … 5257 5219 { 5258 5220 m_hiGoGuid = (*result)[0].GetUInt32()+1; 5221 5259 5222 delete result; 5260 5223 } … … 5264 5227 { 5265 5228 m_auctionid = (*result)[0].GetUInt32()+1; 5229 5266 5230 delete result; 5267 5231 } 5268 5232 else 5233 { 5234 m_auctionid = 0; 5235 } 5269 5236 result = CharacterDatabase.Query( "SELECT MAX(id) FROM mail" ); 5270 5237 if( result ) 5271 5238 { 5272 5239 m_mailid = (*result)[0].GetUInt32()+1; 5240 5273 5241 delete result; 5274 5242 } 5275 5243 else 5244 { 5245 m_mailid = 0; 5246 } 5276 5247 result = CharacterDatabase.Query( "SELECT MAX(id) FROM item_text" ); 5277 5248 if( result ) 5278 5249 { 5279 m_ItemTextId = (*result)[0].GetUInt32()+1; 5250 m_ItemTextId = (*result)[0].GetUInt32(); 5251 5280 5252 delete result; 5281 5253 } 5254 else 5255 m_ItemTextId = 0; 5282 5256 5283 5257 result = CharacterDatabase.Query( "SELECT MAX(guid) FROM corpse" ); … … 5285 5259 { 5286 5260 m_hiCorpseGuid = (*result)[0].GetUInt32()+1; 5261 5287 5262 delete result; 5288 5263 } 5289 5290 result = CharacterDatabase.Query("SELECT MAX(arenateamid) FROM arena_team");5291 if (result)5292 {5293 m_arenaTeamId = (*result)[0].GetUInt32()+1;5294 delete result;5295 }5296 5297 result = CharacterDatabase.Query( "SELECT MAX(guildid) FROM guild" );5298 if (result)5299 {5300 m_guildId = (*result)[0].GetUInt32()+1;5301 delete result;5302 }5303 }5304 5305 uint32 ObjectMgr::GenerateArenaTeamId()5306 {5307 if(m_arenaTeamId>=0xFFFFFFFE)5308 {5309 sLog.outError("Arena team ids overflow!! Can't continue, shutting down server. ");5310 World::StopNow(ERROR_EXIT_CODE);5311 }5312 return m_arenaTeamId++;5313 }5314 5315 uint32 ObjectMgr::GenerateGuildId()5316 {5317 if(m_guildId>=0xFFFFFFFE)5318 {5319 sLog.outError("Guild ids overflow!! Can't continue, shutting down server. ");5320 World::StopNow(ERROR_EXIT_CODE);5321 }5322 return m_guildId++;5323 5264 } 5324 5265 5325 5266 uint32 ObjectMgr::GenerateAuctionID() 5326 5267 { 5327 if(m_auctionid>=0xFFFFFFFE) 5268 ++m_auctionid; 5269 if(m_auctionid>=0xFFFFFFFF) 5328 5270 { 5329 5271 sLog.outError("Auctions ids overflow!! Can't continue, shutting down server. "); 5330 World::StopNow(ERROR_EXIT_CODE);5331 } 5332 return m_auctionid ++;5272 sWorld.m_stopEvent = true; 5273 } 5274 return m_auctionid; 5333 5275 } 5334 5276 5335 5277 uint32 ObjectMgr::GenerateMailID() 5336 5278 { 5337 if(m_mailid>=0xFFFFFFFE) 5279 ++m_mailid; 5280 if(m_mailid>=0xFFFFFFFF) 5338 5281 { 5339 5282 sLog.outError("Mail ids overflow!! Can't continue, shutting down server. "); 5340 World::StopNow(ERROR_EXIT_CODE);5341 } 5342 return m_mailid ++;5283 sWorld.m_stopEvent = true; 5284 } 5285 return m_mailid; 5343 5286 } 5344 5287 5345 5288 uint32 ObjectMgr::GenerateItemTextID() 5346 5289 { 5347 if(m_ItemTextId>=0xFFFFFFFE) 5290 ++m_ItemTextId; 5291 if(m_ItemTextId>=0xFFFFFFFF) 5348 5292 { 5349 5293 sLog.outError("Item text ids overflow!! Can't continue, shutting down server. "); 5350 World::StopNow(ERROR_EXIT_CODE);5351 } 5352 return m_ItemTextId ++;5294 sWorld.m_stopEvent = true; 5295 } 5296 return m_ItemTextId; 5353 5297 } 5354 5298 … … 5372 5316 { 5373 5317 case HIGHGUID_ITEM: 5374 if(m_hiItemGuid>=0xFFFFFFFE) 5318 ++m_hiItemGuid; 5319 if(m_hiItemGuid>=0xFFFFFFFF) 5375 5320 { 5376 5321 sLog.outError("Item guid overflow!! Can't continue, shutting down server. "); 5377 World::StopNow(ERROR_EXIT_CODE);5378 } 5379 return m_hiItemGuid ++;5322 sWorld.m_stopEvent = true; 5323 } 5324 return m_hiItemGuid; 5380 5325 case HIGHGUID_UNIT: 5381 if(m_hiCreatureGuid>=0x00FFFFFE) 5326 ++m_hiCreatureGuid; 5327 if(m_hiCreatureGuid>=0x00FFFFFF) 5382 5328 { 5383 5329 sLog.outError("Creature guid overflow!! Can't continue, shutting down server. "); 5384 World::StopNow(ERROR_EXIT_CODE);5385 } 5386 return m_hiCreatureGuid ++;5330 sWorld.m_stopEvent = true; 5331 } 5332 return m_hiCreatureGuid; 5387 5333 case HIGHGUID_PET: 5388 if(m_hiPetGuid>=0x00FFFFFE) 5334 ++m_hiPetGuid; 5335 if(m_hiPetGuid>=0x00FFFFFF) 5389 5336 { 5390 5337 sLog.outError("Pet guid overflow!! Can't continue, shutting down server. "); 5391 World::StopNow(ERROR_EXIT_CODE);5392 } 5393 return m_hiPetGuid ++;5338 sWorld.m_stopEvent = true; 5339 } 5340 return m_hiPetGuid; 5394 5341 case HIGHGUID_PLAYER: 5395 if(m_hiCharGuid>=0xFFFFFFFE) 5342 ++m_hiCharGuid; 5343 if(m_hiCharGuid>=0xFFFFFFFF) 5396 5344 { 5397 5345 sLog.outError("Players guid overflow!! Can't continue, shutting down server. "); 5398 World::StopNow(ERROR_EXIT_CODE);5399 } 5400 return m_hiCharGuid ++;5346 sWorld.m_stopEvent = true; 5347 } 5348 return m_hiCharGuid; 5401 5349 case HIGHGUID_GAMEOBJECT: 5402 if(m_hiGoGuid>=0x00FFFFFE) 5350 ++m_hiGoGuid; 5351 if(m_hiGoGuid>=0x00FFFFFF) 5403 5352 { 5404 5353 sLog.outError("Gameobject guid overflow!! Can't continue, shutting down server. "); 5405 World::StopNow(ERROR_EXIT_CODE);5406 } 5407 return m_hiGoGuid ++;5354 sWorld.m_stopEvent = true; 5355 } 5356 return m_hiGoGuid; 5408 5357 case HIGHGUID_CORPSE: 5409 if(m_hiCorpseGuid>=0xFFFFFFFE) 5358 ++m_hiCorpseGuid; 5359 if(m_hiCorpseGuid>=0xFFFFFFFF) 5410 5360 { 5411 5361 sLog.outError("Corpse guid overflow!! Can't continue, shutting down server. "); 5412 World::StopNow(ERROR_EXIT_CODE);5413 } 5414 return m_hiCorpseGuid ++;5362 sWorld.m_stopEvent = true; 5363 } 5364 return m_hiCorpseGuid; 5415 5365 case HIGHGUID_DYNAMICOBJECT: 5416 if(m_hiDoGuid>=0xFFFFFFFE) 5366 ++m_hiDoGuid; 5367 if(m_hiDoGuid>=0xFFFFFFFF) 5417 5368 { 5418 5369 sLog.outError("DynamicObject guid overflow!! Can't continue, shutting down server. "); 5419 World::StopNow(ERROR_EXIT_CODE);5420 } 5421 return m_hiDoGuid ++;5370 sWorld.m_stopEvent = true; 5371 } 5372 return m_hiDoGuid; 5422 5373 default: 5423 5374 ASSERT(0); … … 5430 5381 void ObjectMgr::LoadGameObjectLocales() 5431 5382 { 5432 mGameObjectLocaleMap.clear(); // need for reload case5433 5383 mGameObjectLocaleMap.clear(); 5384 5434 5385 QueryResult *result = WorldDatabase.Query("SELECT entry," 5435 5386 "name_loc1,name_loc2,name_loc3,name_loc4,name_loc5,name_loc6,name_loc7,name_loc8," … … 5499 5450 } 5500 5451 5501 struct SQLGameObjectLoader : public SQLStorageLoaderBase<SQLGameObjectLoader>5502 {5503 template<class D>5504 void convert_from_str(uint32 field_pos, char *src, D &dst)5505 {5506 dst = D(objmgr.GetScriptId(src));5507 }5508 };5509 5510 5452 void ObjectMgr::LoadGameobjectInfo() 5511 5453 { 5512 SQLGameObjectLoader loader; 5513 loader.Load(sGOStorage); 5454 sGOStorage.Load(); 5514 5455 5515 5456 // some checks … … 6684 6625 } 6685 6626 6686 uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id)6687 { 6688 AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find( trigger_id);6627 const char* ObjectMgr::GetAreaTriggerScriptName(uint32 id) 6628 { 6629 AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(id); 6689 6630 if(i!= mAreaTriggerScripts.end()) 6690 return i->second ;6691 return 0;6631 return i->second.c_str(); 6632 return ""; 6692 6633 } 6693 6634 … … 6734 6675 return false; 6735 6676 } 6736 6737 6738 6739 6677 case CONDITION_NO_AURA: 6678 return !player->HasAura(value1, value2); 6679 case CONDITION_ACTIVE_EVENT: 6680 return gameeventmgr.IsActiveEvent(value1); 6740 6681 default: 6741 6682 return false; … … 6858 6799 break; 6859 6800 } 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6801 case CONDITION_NO_AURA: 6802 { 6803 if(!sSpellStore.LookupEntry(value1)) 6804 { 6805 sLog.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1); 6806 return false; 6807 } 6808 if(value2 > 2) 6809 { 6810 sLog.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2); 6811 return false; 6812 } 6813 break; 6814 } 6815 case CONDITION_ACTIVE_EVENT: 6816 { 6817 GameEvent::GameEventDataMap const& events = gameeventmgr.GetEventMap(); 6818 if(value1 >=events.size() || !events[value1].isValid()) 6819 { 6820 sLog.outErrorDb("Active event condition requires existed event id (%u), skipped", value1); 6821 return false; 6822 } 6823 break; 6824 } 6884 6825 } 6885 6826 return true; … … 7011 6952 if(itr->first > new_id) 7012 6953 new_id = itr->first; 7013 6954 7014 6955 // use next 7015 6956 ++new_id; … … 7051 6992 void ObjectMgr::LoadTrainerSpell() 7052 6993 { 7053 // For reload case 6994 // For reload case 7054 6995 for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr) 7055 6996 itr->second.Clear(); … … 7142 7083 void ObjectMgr::LoadVendors() 7143 7084 { 7144 // For reload case 7085 // For reload case 7145 7086 for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr) 7146 7087 itr->second.Clear(); … … 7249 7190 "SELECT id,gossip_id,npcflag,icon,action,box_money,coded,option_text,box_text " 7250 7191 "FROM npc_option"); 7251 7252 7192 if( !result ) 7253 7193 { … … 7402 7342 } 7403 7343 7404 void ObjectMgr::LoadScriptNames()7405 {7406 m_scriptNames.push_back("");7407 QueryResult *result = WorldDatabase.Query(7408 "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' "7409 "UNION "7410 "SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' "7411 "UNION "7412 "SELECT DISTINCT(ScriptName) FROM item_template WHERE ScriptName <> '' "7413 "UNION "7414 "SELECT DISTINCT(ScriptName) FROM areatrigger_scripts WHERE ScriptName <> '' "7415 "UNION "7416 "SELECT DISTINCT(script) FROM instance_template WHERE script <> ''");7417 if(result)7418 {7419 do7420 {7421 m_scriptNames.push_back((*result)[0].GetString());7422 } while (result->NextRow());7423 delete result;7424 }7425 7426 std::sort(m_scriptNames.begin(), m_scriptNames.end());7427 }7428 7429 uint32 ObjectMgr::GetScriptId(const char *name)7430 {7431 // use binary search to find the script name in the sorted vector7432 // assume "" is the first element7433 if(!name) return 0;7434 ScriptNameMap::const_iterator itr =7435 std::lower_bound(m_scriptNames.begin(), m_scriptNames.end(), name);7436 if(itr == m_scriptNames.end()) return 0;7437 return itr - m_scriptNames.begin();7438 }7439 7440 void ObjectMgr::CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids)7441 {7442 for(ScriptMapMap::const_iterator itrMM = scripts.begin(); itrMM != scripts.end(); ++itrMM)7443 {7444 for(ScriptMap::const_iterator itrM = itrMM->second.begin(); itrM != itrMM->second.end(); ++itrM)7445 {7446 if(itrM->second.dataint)7447 {7448 if(!GetTrinityStringLocale (itrM->second.dataint))7449 sLog.outErrorDb( "Table `db_script_string` has not existed string id %u", *itrM);7450 7451 if(ids.count(itrM->second.dataint))7452 ids.erase(itrM->second.dataint);7453 }7454 }7455 }7456 }7457 7458 void ObjectMgr::LoadDbScriptStrings()7459 {7460 LoadTrinityStrings(WorldDatabase,"db_script_string",MIN_DB_SCRIPT_STRING_ID,MAX_DB_SCRIPT_STRING_ID);7461 7462 std::set<int32> ids;7463 7464 for(int32 i = MIN_DB_SCRIPT_STRING_ID; i < MAX_DB_SCRIPT_STRING_ID; ++i)7465 if(GetTrinityStringLocale(i))7466 ids.insert(i);7467 7468 CheckScripts(sQuestEndScripts,ids);7469 CheckScripts(sQuestStartScripts,ids);7470 CheckScripts(sSpellScripts,ids);7471 CheckScripts(sGameObjectScripts,ids);7472 CheckScripts(sEventScripts,ids);7473 7474 for(std::set<int32>::const_iterator itr = ids.begin(); itr != ids.end(); ++itr)7475 sLog.outErrorDb( "Table `db_script_string` has unused string id %u", *itr);7476 }7477 7478 7344 // Functions for scripting access 7479 uint32 GetAreaTriggerScriptId(uint32 trigger_id)7480 { 7481 return objmgr.GetAreaTriggerScript Id(trigger_id);7345 const char* GetAreaTriggerScriptNameById(uint32 id) 7346 { 7347 return objmgr.GetAreaTriggerScriptName(id); 7482 7348 } 7483 7349 … … 7494 7360 return objmgr.LoadTrinityStrings(db,table,end_value,start_value); 7495 7361 } 7496 7497 uint32 TRINITY_DLL_SPEC GetScriptId(const char *name)7498 {7499 return objmgr.GetScriptId(name);7500 }7501 7502 ObjectMgr::ScriptNameMap & GetScriptNames()7503 {7504 return objmgr.GetScriptNames();7505 }