2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "Database/SQLStorage.h"
24 #include "ObjectMgr.h"
25 #include "UpdateMask.h"
27 #include "WorldSession.h"
30 #include "ProgressBar.cpp"
31 #include "Policies/SingletonImp.h"
33 INSTANTIATE_SINGLETON_1(ObjectMgr
);
35 extern SQLStorage sItemStorage
;
36 extern SQLStorage sGOStorage
;
37 extern SQLStorage sCreatureStorage
;
39 ObjectMgr::ObjectMgr()
50 ObjectMgr::~ObjectMgr()
55 for( QuestMap::iterator i
= mQuests
.begin( ); i
!= mQuests
.end( ); ++ i
)
62 for( GossipTextMap::iterator i
= mGossipText
.begin( ); i
!= mGossipText
.end( ); ++ i
)
68 for( AreaTriggerMap::iterator i
= mAreaTriggerMap
.begin( ); i
!= mAreaTriggerMap
.end( ); ++ i
)
72 mAreaTriggerMap
.clear( );
83 Group
* ObjectMgr::GetGroupByLeader(const uint64
&guid
) const
85 GroupSet::const_iterator itr
;
86 for (itr
= mGroupSet
.begin(); itr
!= mGroupSet
.end(); itr
++)
88 if ((*itr
)->GetLeaderGUID() == guid
)
100 Guild
* ObjectMgr::GetGuildById(const uint32 GuildId
) const
102 GuildSet::const_iterator itr
;
103 for (itr
= mGuildSet
.begin(); itr
!= mGuildSet
.end(); itr
++)
105 if ((*itr
)->GetId() == GuildId
)
117 CreatureInfo
*ObjectMgr::GetCreatureTemplate(uint32 id
)
119 return (sCreatureStorage
.iNumRecords
<=id
)?NULL
:(CreatureInfo
*)sCreatureStorage
.pIndex
[id
];
127 void ObjectMgr::LoadCreatureTemplates()
130 sCreatureStorage
.Load();
132 sLog
.outString( "" );
133 // sLog.outString( ">> Loaded %d creature definitions", count );
134 // sLog.outString( "" );
137 PlayerCreateInfo
* ObjectMgr::GetPlayerCreateInfo(uint32 race
, uint32 class_
)
141 Field
*player_fields
, *items_fields
, *spells_fields
, *skills_fields
, *actions_fields
;
142 PlayerCreateInfo
*pPlayerCreateInfo
;
144 QueryResult
*player_result
= sDatabase
.PQuery("SELECT * FROM playercreateinfo WHERE race = '%u' AND class = '%u';", race
, class_
);
149 pPlayerCreateInfo
= new PlayerCreateInfo
;
151 player_fields
= player_result
->Fetch();
153 pPlayerCreateInfo
->createId
= player_fields
[0].GetUInt8();
154 createId
= (uint32
)pPlayerCreateInfo
->createId
;
155 pPlayerCreateInfo
->race
= player_fields
[1].GetUInt8();
156 pPlayerCreateInfo
->class_
= player_fields
[2].GetUInt8();
157 pPlayerCreateInfo
->mapId
= player_fields
[3].GetUInt32();
158 pPlayerCreateInfo
->zoneId
= player_fields
[4].GetUInt32();
159 pPlayerCreateInfo
->positionX
= player_fields
[5].GetFloat();
160 pPlayerCreateInfo
->positionY
= player_fields
[6].GetFloat();
161 pPlayerCreateInfo
->positionZ
= player_fields
[7].GetFloat();
162 pPlayerCreateInfo
->displayId
= player_fields
[8].GetUInt16();
163 pPlayerCreateInfo
->strength
= player_fields
[9].GetUInt8();
164 pPlayerCreateInfo
->ability
= player_fields
[10].GetUInt8();
165 pPlayerCreateInfo
->stamina
= player_fields
[11].GetUInt8();
166 pPlayerCreateInfo
->intellect
= player_fields
[12].GetUInt8();
167 pPlayerCreateInfo
->spirit
= player_fields
[13].GetUInt8();
168 pPlayerCreateInfo
->basearmor
= player_fields
[14].GetUInt32();
169 pPlayerCreateInfo
->health
= player_fields
[15].GetUInt32();
170 pPlayerCreateInfo
->mana
= player_fields
[16].GetUInt32();
171 pPlayerCreateInfo
->rage
= player_fields
[17].GetUInt32();
172 pPlayerCreateInfo
->focus
= player_fields
[18].GetUInt32();
173 pPlayerCreateInfo
->energy
= player_fields
[19].GetUInt32();
174 pPlayerCreateInfo
->attackpower
= player_fields
[20].GetUInt32();
175 pPlayerCreateInfo
->mindmg
= player_fields
[21].GetFloat();
176 pPlayerCreateInfo
->maxdmg
= player_fields
[22].GetFloat();
177 pPlayerCreateInfo
->ranmindmg
= player_fields
[23].GetFloat();
178 pPlayerCreateInfo
->ranmaxdmg
= player_fields
[24].GetFloat();
180 delete player_result
;
182 QueryResult
*items_result
= sDatabase
.PQuery("SELECT * FROM playercreateinfo_items WHERE createId = '0' OR createId = '%u';", createId
);
185 if(!items_result
) break;
186 items_fields
= items_result
->Fetch();
187 pPlayerCreateInfo
->item_id
.push_back(items_fields
[1].GetUInt32());
188 pPlayerCreateInfo
->item_bagIndex
.push_back(items_fields
[2].GetUInt32());
189 pPlayerCreateInfo
->item_slot
.push_back(items_fields
[3].GetUInt8());
190 pPlayerCreateInfo
->item_amount
.push_back(items_fields
[4].GetUInt32());
191 } while (items_result
->NextRow());
195 QueryResult
*spells_result
= sDatabase
.PQuery("SELECT * FROM playercreateinfo_spells WHERE createId = '0' OR createId = '%u';", createId
);
199 if(!spells_result
) break;
200 spells_fields
= spells_result
->Fetch();
201 pPlayerCreateInfo
->spell
.push_back(spells_fields
[1].GetUInt16());
203 } while( spells_result
->NextRow() );
205 delete spells_result
;
207 QueryResult
*skills_result
= sDatabase
.PQuery("SELECT * FROM playercreateinfo_skills WHERE createId = '0' OR createId = '%u';", createId
);
211 if(!skills_result
) break;
212 skills_fields
= skills_result
->Fetch();
213 pPlayerCreateInfo
->skill
[0].push_back(skills_fields
[1].GetUInt16());
214 pPlayerCreateInfo
->skill
[1].push_back(skills_fields
[2].GetUInt16());
215 pPlayerCreateInfo
->skill
[2].push_back(skills_fields
[3].GetUInt16());
217 } while( skills_result
->NextRow() );
219 delete skills_result
;
221 QueryResult
*actions_result
= sDatabase
.PQuery("SELECT * FROM playercreateinfo_actions WHERE createId = '0' OR createId = '%u';", createId
);
225 if(!actions_result
) break;
226 actions_fields
= actions_result
->Fetch();
227 pPlayerCreateInfo
->action
[0].push_back(actions_fields
[1].GetUInt16());
228 pPlayerCreateInfo
->action
[1].push_back(actions_fields
[2].GetUInt16());
229 pPlayerCreateInfo
->action
[2].push_back(actions_fields
[3].GetUInt16());
230 pPlayerCreateInfo
->action
[3].push_back(actions_fields
[4].GetUInt16());
232 } while( actions_result
->NextRow() );
234 delete actions_result
;
236 return pPlayerCreateInfo
;
239 uint64
ObjectMgr::GetPlayerGUIDByName(const char *name
) const
244 QueryResult
*result
= sDatabase
.PQuery("SELECT guid FROM characters WHERE name = '%s';", name
);
248 guid
= (*result
)[0].GetUInt32();
257 bool ObjectMgr::GetPlayerNameByGUID(const uint64
&guid
, std::string
&name
) const
260 QueryResult
*result
= sDatabase
.PQuery("SELECT name FROM characters WHERE guid = '%d';", GUID_LOPART(guid
));
264 name
= (*result
)[0].GetString();
273 void ObjectMgr::LoadAuctions()
275 QueryResult
*result
= sDatabase
.PQuery( "SELECT * FROM auctionhouse;" );
284 Field
*fields
= result
->Fetch();
286 aItem
= new AuctionEntry
;
287 aItem
->auctioneer
= fields
[0].GetUInt32();
288 aItem
->item
= fields
[1].GetUInt32();
289 aItem
->owner
= fields
[2].GetUInt32();
290 aItem
->buyout
= fields
[3].GetUInt32();
291 aItem
->time
= fields
[4].GetUInt32();
292 aItem
->bidder
= fields
[5].GetUInt32();
293 aItem
->bid
= fields
[6].GetUInt32();
294 aItem
->Id
= fields
[7].GetUInt32();
296 } while (result
->NextRow());
303 void ObjectMgr::LoadItemPrototypes()
305 sItemStorage
.Load ();
306 sLog
.outString( ">> Loaded %u item prototypes", sItemStorage
.iNumRecords
);
309 void ObjectMgr::LoadAuctionItems()
311 QueryResult
*result
= sDatabase
.PQuery( "SELECT * FROM auctioned_items;" );
318 fields
= result
->Fetch();
319 Item
* item
= new Item
;
320 item
->LoadFromDB(fields
[0].GetUInt32(), 2);
323 while( result
->NextRow() );
329 void ObjectMgr::LoadMailedItems()
331 QueryResult
*result
= sDatabase
.PQuery( "SELECT * FROM mailed_items;" );
338 fields
= result
->Fetch();
339 Item
* item
= new Item
;
340 item
->LoadFromDB(fields
[0].GetUInt32(), 3);
343 while( result
->NextRow() );
348 void ObjectMgr::LoadGuilds()
351 QueryResult
*result
= sDatabase
.PQuery( "SELECT guildId FROM guilds;" );
361 sLog
.outString( "" );
362 sLog
.outString( ">> Loaded %d guild definitions", count
);
367 barGoLink
bar( result
->GetRowCount() );
371 Field
*fields
= result
->Fetch();
377 newguild
= new Guild
;
378 newguild
->LoadGuildFromDB(fields
[0].GetUInt32());
381 }while( result
->NextRow() );
383 sLog
.outString( "" );
384 sLog
.outString( ">> Loaded %d guild definitions", count
);
387 void ObjectMgr::LoadQuests()
389 QueryResult
*result
= sDatabase
.PQuery( "SELECT * FROM quests;" );
391 if( !result
) return;
394 barGoLink
bar( result
->GetRowCount() );
402 Field
*fields
= result
->Fetch();
410 pQuest
->m_qId
= fields
[ iCalc
++ ].GetUInt32();
411 pQuest
->m_qCategory
= fields
[ iCalc
++ ].GetUInt32();
412 pQuest
->m_qFlags
= fields
[ iCalc
++ ].GetUInt32();
414 pQuest
->m_qTitle
= fields
[ iCalc
++ ].GetString();
415 pQuest
->m_qDetails
= fields
[ iCalc
++ ].GetString();
416 pQuest
->m_qObjectives
= fields
[ iCalc
++ ].GetString();
418 pQuest
->m_qCompletionInfo
= fields
[ iCalc
++ ].GetString();
419 pQuest
->m_qIncompleteInfo
= fields
[ iCalc
++ ].GetString();
420 pQuest
->m_qEndInfo
= fields
[ iCalc
++ ].GetString();
422 for (CiC
= 0; CiC
< QUEST_OBJECTIVES_COUNT
; CiC
++)
423 pQuest
->m_qObjectiveInfo
[CiC
] = fields
[ iCalc
++ ].GetString();
425 pQuest
->m_qPlayerLevel
= fields
[ iCalc
++ ].GetUInt32();
426 pQuest
->m_qComplexityLevel
= fields
[ iCalc
++ ].GetUInt32();
428 pQuest
->m_qRequiredQuestsCount
= fields
[ iCalc
++ ].GetUInt32();
429 for ( CiC
= 0; CiC
< QUEST_DEPLINK_COUNT
; CiC
++)
430 { pQuest
->m_qRequiredQuests
[CiC
] = fields
[ iCalc
++ ].GetUInt32(); }
432 pQuest
->m_qRequiredAbsQuestsCount
= fields
[ iCalc
++ ].GetUInt32();
433 for ( CiC
= 0; CiC
< QUEST_DEPLINK_COUNT
; CiC
++)
434 { pQuest
->m_qRequiredAbsQuests
[CiC
] = fields
[ iCalc
++ ].GetUInt32(); }
436 pQuest
->m_qLockerQuestsCount
= fields
[ iCalc
++ ].GetUInt32();
437 for ( CiC
= 0; CiC
< QUEST_DEPLINK_COUNT
; CiC
++)
438 { pQuest
->m_qLockerQuests
[CiC
] = fields
[ iCalc
++ ].GetUInt32(); }
440 for (CiC
= 0; CiC
< QUEST_OBJECTIVES_COUNT
; CiC
++)
441 pQuest
->m_qObjItemId
[CiC
] = fields
[ iCalc
++ ].GetUInt32();
443 for (CiC
= 0; CiC
< QUEST_OBJECTIVES_COUNT
; CiC
++)
444 pQuest
->m_qObjItemCount
[CiC
] = fields
[ iCalc
++ ].GetUInt32();
446 for (CiC
= 0; CiC
< QUEST_OBJECTIVES_COUNT
; CiC
++)
447 pQuest
->m_qObjMobId
[CiC
] = fields
[ iCalc
++ ].GetUInt32();
449 for (CiC
= 0; CiC
< QUEST_OBJECTIVES_COUNT
; CiC
++)
450 pQuest
->m_qObjMobCount
[CiC
] = fields
[ iCalc
++ ].GetUInt32();
453 pQuest
->m_qRewChoicesCount
= fields
[ iCalc
++ ].GetUInt32();
454 for ( CiC
= 0; CiC
< QUEST_REWARD_CHOICES_COUNT
; CiC
++)
455 { pQuest
->m_qRewChoicesItemId
[CiC
] = fields
[ iCalc
++ ].GetUInt32(); }
457 for ( CiC
= 0; CiC
< QUEST_REWARD_CHOICES_COUNT
; CiC
++)
458 { pQuest
->m_qRewChoicesItemCount
[CiC
] = fields
[ iCalc
++ ].GetUInt32(); }
460 pQuest
->m_qRewCount
= fields
[ iCalc
++ ].GetUInt32();
461 for ( CiC
= 0; CiC
< QUEST_REWARDS_COUNT
; CiC
++)
462 { pQuest
->m_qRewItemId
[CiC
] = fields
[ iCalc
++ ].GetUInt32(); }
464 for ( CiC
= 0; CiC
< QUEST_REWARDS_COUNT
; CiC
++)
465 { pQuest
->m_qRewItemCount
[CiC
] = fields
[ iCalc
++ ].GetUInt32(); }
468 pQuest
->m_qRewMoney
= fields
[ iCalc
++ ].GetUInt32();
469 pQuest
->m_qObjRepFaction_1
= fields
[ iCalc
++ ].GetUInt32();
470 pQuest
->m_qObjRepFaction_2
= fields
[ iCalc
++ ].GetUInt32();
471 pQuest
->m_qObjRepValue_1
= fields
[ iCalc
++ ].GetUInt32();
472 pQuest
->m_qObjRepValue_2
= fields
[ iCalc
++ ].GetUInt32();
474 pQuest
->m_qQuestItem
= fields
[ iCalc
++ ].GetUInt32();
475 pQuest
->m_qNextQuestId
= fields
[ iCalc
++ ].GetUInt32();
476 pQuest
->m_qRewSpell
= fields
[ iCalc
++ ].GetUInt32();
477 pQuest
->m_qObjTime
= fields
[ iCalc
++ ].GetUInt32();
479 pQuest
->m_qType
= fields
[ iCalc
++ ].GetUInt32();
480 pQuest
->m_qRequiredRaces
= fields
[ iCalc
++ ].GetUInt32();
481 pQuest
->m_qRequiredClass
= fields
[ iCalc
++ ].GetUInt32();
482 pQuest
->m_qRequiredTradeskill
= fields
[ iCalc
++ ].GetUInt32();
483 pQuest
->m_qSpecialFlags
= fields
[ iCalc
++ ].GetUInt32();
485 pQuest
->m_qPointId
= fields
[ iCalc
++ ].GetUInt32();
486 pQuest
->m_qPointX
= fields
[ iCalc
++ ].GetFloat();
487 pQuest
->m_qPointY
= fields
[ iCalc
++ ].GetFloat();
488 pQuest
->m_qPointOpt
= fields
[ iCalc
++ ].GetUInt32();
493 while( result
->NextRow() );
497 // points all quests for their next quest
498 for( QuestMap::iterator i
= mQuests
.begin( ); i
!= mQuests
.end( ); i
++ )
500 i
->second
->m_qNextQuest
= objmgr
.GetQuest( i
->second
->m_qNextQuestId
);
504 sLog
.outString( "" );
505 sLog
.outString( ">> Loaded %d quest definitions", count
);
510 void ObjectMgr::AddGossipText(GossipText
*pGText
)
512 ASSERT( pGText
->Text_ID
);
513 ASSERT( mGossipText
.find(pGText
->Text_ID
) == mGossipText
.end() );
514 mGossipText
[pGText
->Text_ID
] = pGText
;
518 GossipText
*ObjectMgr::GetGossipText(uint32 Text_ID
)
520 GossipTextMap::const_iterator itr
;
521 for (itr
= mGossipText
.begin(); itr
!= mGossipText
.end(); itr
++)
523 if(itr
->second
->Text_ID
== Text_ID
)
530 void ObjectMgr::LoadGossipText()
533 QueryResult
*result
= sDatabase
.PQuery( "SELECT * FROM npc_text;" );
536 if( !result
) return;
540 barGoLink
bar( result
->GetRowCount() );
546 Field
*fields
= result
->Fetch();
551 pGText
= new GossipText
;
552 pGText
->Text_ID
= fields
[cic
++].GetUInt32();
554 for (int i
=0; i
< 8; i
++)
556 pGText
->Options
[i
].Text_0
= fields
[cic
++].GetString();
557 pGText
->Options
[i
].Text_1
= fields
[cic
++].GetString();
559 pGText
->Options
[i
].Language
= fields
[cic
++].GetUInt32();
560 pGText
->Options
[i
].Probability
= fields
[cic
++].GetFloat();
562 pGText
->Options
[i
].Emotes
[0]._Delay
= fields
[cic
++].GetUInt32();
563 pGText
->Options
[i
].Emotes
[0]._Emote
= fields
[cic
++].GetUInt32();
565 pGText
->Options
[i
].Emotes
[1]._Delay
= fields
[cic
++].GetUInt32();
566 pGText
->Options
[i
].Emotes
[1]._Emote
= fields
[cic
++].GetUInt32();
568 pGText
->Options
[i
].Emotes
[2]._Delay
= fields
[cic
++].GetUInt32();
569 pGText
->Options
[i
].Emotes
[2]._Emote
= fields
[cic
++].GetUInt32();
572 if ( !pGText
->Text_ID
) continue;
573 AddGossipText( pGText
);
575 } while( result
->NextRow() );
577 sLog
.outString( "" );
578 sLog
.outString( ">> Loaded %d npc texts", count
);
583 ItemPage
*ObjectMgr::RetreiveItemPageText(uint32 Page_ID
)
586 QueryResult
*result
= sDatabase
.PQuery("SELECT * FROM item_pages WHERE ID = '%d';", Page_ID
);
588 if( !result
) return NULL
;
590 pIText
= new ItemPage
;
596 Field
*fields
= result
->Fetch();
599 pIText
->Page_ID
= fields
[cic
++].GetUInt32();
601 pIText
->PageText
= fields
[cic
++].GetString();
602 pIText
->Next_Page
= fields
[cic
++].GetUInt32();
604 if ( !pIText
->Page_ID
) break;
605 } while( result
->NextRow() );
612 void ObjectMgr::AddAreaTriggerPoint(AreaTriggerPoint
*pArea
)
614 ASSERT( pArea
->Trigger_ID
);
615 ASSERT( mAreaTriggerMap
.find(pArea
->Trigger_ID
) == mAreaTriggerMap
.end() );
617 mAreaTriggerMap
[pArea
->Trigger_ID
] = pArea
;
621 AreaTriggerPoint
*ObjectMgr::GetAreaTriggerQuestPoint(uint32 Trigger_ID
)
623 AreaTriggerMap::const_iterator itr
;
624 for (itr
= mAreaTriggerMap
.begin(); itr
!= mAreaTriggerMap
.end(); itr
++)
626 if(itr
->second
->Trigger_ID
== Trigger_ID
)
633 void ObjectMgr::LoadAreaTriggerPoints()
636 QueryResult
*result
= sDatabase
.PQuery( "SELECT * FROM triggerquestrelation;" );
637 AreaTriggerPoint
*pArea
;
639 if( !result
) return;
642 barGoLink
bar( result
->GetRowCount() );
650 pArea
= new AreaTriggerPoint
;
652 Field
*fields
= result
->Fetch();
656 pArea
->Trigger_ID
= fields
[0].GetUInt32();
657 pArea
->Quest_ID
= fields
[1].GetUInt32();
658 pArea
->Creature_ID
= fields
[2].GetUInt32();
660 AddAreaTriggerPoint( pArea
);
662 } while( result
->NextRow() );
664 sLog
.outString( "" );
665 sLog
.outString( ">> Loaded %d quest trigger points", count
);
671 bool ObjectMgr::GetGlobalTaxiNodeMask( uint32 curloc
, uint32
*Mask
)
674 QueryResult
*result
= sDatabase
.PQuery("SELECT taxipath.destination FROM taxipath WHERE taxipath.source = '%d' ORDER BY destination LIMIT 1;", curloc
);
680 Field
*fields
= result
->Fetch();
681 uint8 destination
= fields
[0].GetUInt8();
682 uint8 field
= (uint8
)((destination
- 1) / 32);
683 Mask
[field
] |= 1 << ( (destination
- 1 ) % 32 );
689 uint32
ObjectMgr::GetNearestTaxiNode( float x
, float y
, float z
, uint32 mapid
)
692 QueryResult
*result
= sDatabase
.PQuery("SELECT taxinodes.ID, SQRT(pow(taxinodes.x-'%f',2)+pow(taxinodes.y-'%f',2)+pow(taxinodes.z-'%f',2)) as distance FROM taxinodes WHERE taxinodes.continent = '%u' ORDER BY distance LIMIT 1;", x
, y
, z
, mapid
);
698 Field
*fields
= result
->Fetch();
699 return fields
[0].GetUInt8();
705 void ObjectMgr::GetTaxiPath( uint32 source
, uint32 destination
, uint32
&path
, uint32
&cost
)
708 QueryResult
*result
= sDatabase
.PQuery("SELECT taxipath.price, taxipath.ID FROM taxipath WHERE taxipath.source = '%u' AND taxipath.destination = '%u';", source
, destination
);
716 Field
*fields
= result
->Fetch();
717 cost
= fields
[0].GetUInt32();
718 path
= fields
[1].GetUInt16();
722 uint16
ObjectMgr::GetTaxiMount( uint32 id
)
725 QueryResult
*result
= sDatabase
.PQuery("SELECT taxinodes.mount FROM taxinodes WHERE taxinodes.ID = '%u';", id
);
732 Field
*fields
= result
->Fetch();
733 return fields
[0].GetUInt16();
739 void ObjectMgr::GetTaxiPathNodes( uint32 path
, Path
&pathnodes
)
742 QueryResult
*result
= sDatabase
.PQuery("SELECT taxipathnodes.X, taxipathnodes.Y, taxipathnodes.Z FROM taxipathnodes WHERE taxipathnodes.path = '%u';", path
);
747 uint16 count
= result
->GetRowCount();
748 sLog
.outDebug(" ROW COUNT %u ",count
);
749 pathnodes
.Resize( count
);
754 Field
*fields
= result
->Fetch();
755 pathnodes
[ i
].x
= fields
[0].GetFloat();
756 pathnodes
[ i
].y
= fields
[1].GetFloat();
757 pathnodes
[ i
].z
= fields
[2].GetFloat();
759 } while( result
->NextRow() );
763 GraveyardTeleport
*ObjectMgr::GetClosestGraveYard(float x
, float y
, float z
, uint32 MapId
)
766 QueryResult
*result
= sDatabase
.PQuery("SELECT SQRT(POW('%f'-X,2)+POW('%f'-Y,2)+POW('%f'-Z,2)) as distance,X,Y,Z,mapId from graveyards where mapId = '%d' ORDER BY distance ASC LIMIT 1;", x
, y
, z
, MapId
);
771 Field
*fields
= result
->Fetch();
772 GraveyardTeleport
*pgrave
= new GraveyardTeleport
;
774 pgrave
->X
= fields
[1].GetFloat();
775 pgrave
->Y
= fields
[2].GetFloat();
776 pgrave
->Z
= fields
[3].GetFloat();
777 pgrave
->MapId
= fields
[4].GetUInt32();
782 AreaTrigger
*ObjectMgr::GetAreaTrigger(uint32 Trigger_ID
)
785 QueryResult
*result
= sDatabase
.PQuery("SELECT triggerID FROM areatrigger WHERE triggerID = '%d';", Trigger_ID
);
789 Field
*fields
= result
->Fetch();
790 uint32 totrigger
= fields
[0].GetUInt32();
794 QueryResult
*result1
= sDatabase
.PQuery("SELECT TargetMapID,TargetPosX,TargetPosY,TargetPosZ FROM areatrigger WHERE triggerID = '%d';", totrigger
);
797 Field
*fields1
= result1
->Fetch();
798 AreaTrigger
*at
= new AreaTrigger
;
800 at
->mapId
= fields1
[0].GetUInt32();
802 at
->X
= fields1
[1].GetFloat();
803 at
->Y
= fields1
[2].GetFloat();
804 at
->Z
= fields1
[3].GetFloat();
813 void ObjectMgr::LoadTeleportCoords()
816 QueryResult
*result
= sDatabase
.PQuery( "SELECT * FROM areatrigger;" );
826 barGoLink
bar( result
->GetRowCount() );
830 Field
*fields
= result
->Fetch();
836 pTC
= new TeleportCoords
;
837 pTC
->id
= fields
[0].GetUInt32();
838 //pTC->Name = fields[6].GetString();
839 pTC
->mapId
= fields
[5].GetUInt32();
840 pTC
->x
= fields
[1].GetFloat();
841 pTC
->y
= fields
[2].GetFloat();
842 pTC
->z
= fields
[3].GetFloat();
844 AddTeleportCoords(pTC
);
846 } while( result
->NextRow() );
850 sLog
.outString( "" );
851 sLog
.outString( ">> Loaded %d teleport definitions", count
);
855 void ObjectMgr::SetHighestGuids()
858 QueryResult
*result
= sDatabase
.Query( "SELECT MAX(guid) FROM characters;" );
861 m_hiCharGuid
= (*result
)[0].GetUInt32()+1;
866 result
= sDatabase
.Query( "SELECT MAX(guid) FROM creatures;" );
869 m_hiCreatureGuid
= (*result
)[0].GetUInt32()+1;
874 result
= sDatabase
.Query( "SELECT MAX(guid) FROM item_instances;" );
877 m_hiItemGuid
= (*result
)[0].GetUInt32()+1;
884 result
= sDatabase
.Query("SELECT MAX(guid) FROM gameobjects;" );
887 m_hiGoGuid
= (*result
)[0].GetUInt32()+1;
892 result
= sDatabase
.Query("SELECT MAX(id) FROM auctionhouse;" );
895 m_auctionid
= (*result
)[0].GetUInt32()+1;
903 result
= sDatabase
.PQuery( "SELECT MAX(mailid) FROM mail;" );
906 m_mailid
= (*result
)[0].GetUInt32()+1;
915 result
= sDatabase
.PQuery( "SELECT MAX(guid) FROM corpses;" );
918 m_hiCorpseGuid
= (*result
)[0].GetUInt32()+1;
926 uint32
ObjectMgr::GenerateAuctionID()
929 return ++m_auctionid
;
933 uint32
ObjectMgr::GenerateMailID()
939 uint32
ObjectMgr::GenerateLowGuid(uint32 guidhigh
)
945 case HIGHGUID_ITEM
: return ++m_hiItemGuid
;
946 case HIGHGUID_UNIT
: return ++m_hiCreatureGuid
;
947 case HIGHGUID_PLAYER
: return ++m_hiCharGuid
;
948 case HIGHGUID_GAMEOBJECT
: return ++m_hiGoGuid
;
949 case HIGHGUID_CORPSE
: return ++m_hiCorpseGuid
;
950 case HIGHGUID_DYNAMICOBJECT
: return ++m_hiDoGuid
;
961 GameObjectInfo
*ObjectMgr::GetGameObjectInfo(uint32 id
)
964 if(sGOStorage
.iNumRecords
<=id
)
966 sLog
.outString("ERROR: There is no GO with proto %u id the DB",id
);
970 return (sGOStorage
.iNumRecords
<=id
)?NULL
:(GameObjectInfo
*)sGOStorage
.pIndex
[id
];
974 void ObjectMgr::LoadGameobjectInfo()
978 sLog
.outString( ">> Loaded %d game object templates", sGOStorage
.iNumRecords
);
984 ItemPrototype
* ObjectMgr::GetItemPrototype(uint32 id
)
986 return (sItemStorage
.iNumRecords
<=id
)?NULL
:(ItemPrototype
*)sItemStorage
.pIndex
[id
];