Changeset 279 for trunk/src/game/ObjectMgr.cpp
- Timestamp:
- 11/22/08 00:36:22 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/ObjectMgr.cpp
r272 r279 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. See the13 * 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" 24 25 25 26 #include "Log.h" … … 117 118 m_hiDoGuid = 1; 118 119 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; 121 126 122 127 mGuildBankTabPrice.resize(GUILD_BANK_MAX_TABS); … … 416 421 417 422 //prepare mail data... : 418 uint32 itemTextId = this->CreateItemText( msgAuctionWonBody.str() );423 uint32 itemTextId = CreateItemText( msgAuctionWonBody.str() ); 419 424 420 425 // set owner to bidder (to prevent delete item with sender char deleting) … … 467 472 sLog.outDebug("AuctionSalePending body string : %s", msgAuctionSalePendingBody.str().c_str()); 468 473 469 uint32 itemTextId = this->CreateItemText( msgAuctionSalePendingBody.str() );474 uint32 itemTextId = CreateItemText( msgAuctionSalePendingBody.str() ); 470 475 471 476 WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->owner, msgAuctionSalePendingSubject.str(), itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_AUCTION); … … 499 504 sLog.outDebug("AuctionSuccessful body string : %s", auctionSuccessfulBody.str().c_str()); 500 505 501 uint32 itemTextId = this->CreateItemText( auctionSuccessfulBody.str() );506 uint32 itemTextId = CreateItemText( auctionSuccessfulBody.str() ); 502 507 503 508 uint32 profit = auction->bid + auction->deposit - auctionCut; … … 546 551 // will delete item or place to receiver mail list 547 552 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 549 553 } 550 554 // owner not found … … 564 568 void ObjectMgr::LoadCreatureLocales() 565 569 { 566 mCreatureLocaleMap.clear(); 567 570 mCreatureLocaleMap.clear(); // need for reload case 571 568 572 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"); 569 573 … … 624 628 sLog.outString( ">> Loaded %u creature locale strings", mCreatureLocaleMap.size() ); 625 629 } 626 630 627 631 void ObjectMgr::LoadNpcOptionLocales() 628 632 { … … 693 697 } 694 698 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 695 708 void ObjectMgr::LoadCreatureTemplates() 696 709 { 697 sCreatureStorage.Load(); 710 SQLCreatureLoader loader; 711 loader.Load(sCreatureStorage); 698 712 699 713 sLog.outString( ">> Loaded %u creature definitions", sCreatureStorage.RecordCount ); … … 1513 1527 aItem->location = fields[11].GetUInt8(); 1514 1528 //check if sold item exists 1515 if ( this->GetAItem( aItem->item_guidlow ) )1529 if ( GetAItem( aItem->item_guidlow ) ) 1516 1530 { 1517 1531 GetAuctionsMap( aItem->location )->AddAuction(aItem); … … 1533 1547 void ObjectMgr::LoadItemLocales() 1534 1548 { 1535 mItemLocaleMap.clear(); 1536 1549 mItemLocaleMap.clear(); // need for reload case 1550 1537 1551 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"); 1538 1552 … … 1595 1609 } 1596 1610 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 1597 1620 void ObjectMgr::LoadItemPrototypes() 1598 1621 { 1599 sItemStorage.Load (); 1622 SQLItemLoader loader; 1623 loader.Load(sItemStorage); 1600 1624 sLog.outString( ">> Loaded %u item prototypes", sItemStorage.RecordCount ); 1601 1625 sLog.outString(); … … 2507 2531 if (sWorld.getConfig(CONFIG_EXPANSION) < 1 && (race == RACE_BLOODELF || race == RACE_DRAENEI)) 2508 2532 continue; 2509 2533 2510 2534 // skip expansion classes if not playing with expansion 2511 2535 if (sWorld.getConfig(CONFIG_EXPANSION) < 2 && class_ == CLASS_DEATH_KNIGHT) … … 3556 3580 void ObjectMgr::LoadQuestLocales() 3557 3581 { 3558 mQuestLocaleMap.clear(); 3582 mQuestLocaleMap.clear(); // need for reload case 3559 3583 3560 3584 QueryResult *result = WorldDatabase.Query("SELECT entry," … … 3750 3774 scripts.clear(); // need for reload support 3751 3775 3752 QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,data text, x, y, z, o FROM %s", tablename );3776 QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,dataint, x, y, z, o FROM %s", tablename ); 3753 3777 3754 3778 uint32 count = 0; … … 3772 3796 Field *fields = result->Fetch(); 3773 3797 ScriptInfo tmp; 3774 tmp.id = fields[0].GetUInt32();3775 tmp.delay = fields[1].GetUInt32();3776 tmp.command = fields[2].GetUInt32();3777 tmp.datalong = fields[3].GetUInt32();3798 tmp.id = fields[0].GetUInt32(); 3799 tmp.delay = fields[1].GetUInt32(); 3800 tmp.command = fields[2].GetUInt32(); 3801 tmp.datalong = fields[3].GetUInt32(); 3778 3802 tmp.datalong2 = fields[4].GetUInt32(); 3779 tmp.data text = 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();3803 tmp.dataint = fields[5].GetInt32(); 3804 tmp.x = fields[6].GetFloat(); 3805 tmp.y = fields[7].GetFloat(); 3806 tmp.z = fields[8].GetFloat(); 3807 tmp.o = fields[9].GetFloat(); 3784 3808 3785 3809 // generic command args check … … 3793 3817 continue; 3794 3818 } 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 loading 3795 3831 break; 3796 3832 } … … 4157 4193 void ObjectMgr::LoadPageTextLocales() 4158 4194 { 4159 mPageTextLocaleMap.clear(); 4160 4195 mPageTextLocaleMap.clear(); // need for reload case 4196 4161 4197 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"); 4162 4198 … … 4207 4243 } 4208 4244 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 4209 4254 void ObjectMgr::LoadInstanceTemplate() 4210 4255 { 4211 sInstanceTemplate.Load(); 4256 SQLInstanceLoader loader; 4257 loader.Load(sInstanceTemplate); 4212 4258 4213 4259 for(uint32 i = 0; i < sInstanceTemplate.MaxEntry; i++) … … 4325 4371 void ObjectMgr::LoadNpcTextLocales() 4326 4372 { 4327 mNpcTextLocaleMap.clear(); 4328 4373 mNpcTextLocaleMap.clear(); // need for reload case 4374 4329 4375 QueryResult *result = WorldDatabase.Query("SELECT entry," 4330 4376 "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," … … 4623 4669 4624 4670 uint32 Trigger_ID = fields[0].GetUInt32(); 4625 std::string scriptName = fields[1].GetCppString();4671 const char *scriptName = fields[1].GetString(); 4626 4672 4627 4673 AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); … … 4631 4677 continue; 4632 4678 } 4633 mAreaTriggerScripts[Trigger_ID] = scriptName;4679 mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName); 4634 4680 } while( result->NextRow() ); 4635 4681 … … 4639 4685 sLog.outString( ">> Loaded %u areatrigger scripts", count ); 4640 4686 } 4687 4641 4688 uint32 ObjectMgr::GetNearestTaxiNode( float x, float y, float z, uint32 mapid ) 4642 4689 { … … 4697 4744 uint16 ObjectMgr::GetTaxiMount( uint32 id, uint32 team ) 4698 4745 { 4699 uint 32mount_entry = 0;4700 uint 32mount_id = 0;4746 uint16 mount_entry = 0; 4747 uint16 mount_id = 0; 4701 4748 4702 4749 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(id); 4703 if 4750 if(node) 4704 4751 { 4705 4752 if (team == ALLIANCE) mount_entry = node->alliance_mount_type; … … 4940 4987 } 4941 4988 4942 // find now nearest graveyard at same map4943 4989 if(entryNear) 4944 4990 return entryNear; … … 5181 5227 { 5182 5228 m_hiCharGuid = (*result)[0].GetUInt32()+1; 5183 5184 5229 delete result; 5185 5230 } … … 5189 5234 { 5190 5235 m_hiCreatureGuid = (*result)[0].GetUInt32()+1; 5191 5192 5236 delete result; 5193 5237 } 5194 5238 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 } 5239 // pet guids are not saved to DB, set to 0 (pet guid != pet id) 5240 m_hiPetGuid = 0; 5202 5241 5203 5242 result = CharacterDatabase.Query( "SELECT MAX(guid) FROM item_instance" ); … … 5205 5244 { 5206 5245 m_hiItemGuid = (*result)[0].GetUInt32()+1; 5207 5208 5246 delete result; 5209 5247 } … … 5219 5257 { 5220 5258 m_hiGoGuid = (*result)[0].GetUInt32()+1; 5221 5222 5259 delete result; 5223 5260 } … … 5227 5264 { 5228 5265 m_auctionid = (*result)[0].GetUInt32()+1; 5229 5230 5266 delete result; 5231 5267 } 5232 else 5233 { 5234 m_auctionid = 0; 5235 } 5268 5236 5269 result = CharacterDatabase.Query( "SELECT MAX(id) FROM mail" ); 5237 5270 if( result ) 5238 5271 { 5239 5272 m_mailid = (*result)[0].GetUInt32()+1; 5240 5241 5273 delete result; 5242 5274 } 5243 else 5244 { 5245 m_mailid = 0; 5246 } 5275 5247 5276 result = CharacterDatabase.Query( "SELECT MAX(id) FROM item_text" ); 5248 5277 if( result ) 5249 5278 { 5250 m_ItemTextId = (*result)[0].GetUInt32(); 5251 5279 m_ItemTextId = (*result)[0].GetUInt32()+1; 5252 5280 delete result; 5253 5281 } 5254 else5255 m_ItemTextId = 0;5256 5282 5257 5283 result = CharacterDatabase.Query( "SELECT MAX(guid) FROM corpse" ); … … 5259 5285 { 5260 5286 m_hiCorpseGuid = (*result)[0].GetUInt32()+1; 5261 5262 5287 delete result; 5263 5288 } 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++; 5264 5323 } 5265 5324 5266 5325 uint32 ObjectMgr::GenerateAuctionID() 5267 5326 { 5268 ++m_auctionid; 5269 if(m_auctionid>=0xFFFFFFFF) 5327 if(m_auctionid>=0xFFFFFFFE) 5270 5328 { 5271 5329 sLog.outError("Auctions ids overflow!! Can't continue, shutting down server. "); 5272 sWorld.m_stopEvent = true;5273 } 5274 return m_auctionid ;5330 World::StopNow(ERROR_EXIT_CODE); 5331 } 5332 return m_auctionid++; 5275 5333 } 5276 5334 5277 5335 uint32 ObjectMgr::GenerateMailID() 5278 5336 { 5279 ++m_mailid; 5280 if(m_mailid>=0xFFFFFFFF) 5337 if(m_mailid>=0xFFFFFFFE) 5281 5338 { 5282 5339 sLog.outError("Mail ids overflow!! Can't continue, shutting down server. "); 5283 sWorld.m_stopEvent = true;5284 } 5285 return m_mailid ;5340 World::StopNow(ERROR_EXIT_CODE); 5341 } 5342 return m_mailid++; 5286 5343 } 5287 5344 5288 5345 uint32 ObjectMgr::GenerateItemTextID() 5289 5346 { 5290 ++m_ItemTextId; 5291 if(m_ItemTextId>=0xFFFFFFFF) 5347 if(m_ItemTextId>=0xFFFFFFFE) 5292 5348 { 5293 5349 sLog.outError("Item text ids overflow!! Can't continue, shutting down server. "); 5294 sWorld.m_stopEvent = true;5295 } 5296 return m_ItemTextId ;5350 World::StopNow(ERROR_EXIT_CODE); 5351 } 5352 return m_ItemTextId++; 5297 5353 } 5298 5354 … … 5316 5372 { 5317 5373 case HIGHGUID_ITEM: 5318 ++m_hiItemGuid; 5319 if(m_hiItemGuid>=0xFFFFFFFF) 5374 if(m_hiItemGuid>=0xFFFFFFFE) 5320 5375 { 5321 5376 sLog.outError("Item guid overflow!! Can't continue, shutting down server. "); 5322 sWorld.m_stopEvent = true;5323 } 5324 return m_hiItemGuid ;5377 World::StopNow(ERROR_EXIT_CODE); 5378 } 5379 return m_hiItemGuid++; 5325 5380 case HIGHGUID_UNIT: 5326 ++m_hiCreatureGuid; 5327 if(m_hiCreatureGuid>=0x00FFFFFF) 5381 if(m_hiCreatureGuid>=0x00FFFFFE) 5328 5382 { 5329 5383 sLog.outError("Creature guid overflow!! Can't continue, shutting down server. "); 5330 sWorld.m_stopEvent = true;5331 } 5332 return m_hiCreatureGuid ;5384 World::StopNow(ERROR_EXIT_CODE); 5385 } 5386 return m_hiCreatureGuid++; 5333 5387 case HIGHGUID_PET: 5334 ++m_hiPetGuid; 5335 if(m_hiPetGuid>=0x00FFFFFF) 5388 if(m_hiPetGuid>=0x00FFFFFE) 5336 5389 { 5337 5390 sLog.outError("Pet guid overflow!! Can't continue, shutting down server. "); 5338 sWorld.m_stopEvent = true;5339 } 5340 return m_hiPetGuid ;5391 World::StopNow(ERROR_EXIT_CODE); 5392 } 5393 return m_hiPetGuid++; 5341 5394 case HIGHGUID_PLAYER: 5342 ++m_hiCharGuid; 5343 if(m_hiCharGuid>=0xFFFFFFFF) 5395 if(m_hiCharGuid>=0xFFFFFFFE) 5344 5396 { 5345 5397 sLog.outError("Players guid overflow!! Can't continue, shutting down server. "); 5346 sWorld.m_stopEvent = true;5347 } 5348 return m_hiCharGuid ;5398 World::StopNow(ERROR_EXIT_CODE); 5399 } 5400 return m_hiCharGuid++; 5349 5401 case HIGHGUID_GAMEOBJECT: 5350 ++m_hiGoGuid; 5351 if(m_hiGoGuid>=0x00FFFFFF) 5402 if(m_hiGoGuid>=0x00FFFFFE) 5352 5403 { 5353 5404 sLog.outError("Gameobject guid overflow!! Can't continue, shutting down server. "); 5354 sWorld.m_stopEvent = true;5355 } 5356 return m_hiGoGuid ;5405 World::StopNow(ERROR_EXIT_CODE); 5406 } 5407 return m_hiGoGuid++; 5357 5408 case HIGHGUID_CORPSE: 5358 ++m_hiCorpseGuid; 5359 if(m_hiCorpseGuid>=0xFFFFFFFF) 5409 if(m_hiCorpseGuid>=0xFFFFFFFE) 5360 5410 { 5361 5411 sLog.outError("Corpse guid overflow!! Can't continue, shutting down server. "); 5362 sWorld.m_stopEvent = true;5363 } 5364 return m_hiCorpseGuid ;5412 World::StopNow(ERROR_EXIT_CODE); 5413 } 5414 return m_hiCorpseGuid++; 5365 5415 case HIGHGUID_DYNAMICOBJECT: 5366 ++m_hiDoGuid; 5367 if(m_hiDoGuid>=0xFFFFFFFF) 5416 if(m_hiDoGuid>=0xFFFFFFFE) 5368 5417 { 5369 5418 sLog.outError("DynamicObject guid overflow!! Can't continue, shutting down server. "); 5370 sWorld.m_stopEvent = true;5371 } 5372 return m_hiDoGuid ;5419 World::StopNow(ERROR_EXIT_CODE); 5420 } 5421 return m_hiDoGuid++; 5373 5422 default: 5374 5423 ASSERT(0); … … 5381 5430 void ObjectMgr::LoadGameObjectLocales() 5382 5431 { 5383 mGameObjectLocaleMap.clear(); 5384 5432 mGameObjectLocaleMap.clear(); // need for reload case 5433 5385 5434 QueryResult *result = WorldDatabase.Query("SELECT entry," 5386 5435 "name_loc1,name_loc2,name_loc3,name_loc4,name_loc5,name_loc6,name_loc7,name_loc8," … … 5450 5499 } 5451 5500 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 5452 5510 void ObjectMgr::LoadGameobjectInfo() 5453 5511 { 5454 sGOStorage.Load(); 5512 SQLGameObjectLoader loader; 5513 loader.Load(sGOStorage); 5455 5514 5456 5515 // some checks … … 6625 6684 } 6626 6685 6627 const char* ObjectMgr::GetAreaTriggerScriptName(uint32id)6628 { 6629 AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find( id);6686 uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id) 6687 { 6688 AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(trigger_id); 6630 6689 if(i!= mAreaTriggerScripts.end()) 6631 return i->second .c_str();6632 return "";6690 return i->second; 6691 return 0; 6633 6692 } 6634 6693 … … 6675 6734 return false; 6676 6735 } 6677 6678 6679 6680 6736 case CONDITION_NO_AURA: 6737 return !player->HasAura(value1, value2); 6738 case CONDITION_ACTIVE_EVENT: 6739 return gameeventmgr.IsActiveEvent(value1); 6681 6740 default: 6682 6741 return false; … … 6799 6858 break; 6800 6859 } 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6860 case CONDITION_NO_AURA: 6861 { 6862 if(!sSpellStore.LookupEntry(value1)) 6863 { 6864 sLog.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1); 6865 return false; 6866 } 6867 if(value2 > 2) 6868 { 6869 sLog.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2); 6870 return false; 6871 } 6872 break; 6873 } 6874 case CONDITION_ACTIVE_EVENT: 6875 { 6876 GameEvent::GameEventDataMap const& events = gameeventmgr.GetEventMap(); 6877 if(value1 >=events.size() || !events[value1].isValid()) 6878 { 6879 sLog.outErrorDb("Active event condition requires existed event id (%u), skipped", value1); 6880 return false; 6881 } 6882 break; 6883 } 6825 6884 } 6826 6885 return true; … … 6952 7011 if(itr->first > new_id) 6953 7012 new_id = itr->first; 6954 7013 6955 7014 // use next 6956 7015 ++new_id; … … 6992 7051 void ObjectMgr::LoadTrainerSpell() 6993 7052 { 6994 // For reload case 7053 // For reload case 6995 7054 for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr) 6996 7055 itr->second.Clear(); … … 7083 7142 void ObjectMgr::LoadVendors() 7084 7143 { 7085 // For reload case 7144 // For reload case 7086 7145 for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr) 7087 7146 itr->second.Clear(); … … 7190 7249 "SELECT id,gossip_id,npcflag,icon,action,box_money,coded,option_text,box_text " 7191 7250 "FROM npc_option"); 7251 7192 7252 if( !result ) 7193 7253 { … … 7342 7402 } 7343 7403 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 do 7420 { 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 vector 7432 // assume "" is the first element 7433 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 7344 7478 // Functions for scripting access 7345 const char* GetAreaTriggerScriptNameById(uint32id)7346 { 7347 return objmgr.GetAreaTriggerScript Name(id);7479 uint32 GetAreaTriggerScriptId(uint32 trigger_id) 7480 { 7481 return objmgr.GetAreaTriggerScriptId(trigger_id); 7348 7482 } 7349 7483 … … 7360 7494 return objmgr.LoadTrinityStrings(db,table,end_value,start_value); 7361 7495 } 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 }