2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
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"
22 #include "Database/SQLStorageImpl.h"
23 #include "Policies/SingletonImp.h"
26 #include "MapManager.h"
27 #include "ObjectMgr.h"
28 #include "ObjectDefines.h"
30 #include "UpdateMask.h"
34 #include "ArenaTeam.h"
35 #include "Transports.h"
36 #include "ProgressBar.h"
38 #include "GameEventMgr.h"
41 #include "AccountMgr.h"
42 #include "InstanceSaveMgr.h"
43 #include "SpellAuras.h"
45 #include "WaypointManager.h"
46 #include "GossipDef.h"
48 INSTANTIATE_SINGLETON_1(ObjectMgr
);
50 ScriptMapMap sQuestEndScripts
;
51 ScriptMapMap sQuestStartScripts
;
52 ScriptMapMap sSpellScripts
;
53 ScriptMapMap sGameObjectScripts
;
54 ScriptMapMap sEventScripts
;
55 ScriptMapMap sGossipScripts
;
57 bool normalizePlayerName(std::string
& name
)
62 wchar_t wstr_buf
[MAX_INTERNAL_PLAYER_NAME
+1];
63 size_t wstr_len
= MAX_INTERNAL_PLAYER_NAME
;
65 if(!Utf8toWStr(name
,&wstr_buf
[0],wstr_len
))
68 wstr_buf
[0] = wcharToUpper(wstr_buf
[0]);
69 for(size_t i
= 1; i
< wstr_len
; ++i
)
70 wstr_buf
[i
] = wcharToLower(wstr_buf
[i
]);
72 if(!WStrToUtf8(wstr_buf
,wstr_len
,name
))
78 LanguageDesc lang_description
[LANGUAGES_COUNT
] =
81 { LANG_UNIVERSAL
, 0, 0 },
82 { LANG_ORCISH
, 669, SKILL_LANG_ORCISH
},
83 { LANG_DARNASSIAN
, 671, SKILL_LANG_DARNASSIAN
},
84 { LANG_TAURAHE
, 670, SKILL_LANG_TAURAHE
},
85 { LANG_DWARVISH
, 672, SKILL_LANG_DWARVEN
},
86 { LANG_COMMON
, 668, SKILL_LANG_COMMON
},
87 { LANG_DEMONIC
, 815, SKILL_LANG_DEMON_TONGUE
},
88 { LANG_TITAN
, 816, SKILL_LANG_TITAN
},
89 { LANG_THALASSIAN
, 813, SKILL_LANG_THALASSIAN
},
90 { LANG_DRACONIC
, 814, SKILL_LANG_DRACONIC
},
91 { LANG_KALIMAG
, 817, SKILL_LANG_OLD_TONGUE
},
92 { LANG_GNOMISH
, 7340, SKILL_LANG_GNOMISH
},
93 { LANG_TROLL
, 7341, SKILL_LANG_TROLL
},
94 { LANG_GUTTERSPEAK
, 17737, SKILL_LANG_GUTTERSPEAK
},
95 { LANG_DRAENEI
, 29932, SKILL_LANG_DRAENEI
},
96 { LANG_ZOMBIE
, 0, 0 },
97 { LANG_GNOMISH_BINARY
, 0, 0 },
98 { LANG_GOBLIN_BINARY
, 0, 0 }
101 LanguageDesc
const* GetLanguageDescByID(uint32 lang
)
103 for(int i
= 0; i
< LANGUAGES_COUNT
; ++i
)
105 if(uint32(lang_description
[i
].lang_id
) == lang
)
106 return &lang_description
[i
];
112 bool SpellClickInfo::IsFitToRequirements(Player
const* player
) const
116 // not in expected required quest state
117 if (!player
|| ((!questStartCanActive
|| !player
->IsActiveQuest(questStart
)) && !player
->GetQuestRewardStatus(questStart
)))
123 // not in expected forbidden quest state
124 if(!player
|| player
->GetQuestRewardStatus(questEnd
))
131 ObjectMgr::ObjectMgr()
134 m_hiCreatureGuid
= 1;
141 m_equipmentSetGuid
= 1;
146 // Only zero condition left, others will be added while loading DB tables
147 mConditions
.resize(1);
150 ObjectMgr::~ObjectMgr()
152 for( QuestMap::iterator i
= mQuestTemplates
.begin( ); i
!= mQuestTemplates
.end( ); ++i
)
155 for(PetLevelInfoMap::iterator i
= petInfo
.begin( ); i
!= petInfo
.end( ); ++i
)
158 // free only if loaded
159 for (int class_
= 0; class_
< MAX_CLASSES
; ++class_
)
160 delete[] playerClassInfo
[class_
].levelInfo
;
162 for (int race
= 0; race
< MAX_RACES
; ++race
)
163 for (int class_
= 0; class_
< MAX_CLASSES
; ++class_
)
164 delete[] playerInfo
[race
][class_
].levelInfo
;
166 // free group and guild objects
167 for (GroupSet::iterator itr
= mGroupSet
.begin(); itr
!= mGroupSet
.end(); ++itr
)
170 for (GuildMap::iterator itr
= mGuildMap
.begin(); itr
!= mGuildMap
.end(); ++itr
)
173 for (ArenaTeamMap::iterator itr
= mArenaTeamMap
.begin(); itr
!= mArenaTeamMap
.end(); ++itr
)
176 for (CacheVendorItemMap::iterator itr
= m_mCacheVendorItemMap
.begin(); itr
!= m_mCacheVendorItemMap
.end(); ++itr
)
179 for (CacheTrainerSpellMap::iterator itr
= m_mCacheTrainerSpellMap
.begin(); itr
!= m_mCacheTrainerSpellMap
.end(); ++itr
)
183 Group
* ObjectMgr::GetGroupByLeader(const uint64
&guid
) const
185 for(GroupSet::const_iterator itr
= mGroupSet
.begin(); itr
!= mGroupSet
.end(); ++itr
)
186 if ((*itr
)->GetLeaderGUID() == guid
)
192 Guild
* ObjectMgr::GetGuildById(uint32 GuildId
) const
194 GuildMap::const_iterator itr
= mGuildMap
.find(GuildId
);
195 if (itr
!= mGuildMap
.end())
201 Guild
* ObjectMgr::GetGuildByName(const std::string
& guildname
) const
203 for(GuildMap::const_iterator itr
= mGuildMap
.begin(); itr
!= mGuildMap
.end(); ++itr
)
204 if (itr
->second
->GetName() == guildname
)
210 std::string
ObjectMgr::GetGuildNameById(uint32 GuildId
) const
212 GuildMap::const_iterator itr
= mGuildMap
.find(GuildId
);
213 if (itr
!= mGuildMap
.end())
214 return itr
->second
->GetName();
219 Guild
* ObjectMgr::GetGuildByLeader(const uint64
&guid
) const
221 for(GuildMap::const_iterator itr
= mGuildMap
.begin(); itr
!= mGuildMap
.end(); ++itr
)
222 if (itr
->second
->GetLeader() == guid
)
228 void ObjectMgr::AddGuild(Guild
* guild
)
230 mGuildMap
[guild
->GetId()] = guild
;
233 void ObjectMgr::RemoveGuild(uint32 Id
)
238 ArenaTeam
* ObjectMgr::GetArenaTeamById(uint32 arenateamid
) const
240 ArenaTeamMap::const_iterator itr
= mArenaTeamMap
.find(arenateamid
);
241 if (itr
!= mArenaTeamMap
.end())
247 ArenaTeam
* ObjectMgr::GetArenaTeamByName(const std::string
& arenateamname
) const
249 for(ArenaTeamMap::const_iterator itr
= mArenaTeamMap
.begin(); itr
!= mArenaTeamMap
.end(); ++itr
)
250 if (itr
->second
->GetName() == arenateamname
)
256 ArenaTeam
* ObjectMgr::GetArenaTeamByCaptain(uint64
const& guid
) const
258 for(ArenaTeamMap::const_iterator itr
= mArenaTeamMap
.begin(); itr
!= mArenaTeamMap
.end(); ++itr
)
259 if (itr
->second
->GetCaptain() == guid
)
265 void ObjectMgr::AddArenaTeam(ArenaTeam
* arenaTeam
)
267 mArenaTeamMap
[arenaTeam
->GetId()] = arenaTeam
;
270 void ObjectMgr::RemoveArenaTeam(uint32 Id
)
272 mArenaTeamMap
.erase(Id
);
275 CreatureInfo
const* ObjectMgr::GetCreatureTemplate(uint32 id
)
277 return sCreatureStorage
.LookupEntry
<CreatureInfo
>(id
);
280 void ObjectMgr::LoadCreatureLocales()
282 mCreatureLocaleMap
.clear(); // need for reload case
284 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");
293 sLog
.outString(">> Loaded 0 creature locale strings. DB table `locales_creature` is empty.");
297 barGoLink
bar(result
->GetRowCount());
301 Field
*fields
= result
->Fetch();
304 uint32 entry
= fields
[0].GetUInt32();
306 CreatureLocale
& data
= mCreatureLocaleMap
[entry
];
308 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
310 std::string str
= fields
[1+2*(i
-1)].GetCppString();
313 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
316 if(data
.Name
.size() <= idx
)
317 data
.Name
.resize(idx
+1);
319 data
.Name
[idx
] = str
;
322 str
= fields
[1+2*(i
-1)+1].GetCppString();
325 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
328 if(data
.SubName
.size() <= idx
)
329 data
.SubName
.resize(idx
+1);
331 data
.SubName
[idx
] = str
;
335 } while (result
->NextRow());
340 sLog
.outString( ">> Loaded %lu creature locale strings", (unsigned long)mCreatureLocaleMap
.size() );
343 void ObjectMgr::LoadGossipMenuItemsLocales()
345 mGossipMenuItemsLocaleMap
.clear(); // need for reload case
347 QueryResult
*result
= WorldDatabase
.Query("SELECT menu_id,id,"
348 "option_text_loc1,box_text_loc1,option_text_loc2,box_text_loc2,"
349 "option_text_loc3,box_text_loc3,option_text_loc4,box_text_loc4,"
350 "option_text_loc5,box_text_loc5,option_text_loc6,box_text_loc6,"
351 "option_text_loc7,box_text_loc7,option_text_loc8,box_text_loc8 "
352 "FROM locales_gossip_menu_option");
361 sLog
.outString(">> Loaded 0 gossip_menu_option locale strings. DB table `locales_gossip_menu_option` is empty.");
365 barGoLink
bar(result
->GetRowCount());
369 Field
*fields
= result
->Fetch();
372 uint16 menuId
= fields
[0].GetUInt16();
373 uint16 id
= fields
[1].GetUInt16();
375 GossipMenuItemsLocale
& data
= mGossipMenuItemsLocaleMap
[MAKE_PAIR32(menuId
,id
)];
377 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
379 std::string str
= fields
[2+2*(i
-1)].GetCppString();
382 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
385 if(data
.OptionText
.size() <= idx
)
386 data
.OptionText
.resize(idx
+1);
388 data
.OptionText
[idx
] = str
;
391 str
= fields
[2+2*(i
-1)+1].GetCppString();
394 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
397 if(data
.BoxText
.size() <= idx
)
398 data
.BoxText
.resize(idx
+1);
400 data
.BoxText
[idx
] = str
;
404 } while (result
->NextRow());
409 sLog
.outString( ">> Loaded %lu gossip_menu_option locale strings", (unsigned long)mGossipMenuItemsLocaleMap
.size() );
412 void ObjectMgr::LoadPointOfInterestLocales()
414 mPointOfInterestLocaleMap
.clear(); // need for reload case
416 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,icon_name_loc1,icon_name_loc2,icon_name_loc3,icon_name_loc4,icon_name_loc5,icon_name_loc6,icon_name_loc7,icon_name_loc8 FROM locales_points_of_interest");
425 sLog
.outString(">> Loaded 0 points_of_interest locale strings. DB table `locales_points_of_interest` is empty.");
429 barGoLink
bar(result
->GetRowCount());
433 Field
*fields
= result
->Fetch();
436 uint32 entry
= fields
[0].GetUInt32();
438 PointOfInterestLocale
& data
= mPointOfInterestLocaleMap
[entry
];
440 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
442 std::string str
= fields
[i
].GetCppString();
446 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
449 if(data
.IconName
.size() <= idx
)
450 data
.IconName
.resize(idx
+1);
452 data
.IconName
[idx
] = str
;
455 } while (result
->NextRow());
460 sLog
.outString( ">> Loaded %lu points_of_interest locale strings", (unsigned long)mPointOfInterestLocaleMap
.size() );
463 struct SQLCreatureLoader
: public SQLStorageLoaderBase
<SQLCreatureLoader
>
466 void convert_from_str(uint32
/*field_pos*/, char *src
, D
&dst
)
468 dst
= D(sObjectMgr
.GetScriptId(src
));
472 void ObjectMgr::LoadCreatureTemplates()
474 SQLCreatureLoader loader
;
475 loader
.Load(sCreatureStorage
);
477 sLog
.outString( ">> Loaded %u creature definitions", sCreatureStorage
.RecordCount
);
480 std::set
<uint32
> difficultyEntries
[MAX_DIFFICULTY
- 1]; // already loaded difficulty 1 value in creatures
481 std::set
<uint32
> hasDifficultyEntries
[MAX_DIFFICULTY
- 1]; // already loaded creatures with difficulty 1 values
483 // check data correctness
484 for(uint32 i
= 1; i
< sCreatureStorage
.MaxEntry
; ++i
)
486 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
>(i
);
490 bool ok
= true; // bool to allow continue outside this loop
491 for (uint32 diff
= 0; diff
< MAX_DIFFICULTY
- 1 && ok
; ++diff
)
493 if (!cInfo
->DifficultyEntry
[diff
])
495 ok
= false; // will be set to true at the end of this loop again
497 CreatureInfo
const* difficultyInfo
= GetCreatureTemplate(cInfo
->DifficultyEntry
[diff
]);
500 sLog
.outErrorDb("Creature (Entry: %u) have `difficulty_entry_%u`=%u but creature entry %u not exist.",
501 i
, diff
+ 1, cInfo
->DifficultyEntry
[diff
], cInfo
->DifficultyEntry
[diff
]);
505 if (difficultyEntries
[diff
].find(i
) != difficultyEntries
[diff
].end())
507 sLog
.outErrorDb("Creature (Entry: %u) listed as difficulty %u but have value in `difficulty_entry_%u`.", i
, diff
+ 1, diff
+ 1);
512 for (uint32 diff2
= 0; diff2
< MAX_DIFFICULTY
- 1 && ok2
; ++diff2
)
515 if (difficultyEntries
[diff2
].find(cInfo
->DifficultyEntry
[diff
]) != difficultyEntries
[diff2
].end())
517 sLog
.outErrorDb("Creature (Entry: %u) already listed as difficulty %u for another entry.", cInfo
->DifficultyEntry
[diff
], diff2
+ 1);
521 if (hasDifficultyEntries
[diff2
].find(cInfo
->DifficultyEntry
[diff
]) != hasDifficultyEntries
[diff2
].end())
523 sLog
.outErrorDb("Creature (Entry: %u) have `difficulty_entry_%u`=%u but creature entry %u have difficulty %u entry also.",
524 i
, diff
+ 1, cInfo
->DifficultyEntry
[diff
], cInfo
->DifficultyEntry
[diff
], diff2
+ 1);
532 if (cInfo
->unit_class
!= difficultyInfo
->unit_class
)
534 sLog
.outErrorDb("Creature (Entry: %u, class %u) has different `unit_class` in difficulty %u mode (Entry: %u, class %u).",
535 i
, cInfo
->unit_class
, diff
+ 1, cInfo
->DifficultyEntry
[diff
], difficultyInfo
->unit_class
);
539 if (cInfo
->npcflag
!= difficultyInfo
->npcflag
)
541 sLog
.outErrorDb("Creature (Entry: %u) has different `npcflag` in difficulty %u mode (Entry: %u).", i
, diff
+ 1, cInfo
->DifficultyEntry
[diff
]);
545 if (cInfo
->trainer_class
!= difficultyInfo
->trainer_class
)
547 sLog
.outErrorDb("Creature (Entry: %u) has different `trainer_class` in difficulty %u mode (Entry: %u).", i
, diff
+ 1, cInfo
->DifficultyEntry
[diff
]);
551 if (cInfo
->trainer_race
!= difficultyInfo
->trainer_race
)
553 sLog
.outErrorDb("Creature (Entry: %u) has different `trainer_race` in difficulty %u mode (Entry: %u).", i
, diff
+ 1, cInfo
->DifficultyEntry
[diff
]);
557 if (cInfo
->trainer_type
!= difficultyInfo
->trainer_type
)
559 sLog
.outErrorDb("Creature (Entry: %u) has different `trainer_type` in difficulty %u mode (Entry: %u).", i
, diff
+ 1, cInfo
->DifficultyEntry
[diff
]);
563 if (cInfo
->trainer_spell
!= difficultyInfo
->trainer_spell
)
565 sLog
.outErrorDb("Creature (Entry: %u) has different `trainer_spell` in difficulty %u mode (Entry: %u).", i
, diff
+ 1, cInfo
->DifficultyEntry
[diff
]);
569 if (difficultyInfo
->AIName
&& *difficultyInfo
->AIName
)
571 sLog
.outErrorDb("Difficulty %u mode creature (Entry: %u) has `AIName`, but in any case will used difficulty 0 mode creature (Entry: %u) AIName.",
572 diff
, cInfo
->DifficultyEntry
[diff
], i
);
576 if (difficultyInfo
->ScriptID
)
578 sLog
.outErrorDb("Difficulty %u mode creature (Entry: %u) has `ScriptName`, but in any case will used difficulty 0 mode creature (Entry: %u) ScriptName.",
579 diff
, cInfo
->DifficultyEntry
[diff
], i
);
583 hasDifficultyEntries
[diff
].insert(i
);
584 difficultyEntries
[diff
].insert(cInfo
->DifficultyEntry
[diff
]);
590 FactionTemplateEntry
const* factionTemplate
= sFactionTemplateStore
.LookupEntry(cInfo
->faction_A
);
591 if (!factionTemplate
)
592 sLog
.outErrorDb("Creature (Entry: %u) has non-existing faction_A template (%u)", cInfo
->Entry
, cInfo
->faction_A
);
594 factionTemplate
= sFactionTemplateStore
.LookupEntry(cInfo
->faction_H
);
595 if (!factionTemplate
)
596 sLog
.outErrorDb("Creature (Entry: %u) has non-existing faction_H template (%u)", cInfo
->Entry
, cInfo
->faction_H
);
598 // used later for scale
599 CreatureDisplayInfoEntry
const* displayScaleEntry
= NULL
;
601 if (cInfo
->DisplayID_A
[0])
603 CreatureDisplayInfoEntry
const* displayEntry
= sCreatureDisplayInfoStore
.LookupEntry(cInfo
->DisplayID_A
[0]);
606 sLog
.outErrorDb("Creature (Entry: %u) has non-existing DisplayID_A id (%u), can crash client", cInfo
->Entry
, cInfo
->DisplayID_A
[0]);
607 const_cast<CreatureInfo
*>(cInfo
)->DisplayID_A
[0] = 0;
609 else if(!displayScaleEntry
)
610 displayScaleEntry
= displayEntry
;
612 CreatureModelInfo
const* minfo
= sCreatureModelStorage
.LookupEntry
<CreatureModelInfo
>(cInfo
->DisplayID_A
[0]);
614 sLog
.outErrorDb("Creature (Entry: %u) not has model data for DisplayID_A (%u)", cInfo
->Entry
, cInfo
->DisplayID_A
[0]);
617 if (cInfo
->DisplayID_A
[1])
619 CreatureDisplayInfoEntry
const* displayEntry
= sCreatureDisplayInfoStore
.LookupEntry(cInfo
->DisplayID_A
[1]);
622 sLog
.outErrorDb("Creature (Entry: %u) has non-existing DisplayID_A2 id (%u), can crash client", cInfo
->Entry
, cInfo
->DisplayID_A
[1]);
623 const_cast<CreatureInfo
*>(cInfo
)->DisplayID_A
[1] = 0;
625 else if(!displayScaleEntry
)
626 displayScaleEntry
= displayEntry
;
628 CreatureModelInfo
const* minfo
= sCreatureModelStorage
.LookupEntry
<CreatureModelInfo
>(cInfo
->DisplayID_A
[1]);
630 sLog
.outErrorDb("Creature (Entry: %u) not has model data for DisplayID_A2 (%u)", cInfo
->Entry
, cInfo
->DisplayID_A
[1]);
633 if (cInfo
->DisplayID_H
[0])
635 CreatureDisplayInfoEntry
const* displayEntry
= sCreatureDisplayInfoStore
.LookupEntry(cInfo
->DisplayID_H
[0]);
638 sLog
.outErrorDb("Creature (Entry: %u) has non-existing DisplayID_H id (%u), can crash client", cInfo
->Entry
, cInfo
->DisplayID_H
[0]);
639 const_cast<CreatureInfo
*>(cInfo
)->DisplayID_H
[0] = 0;
641 else if(!displayScaleEntry
)
642 displayScaleEntry
= displayEntry
;
644 CreatureModelInfo
const* minfo
= sCreatureModelStorage
.LookupEntry
<CreatureModelInfo
>(cInfo
->DisplayID_H
[0]);
646 sLog
.outErrorDb("Creature (Entry: %u) not has model data for DisplayID_H (%u)", cInfo
->Entry
, cInfo
->DisplayID_H
[0]);
649 if (cInfo
->DisplayID_H
[1])
651 CreatureDisplayInfoEntry
const* displayEntry
= sCreatureDisplayInfoStore
.LookupEntry(cInfo
->DisplayID_H
[1]);
654 sLog
.outErrorDb("Creature (Entry: %u) has non-existing DisplayID_H2 id (%u), can crash client", cInfo
->Entry
, cInfo
->DisplayID_H
[1]);
655 const_cast<CreatureInfo
*>(cInfo
)->DisplayID_H
[1] = 0;
657 else if(!displayScaleEntry
)
658 displayScaleEntry
= displayEntry
;
660 CreatureModelInfo
const* minfo
= sCreatureModelStorage
.LookupEntry
<CreatureModelInfo
>(cInfo
->DisplayID_H
[1]);
662 sLog
.outErrorDb("Creature (Entry: %u) not has model data for DisplayID_H2 (%u)", cInfo
->Entry
, cInfo
->DisplayID_H
[1]);
665 if (!displayScaleEntry
)
666 sLog
.outErrorDb("Creature (Entry: %u) not has any existed display id in DisplayID_A/DisplayID_A2/DisplayID_H/DisplayID_H2", cInfo
->Entry
);
668 for(int k
= 0; k
< MAX_KILL_CREDIT
; ++k
)
670 if(cInfo
->KillCredit
[k
])
672 if(!GetCreatureTemplate(cInfo
->KillCredit
[k
]))
674 sLog
.outErrorDb("Creature (Entry: %u) has not existed creature entry in `KillCredit%d` (%u)",cInfo
->Entry
,k
+1,cInfo
->KillCredit
[k
]);
675 const_cast<CreatureInfo
*>(cInfo
)->KillCredit
[k
] = 0;
680 // use below code for 0-checks for unit_class
681 if (/*!cInfo->unit_class ||*/cInfo
->unit_class
&& ((1 << (cInfo
->unit_class
-1)) & CLASSMASK_ALL_CREATURES
) == 0)
682 sLog
.outErrorDb("Creature (Entry: %u) has invalid unit_class(%u) for creature_template", cInfo
->Entry
, cInfo
->unit_class
);
684 if(cInfo
->dmgschool
>= MAX_SPELL_SCHOOL
)
686 sLog
.outErrorDb("Creature (Entry: %u) has invalid spell school value (%u) in `dmgschool`",cInfo
->Entry
,cInfo
->dmgschool
);
687 const_cast<CreatureInfo
*>(cInfo
)->dmgschool
= SPELL_SCHOOL_NORMAL
;
690 if(cInfo
->baseattacktime
== 0)
691 const_cast<CreatureInfo
*>(cInfo
)->baseattacktime
= BASE_ATTACK_TIME
;
693 if(cInfo
->rangeattacktime
== 0)
694 const_cast<CreatureInfo
*>(cInfo
)->rangeattacktime
= BASE_ATTACK_TIME
;
696 if(cInfo
->npcflag
& UNIT_NPC_FLAG_SPELLCLICK
)
698 sLog
.outErrorDb("Creature (Entry: %u) has dynamic flag UNIT_NPC_FLAG_SPELLCLICK (%u) set, it expect to be set by code base at `npc_spellclick_spells` content.",cInfo
->Entry
,UNIT_NPC_FLAG_SPELLCLICK
);
699 const_cast<CreatureInfo
*>(cInfo
)->npcflag
&= ~UNIT_NPC_FLAG_SPELLCLICK
;
702 if((cInfo
->npcflag
& UNIT_NPC_FLAG_TRAINER
) && cInfo
->trainer_type
>= MAX_TRAINER_TYPE
)
703 sLog
.outErrorDb("Creature (Entry: %u) has wrong trainer type %u",cInfo
->Entry
,cInfo
->trainer_type
);
705 if(cInfo
->type
&& !sCreatureTypeStore
.LookupEntry(cInfo
->type
))
707 sLog
.outErrorDb("Creature (Entry: %u) has invalid creature type (%u) in `type`",cInfo
->Entry
,cInfo
->type
);
708 const_cast<CreatureInfo
*>(cInfo
)->type
= CREATURE_TYPE_HUMANOID
;
711 // must exist or used hidden but used in data horse case
712 if(cInfo
->family
&& !sCreatureFamilyStore
.LookupEntry(cInfo
->family
) && cInfo
->family
!= CREATURE_FAMILY_HORSE_CUSTOM
)
714 sLog
.outErrorDb("Creature (Entry: %u) has invalid creature family (%u) in `family`",cInfo
->Entry
,cInfo
->family
);
715 const_cast<CreatureInfo
*>(cInfo
)->family
= 0;
718 if(cInfo
->InhabitType
<= 0 || cInfo
->InhabitType
> INHABIT_ANYWHERE
)
720 sLog
.outErrorDb("Creature (Entry: %u) has wrong value (%u) in `InhabitType`, creature will not correctly walk/swim/fly",cInfo
->Entry
,cInfo
->InhabitType
);
721 const_cast<CreatureInfo
*>(cInfo
)->InhabitType
= INHABIT_ANYWHERE
;
724 if(cInfo
->PetSpellDataId
)
726 CreatureSpellDataEntry
const* spellDataId
= sCreatureSpellDataStore
.LookupEntry(cInfo
->PetSpellDataId
);
728 sLog
.outErrorDb("Creature (Entry: %u) has non-existing PetSpellDataId (%u)", cInfo
->Entry
, cInfo
->PetSpellDataId
);
731 for(int j
= 0; j
< CREATURE_MAX_SPELLS
; ++j
)
733 if(cInfo
->spells
[j
] && !sSpellStore
.LookupEntry(cInfo
->spells
[j
]))
735 sLog
.outErrorDb("Creature (Entry: %u) has non-existing Spell%d (%u), set to 0", cInfo
->Entry
, j
+1,cInfo
->spells
[j
]);
736 const_cast<CreatureInfo
*>(cInfo
)->spells
[j
] = 0;
740 if(cInfo
->MovementType
>= MAX_DB_MOTION_TYPE
)
742 sLog
.outErrorDb("Creature (Entry: %u) has wrong movement generator type (%u), ignore and set to IDLE.",cInfo
->Entry
,cInfo
->MovementType
);
743 const_cast<CreatureInfo
*>(cInfo
)->MovementType
= IDLE_MOTION_TYPE
;
746 if(cInfo
->equipmentId
> 0) // 0 no equipment
748 if(!GetEquipmentInfo(cInfo
->equipmentId
))
750 sLog
.outErrorDb("Table `creature_template` have creature (Entry: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.", cInfo
->Entry
, cInfo
->equipmentId
);
751 const_cast<CreatureInfo
*>(cInfo
)->equipmentId
= 0;
755 /// if not set custom creature scale then load scale from CreatureDisplayInfo.dbc
756 if(cInfo
->scale
<= 0.0f
)
758 if(displayScaleEntry
)
759 const_cast<CreatureInfo
*>(cInfo
)->scale
= displayScaleEntry
->scale
;
761 const_cast<CreatureInfo
*>(cInfo
)->scale
= 1.0f
;
766 void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon
* addon
, char const* table
, char const* guidEntryStr
)
768 // Now add the auras, format "spellid effectindex spellid effectindex..."
770 std::vector
<int> val
;
771 s
=p
=(char*)reinterpret_cast<char const*>(addon
->auras
);
779 val
.push_back(atoi(s
));
784 val
.push_back(atoi(s
));
786 // free char* loaded memory
787 delete[] (char*)reinterpret_cast<char const*>(addon
->auras
);
793 sLog
.outErrorDb("Creature (%s: %u) has wrong `auras` data in `%s`.",guidEntryStr
,addon
->guidOrEntry
,table
);
805 // replace by new structures array
806 const_cast<CreatureDataAddonAura
*&>(addon
->auras
) = new CreatureDataAddonAura
[val
.size()/2+1];
809 for(uint32 j
= 0; j
< val
.size()/2; ++j
)
811 CreatureDataAddonAura
& cAura
= const_cast<CreatureDataAddonAura
&>(addon
->auras
[i
]);
812 cAura
.spell_id
= (uint32
)val
[2*j
+0];
813 cAura
.effect_idx
= (uint32
)val
[2*j
+1];
814 if ( cAura
.effect_idx
> 2 )
816 sLog
.outErrorDb("Creature (%s: %u) has wrong effect %u for spell %u in `auras` field in `%s`.",guidEntryStr
,addon
->guidOrEntry
,cAura
.effect_idx
,cAura
.spell_id
,table
);
819 SpellEntry
const *AdditionalSpellInfo
= sSpellStore
.LookupEntry(cAura
.spell_id
);
820 if (!AdditionalSpellInfo
)
822 sLog
.outErrorDb("Creature (%s: %u) has wrong spell %u defined in `auras` field in `%s`.",guidEntryStr
,addon
->guidOrEntry
,cAura
.spell_id
,table
);
826 if (!AdditionalSpellInfo
->Effect
[cAura
.effect_idx
] || !AdditionalSpellInfo
->EffectApplyAuraName
[cAura
.effect_idx
])
828 sLog
.outErrorDb("Creature (%s: %u) has not aura effect %u of spell %u defined in `auras` field in `%s`.",guidEntryStr
,addon
->guidOrEntry
,cAura
.effect_idx
,cAura
.spell_id
,table
);
835 // fill terminator element (after last added)
836 CreatureDataAddonAura
& endAura
= const_cast<CreatureDataAddonAura
&>(addon
->auras
[i
]);
837 endAura
.spell_id
= 0;
838 endAura
.effect_idx
= 0;
841 void ObjectMgr::LoadCreatureAddons(SQLStorage
& creatureaddons
, char const* entryName
, char const* comment
)
843 creatureaddons
.Load();
845 sLog
.outString(">> Loaded %u %s", creatureaddons
.RecordCount
, comment
);
848 // check data correctness and convert 'auras'
849 for(uint32 i
= 1; i
< creatureaddons
.MaxEntry
; ++i
)
851 CreatureDataAddon
const* addon
= creatureaddons
.LookupEntry
<CreatureDataAddon
>(i
);
857 if (!sCreatureDisplayInfoStore
.LookupEntry(addon
->mount
))
859 sLog
.outErrorDb("Creature (%s %u) have invalid displayInfoId for mount (%u) defined in `%s`.", entryName
, addon
->guidOrEntry
, addon
->mount
, creatureaddons
.GetTableName());
860 const_cast<CreatureDataAddon
*>(addon
)->mount
= 0;
864 if (!sEmotesStore
.LookupEntry(addon
->emote
))
865 sLog
.outErrorDb("Creature (%s %u) have invalid emote (%u) defined in `%s`.", entryName
, addon
->guidOrEntry
, addon
->emote
, creatureaddons
.GetTableName());
867 if (addon
->move_flags
& (MONSTER_MOVE_UNK1
|MONSTER_MOVE_UNK4
))
869 sLog
.outErrorDb("Creature (%s %u) movement flags mask defined in `%s` include forbidden flags (" I32FMT
") that can crash client, cleanup at load.", entryName
, addon
->guidOrEntry
, creatureaddons
.GetTableName(), (MONSTER_MOVE_UNK1
|MONSTER_MOVE_UNK4
));
870 const_cast<CreatureDataAddon
*>(addon
)->move_flags
&= ~(MONSTER_MOVE_UNK1
|MONSTER_MOVE_UNK4
);
873 ConvertCreatureAddonAuras(const_cast<CreatureDataAddon
*>(addon
), creatureaddons
.GetTableName(), entryName
);
877 void ObjectMgr::LoadCreatureAddons()
879 LoadCreatureAddons(sCreatureInfoAddonStorage
,"Entry","creature template addons");
882 for(uint32 i
= 1; i
< sCreatureInfoAddonStorage
.MaxEntry
; ++i
)
883 if(CreatureDataAddon
const* addon
= sCreatureInfoAddonStorage
.LookupEntry
<CreatureDataAddon
>(i
))
884 if(!sCreatureStorage
.LookupEntry
<CreatureInfo
>(addon
->guidOrEntry
))
885 sLog
.outErrorDb("Creature (Entry: %u) does not exist but has a record in `%s`",addon
->guidOrEntry
, sCreatureInfoAddonStorage
.GetTableName());
887 LoadCreatureAddons(sCreatureDataAddonStorage
,"GUID","creature addons");
890 for(uint32 i
= 1; i
< sCreatureDataAddonStorage
.MaxEntry
; ++i
)
891 if(CreatureDataAddon
const* addon
= sCreatureDataAddonStorage
.LookupEntry
<CreatureDataAddon
>(i
))
892 if(mCreatureDataMap
.find(addon
->guidOrEntry
)==mCreatureDataMap
.end())
893 sLog
.outErrorDb("Creature (GUID: %u) does not exist but has a record in `creature_addon`",addon
->guidOrEntry
);
896 EquipmentInfo
const* ObjectMgr::GetEquipmentInfo(uint32 entry
)
898 return sEquipmentStorage
.LookupEntry
<EquipmentInfo
>(entry
);
901 void ObjectMgr::LoadEquipmentTemplates()
903 sEquipmentStorage
.Load();
905 for(uint32 i
=0; i
< sEquipmentStorage
.MaxEntry
; ++i
)
907 EquipmentInfo
const* eqInfo
= sEquipmentStorage
.LookupEntry
<EquipmentInfo
>(i
);
912 for(uint8 j
=0; j
<3; j
++)
914 if(!eqInfo
->equipentry
[j
])
917 ItemEntry
const *dbcitem
= sItemStore
.LookupEntry(eqInfo
->equipentry
[j
]);
921 sLog
.outErrorDb("Unknown item (entry=%u) in creature_equip_template.equipentry%u for entry = %u, forced to 0.", eqInfo
->equipentry
[j
], j
+1, i
);
922 const_cast<EquipmentInfo
*>(eqInfo
)->equipentry
[j
] = 0;
926 if(dbcitem
->InventoryType
!= INVTYPE_WEAPON
&&
927 dbcitem
->InventoryType
!= INVTYPE_SHIELD
&&
928 dbcitem
->InventoryType
!= INVTYPE_RANGED
&&
929 dbcitem
->InventoryType
!= INVTYPE_2HWEAPON
&&
930 dbcitem
->InventoryType
!= INVTYPE_WEAPONMAINHAND
&&
931 dbcitem
->InventoryType
!= INVTYPE_WEAPONOFFHAND
&&
932 dbcitem
->InventoryType
!= INVTYPE_HOLDABLE
&&
933 dbcitem
->InventoryType
!= INVTYPE_THROWN
&&
934 dbcitem
->InventoryType
!= INVTYPE_RANGEDRIGHT
)
936 sLog
.outErrorDb("Item (entry=%u) in creature_equip_template.equipentry%u for entry = %u is not equipable in a hand, forced to 0.", eqInfo
->equipentry
[j
], j
+1, i
);
937 const_cast<EquipmentInfo
*>(eqInfo
)->equipentry
[j
] = 0;
941 sLog
.outString( ">> Loaded %u equipment template", sEquipmentStorage
.RecordCount
);
945 CreatureModelInfo
const* ObjectMgr::GetCreatureModelInfo(uint32 modelid
)
947 return sCreatureModelStorage
.LookupEntry
<CreatureModelInfo
>(modelid
);
950 uint32
ObjectMgr::ChooseDisplayId(uint32 team
, const CreatureInfo
*cinfo
, const CreatureData
*data
/*= NULL*/)
952 // Load creature model (display id)
953 if (data
&& data
->displayid
)
954 return data
->displayid
;
956 // use defaults from the template
959 // DisplayID_A is used if no team is given
962 if(cinfo
->DisplayID_H
[0])
963 display_id
= cinfo
->DisplayID_H
[1] ? cinfo
->DisplayID_H
[urand(0,1)] : cinfo
->DisplayID_H
[0];
965 display_id
= cinfo
->DisplayID_H
[1];
968 display_id
= cinfo
->DisplayID_A
[0] ? cinfo
->DisplayID_A
[0] : cinfo
->DisplayID_A
[1];
972 if(cinfo
->DisplayID_A
[0])
973 display_id
= cinfo
->DisplayID_A
[1] ? cinfo
->DisplayID_A
[urand(0,1)] : cinfo
->DisplayID_A
[0];
975 display_id
= cinfo
->DisplayID_A
[1];
978 display_id
= cinfo
->DisplayID_H
[0] ? cinfo
->DisplayID_H
[0] : cinfo
->DisplayID_H
[1];
984 CreatureModelInfo
const* ObjectMgr::GetCreatureModelRandomGender(uint32 display_id
)
986 CreatureModelInfo
const *minfo
= GetCreatureModelInfo(display_id
);
990 // If a model for another gender exists, 50% chance to use it
991 if(minfo
->modelid_other_gender
!= 0 && urand(0,1) == 0)
993 CreatureModelInfo
const *minfo_tmp
= GetCreatureModelInfo(minfo
->modelid_other_gender
);
996 sLog
.outErrorDb("Model (Entry: %u) has modelid_other_gender %u not found in table `creature_model_info`. ", minfo
->modelid
, minfo
->modelid_other_gender
);
997 return minfo
; // not fatal, just use the previous one
1006 void ObjectMgr::LoadCreatureModelInfo()
1008 sCreatureModelStorage
.Load();
1011 for(uint32 i
= 1; i
< sCreatureModelStorage
.MaxEntry
; ++i
)
1013 CreatureModelInfo
const *minfo
= sCreatureModelStorage
.LookupEntry
<CreatureModelInfo
>(i
);
1017 if (!sCreatureDisplayInfoStore
.LookupEntry(minfo
->modelid
))
1018 sLog
.outErrorDb("Table `creature_model_info` has model for not existed display id (%u).", minfo
->modelid
);
1020 if (minfo
->gender
> GENDER_NONE
)
1022 sLog
.outErrorDb("Table `creature_model_info` has wrong gender (%u) for display id (%u).", uint32(minfo
->gender
), minfo
->modelid
);
1023 const_cast<CreatureModelInfo
*>(minfo
)->gender
= GENDER_MALE
;
1026 if (minfo
->modelid_other_gender
&& !sCreatureDisplayInfoStore
.LookupEntry(minfo
->modelid_other_gender
))
1028 sLog
.outErrorDb("Table `creature_model_info` has not existed alt.gender model (%u) for existed display id (%u).", minfo
->modelid_other_gender
, minfo
->modelid
);
1029 const_cast<CreatureModelInfo
*>(minfo
)->modelid_other_gender
= 0;
1033 sLog
.outString( ">> Loaded %u creature model based info", sCreatureModelStorage
.RecordCount
);
1037 void ObjectMgr::LoadCreatures()
1041 QueryResult
*result
= WorldDatabase
.Query("SELECT creature.guid, id, map, modelid,"
1042 // 4 5 6 7 8 9 10 11
1043 "equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint,"
1044 // 12 13 14 15 16 17 18 19
1045 "curhealth, curmana, DeathState, MovementType, spawnMask, phaseMask, event, pool_entry "
1046 "FROM creature LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid "
1047 "LEFT OUTER JOIN pool_creature ON creature.guid = pool_creature.guid");
1056 sLog
.outErrorDb(">> Loaded 0 creature. DB table `creature` is empty.");
1060 // build single time for check creature data
1061 std::set
<uint32
> difficultyCreatures
[MAX_DIFFICULTY
- 1];
1062 for (uint32 i
= 0; i
< sCreatureStorage
.MaxEntry
; ++i
)
1063 if (CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
>(i
))
1064 for (uint32 diff
= 0; diff
< MAX_DIFFICULTY
- 1; ++diff
)
1065 if (cInfo
->DifficultyEntry
[diff
])
1066 difficultyCreatures
[diff
].insert(cInfo
->DifficultyEntry
[diff
]);
1068 // build single time for check spawnmask
1069 std::map
<uint32
,uint32
> spawnMasks
;
1070 for(uint32 i
= 0; i
< sMapStore
.GetNumRows(); ++i
)
1071 if(sMapStore
.LookupEntry(i
))
1072 for(int k
= 0; k
< MAX_DIFFICULTY
; ++k
)
1073 if (GetMapDifficultyData(i
,Difficulty(k
)))
1074 spawnMasks
[i
] |= (1 << k
);
1076 barGoLink
bar(result
->GetRowCount());
1080 Field
*fields
= result
->Fetch();
1083 uint32 guid
= fields
[ 0].GetUInt32();
1084 uint32 entry
= fields
[ 1].GetUInt32();
1086 CreatureInfo
const* cInfo
= GetCreatureTemplate(entry
);
1089 sLog
.outErrorDb("Table `creature` has creature (GUID: %u) with non existing creature entry %u, skipped.", guid
, entry
);
1093 CreatureData
& data
= mCreatureDataMap
[guid
];
1096 data
.mapid
= fields
[ 2].GetUInt32();
1097 data
.displayid
= fields
[ 3].GetUInt32();
1098 data
.equipmentId
= fields
[ 4].GetUInt32();
1099 data
.posX
= fields
[ 5].GetFloat();
1100 data
.posY
= fields
[ 6].GetFloat();
1101 data
.posZ
= fields
[ 7].GetFloat();
1102 data
.orientation
= fields
[ 8].GetFloat();
1103 data
.spawntimesecs
= fields
[ 9].GetUInt32();
1104 data
.spawndist
= fields
[10].GetFloat();
1105 data
.currentwaypoint
= fields
[11].GetUInt32();
1106 data
.curhealth
= fields
[12].GetUInt32();
1107 data
.curmana
= fields
[13].GetUInt32();
1108 data
.is_dead
= fields
[14].GetBool();
1109 data
.movementType
= fields
[15].GetUInt8();
1110 data
.spawnMask
= fields
[16].GetUInt8();
1111 data
.phaseMask
= fields
[17].GetUInt16();
1112 int16 gameEvent
= fields
[18].GetInt16();
1113 int16 PoolId
= fields
[19].GetInt16();
1115 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(data
.mapid
);
1118 sLog
.outErrorDb("Table `creature` have creature (GUID: %u) that spawned at not existed map (Id: %u), skipped.",guid
, data
.mapid
);
1122 if (data
.spawnMask
& ~spawnMasks
[data
.mapid
])
1123 sLog
.outErrorDb("Table `creature` have creature (GUID: %u) that have wrong spawn mask %u including not supported difficulty modes for map (Id: %u).",guid
, data
.spawnMask
, data
.mapid
);
1126 for (uint32 diff
= 0; diff
< MAX_DIFFICULTY
- 1 && ok
; ++diff
)
1128 if (difficultyCreatures
[diff
].find(data
.id
) != difficultyCreatures
[diff
].end())
1130 sLog
.outErrorDb("Table `creature` have creature (GUID: %u) that listed as difficulty %u template (entry: %u) in `creature_template`, skipped.",
1131 guid
, diff
+ 1, data
.id
);
1138 if(data
.equipmentId
> 0) // -1 no equipment, 0 use default
1140 if(!GetEquipmentInfo(data
.equipmentId
))
1142 sLog
.outErrorDb("Table `creature` have creature (Entry: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.", data
.id
, data
.equipmentId
);
1143 data
.equipmentId
= -1;
1147 if(cInfo
->RegenHealth
&& data
.curhealth
< cInfo
->minhealth
)
1149 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `creature_template`.`RegenHealth`=1 and low current health (%u), `creature_template`.`minhealth`=%u.",guid
,data
.id
,data
.curhealth
, cInfo
->minhealth
);
1150 data
.curhealth
= cInfo
->minhealth
;
1153 if(cInfo
->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
1155 if(!mapEntry
|| !mapEntry
->IsDungeon())
1156 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `creature_template`.`flags_extra` including CREATURE_FLAG_EXTRA_INSTANCE_BIND but creature are not in instance.",guid
,data
.id
);
1159 if(data
.curmana
< cInfo
->minmana
)
1161 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with low current mana (%u), `creature_template`.`minmana`=%u.",guid
,data
.id
,data
.curmana
, cInfo
->minmana
);
1162 data
.curmana
= cInfo
->minmana
;
1165 if(data
.spawndist
< 0.0f
)
1167 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `spawndist`< 0, set to 0.",guid
,data
.id
);
1168 data
.spawndist
= 0.0f
;
1170 else if(data
.movementType
== RANDOM_MOTION_TYPE
)
1172 if(data
.spawndist
== 0.0f
)
1174 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `MovementType`=1 (random movement) but with `spawndist`=0, replace by idle movement type (0).",guid
,data
.id
);
1175 data
.movementType
= IDLE_MOTION_TYPE
;
1178 else if(data
.movementType
== IDLE_MOTION_TYPE
)
1180 if(data
.spawndist
!= 0.0f
)
1182 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `MovementType`=0 (idle) have `spawndist`<>0, set to 0.",guid
,data
.id
);
1183 data
.spawndist
= 0.0f
;
1187 if(data
.phaseMask
==0)
1189 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `phaseMask`=0 (not visible for anyone), set to 1.",guid
,data
.id
);
1193 if (gameEvent
==0 && PoolId
==0) // if not this is to be managed by GameEvent System or Pool system
1194 AddCreatureToGrid(guid
, &data
);
1198 } while (result
->NextRow());
1203 sLog
.outString( ">> Loaded %lu creatures", (unsigned long)mCreatureDataMap
.size() );
1206 void ObjectMgr::AddCreatureToGrid(uint32 guid
, CreatureData
const* data
)
1208 uint8 mask
= data
->spawnMask
;
1209 for(uint8 i
= 0; mask
!= 0; i
++, mask
>>= 1)
1213 CellPair cell_pair
= MaNGOS::ComputeCellPair(data
->posX
, data
->posY
);
1214 uint32 cell_id
= (cell_pair
.y_coord
*TOTAL_NUMBER_OF_CELLS_PER_MAP
) + cell_pair
.x_coord
;
1216 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(data
->mapid
,i
)][cell_id
];
1217 cell_guids
.creatures
.insert(guid
);
1222 void ObjectMgr::RemoveCreatureFromGrid(uint32 guid
, CreatureData
const* data
)
1224 uint8 mask
= data
->spawnMask
;
1225 for(uint8 i
= 0; mask
!= 0; i
++, mask
>>= 1)
1229 CellPair cell_pair
= MaNGOS::ComputeCellPair(data
->posX
, data
->posY
);
1230 uint32 cell_id
= (cell_pair
.y_coord
*TOTAL_NUMBER_OF_CELLS_PER_MAP
) + cell_pair
.x_coord
;
1232 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(data
->mapid
,i
)][cell_id
];
1233 cell_guids
.creatures
.erase(guid
);
1238 void ObjectMgr::LoadGameobjects()
1243 QueryResult
*result
= WorldDatabase
.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
1244 // 7 8 9 10 11 12 13 14 15 16 17
1245 "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, event, pool_entry "
1246 "FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid "
1247 "LEFT OUTER JOIN pool_gameobject ON gameobject.guid = pool_gameobject.guid");
1256 sLog
.outErrorDb(">> Loaded 0 gameobjects. DB table `gameobject` is empty.");
1260 // build single time for check spawnmask
1261 std::map
<uint32
,uint32
> spawnMasks
;
1262 for(uint32 i
= 0; i
< sMapStore
.GetNumRows(); ++i
)
1263 if(sMapStore
.LookupEntry(i
))
1264 for(int k
= 0; k
< MAX_DIFFICULTY
; ++k
)
1265 if (GetMapDifficultyData(i
,Difficulty(k
)))
1266 spawnMasks
[i
] |= (1 << k
);
1268 barGoLink
bar(result
->GetRowCount());
1272 Field
*fields
= result
->Fetch();
1275 uint32 guid
= fields
[ 0].GetUInt32();
1276 uint32 entry
= fields
[ 1].GetUInt32();
1278 GameObjectInfo
const* gInfo
= GetGameObjectInfo(entry
);
1281 sLog
.outErrorDb("Table `gameobject` has gameobject (GUID: %u) with non existing gameobject entry %u, skipped.", guid
, entry
);
1285 if(!gInfo
->displayId
)
1289 // can be invisible always and then not req. display id in like case
1290 case GAMEOBJECT_TYPE_TRAP
:
1291 case GAMEOBJECT_TYPE_SPELL_FOCUS
:
1294 sLog
.outErrorDb("Gameobject (GUID: %u Entry %u GoType: %u) have displayId == 0 and then will always invisible in game.", guid
, entry
, gInfo
->type
);
1298 else if (!sGameObjectDisplayInfoStore
.LookupEntry(gInfo
->displayId
))
1300 sLog
.outErrorDb("Gameobject (GUID: %u Entry %u GoType: %u) have invalid displayId (%u), not loaded.", guid
, entry
, gInfo
->type
, gInfo
->displayId
);
1304 GameObjectData
& data
= mGameObjectDataMap
[guid
];
1307 data
.mapid
= fields
[ 2].GetUInt32();
1308 data
.posX
= fields
[ 3].GetFloat();
1309 data
.posY
= fields
[ 4].GetFloat();
1310 data
.posZ
= fields
[ 5].GetFloat();
1311 data
.orientation
= fields
[ 6].GetFloat();
1312 data
.rotation0
= fields
[ 7].GetFloat();
1313 data
.rotation1
= fields
[ 8].GetFloat();
1314 data
.rotation2
= fields
[ 9].GetFloat();
1315 data
.rotation3
= fields
[10].GetFloat();
1316 data
.spawntimesecs
= fields
[11].GetInt32();
1318 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(data
.mapid
);
1321 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) that spawned at not existed map (Id: %u), skip", guid
, data
.id
, data
.mapid
);
1325 if (data
.spawnMask
& ~spawnMasks
[data
.mapid
])
1326 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) that have wrong spawn mask %u including not supported difficulty modes for map (Id: %u), skip", guid
, data
.id
, data
.spawnMask
, data
.mapid
);
1328 if (data
.spawntimesecs
== 0 && gInfo
->IsDespawnAtAction())
1330 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with `spawntimesecs` (0) value, but gameobejct marked as despawnable at action.", guid
, data
.id
);
1333 data
.animprogress
= fields
[12].GetUInt32();
1335 uint32 go_state
= fields
[13].GetUInt32();
1336 if (go_state
>= MAX_GO_STATE
)
1338 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid `state` (%u) value, skip", guid
, data
.id
, go_state
);
1341 data
.go_state
= GOState(go_state
);
1343 data
.spawnMask
= fields
[14].GetUInt8();
1344 data
.phaseMask
= fields
[15].GetUInt16();
1345 int16 gameEvent
= fields
[16].GetInt16();
1346 int16 PoolId
= fields
[17].GetInt16();
1348 if (data
.rotation2
< -1.0f
|| data
.rotation2
> 1.0f
)
1350 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation2 (%f) value, skip", guid
, data
.id
, data
.rotation2
);
1354 if (data
.rotation3
< -1.0f
|| data
.rotation3
> 1.0f
)
1356 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation3 (%f) value, skip", guid
, data
.id
, data
.rotation3
);
1360 if(!MapManager::IsValidMapCoord(data
.mapid
, data
.posX
, data
.posY
, data
.posZ
, data
.orientation
))
1362 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid coordinates, skip", guid
, data
.id
);
1366 if(data
.phaseMask
== 0)
1368 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with `phaseMask`=0 (not visible for anyone), set to 1.", guid
, data
.id
);
1372 if (gameEvent
== 0 && PoolId
== 0) // if not this is to be managed by GameEvent System or Pool system
1373 AddGameobjectToGrid(guid
, &data
);
1376 } while (result
->NextRow());
1381 sLog
.outString( ">> Loaded %lu gameobjects", (unsigned long)mGameObjectDataMap
.size());
1384 void ObjectMgr::AddGameobjectToGrid(uint32 guid
, GameObjectData
const* data
)
1386 uint8 mask
= data
->spawnMask
;
1387 for(uint8 i
= 0; mask
!= 0; i
++, mask
>>= 1)
1391 CellPair cell_pair
= MaNGOS::ComputeCellPair(data
->posX
, data
->posY
);
1392 uint32 cell_id
= (cell_pair
.y_coord
*TOTAL_NUMBER_OF_CELLS_PER_MAP
) + cell_pair
.x_coord
;
1394 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(data
->mapid
,i
)][cell_id
];
1395 cell_guids
.gameobjects
.insert(guid
);
1400 void ObjectMgr::RemoveGameobjectFromGrid(uint32 guid
, GameObjectData
const* data
)
1402 uint8 mask
= data
->spawnMask
;
1403 for(uint8 i
= 0; mask
!= 0; i
++, mask
>>= 1)
1407 CellPair cell_pair
= MaNGOS::ComputeCellPair(data
->posX
, data
->posY
);
1408 uint32 cell_id
= (cell_pair
.y_coord
*TOTAL_NUMBER_OF_CELLS_PER_MAP
) + cell_pair
.x_coord
;
1410 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(data
->mapid
,i
)][cell_id
];
1411 cell_guids
.gameobjects
.erase(guid
);
1416 void ObjectMgr::LoadCreatureRespawnTimes()
1418 // remove outdated data
1419 WorldDatabase
.DirectExecute("DELETE FROM creature_respawn WHERE respawntime <= UNIX_TIMESTAMP(NOW())");
1423 QueryResult
*result
= WorldDatabase
.Query("SELECT guid,respawntime,instance FROM creature_respawn");
1432 sLog
.outString(">> Loaded 0 creature respawn time.");
1436 barGoLink
bar(result
->GetRowCount());
1440 Field
*fields
= result
->Fetch();
1443 uint32 loguid
= fields
[0].GetUInt32();
1444 uint64 respawn_time
= fields
[1].GetUInt64();
1445 uint32 instance
= fields
[2].GetUInt32();
1447 mCreatureRespawnTimes
[MAKE_PAIR64(loguid
,instance
)] = time_t(respawn_time
);
1450 } while (result
->NextRow());
1454 sLog
.outString( ">> Loaded %lu creature respawn times", (unsigned long)mCreatureRespawnTimes
.size() );
1458 void ObjectMgr::LoadGameobjectRespawnTimes()
1460 // remove outdated data
1461 WorldDatabase
.DirectExecute("DELETE FROM gameobject_respawn WHERE respawntime <= UNIX_TIMESTAMP(NOW())");
1465 QueryResult
*result
= WorldDatabase
.Query("SELECT guid,respawntime,instance FROM gameobject_respawn");
1474 sLog
.outString(">> Loaded 0 gameobject respawn time.");
1478 barGoLink
bar(result
->GetRowCount());
1482 Field
*fields
= result
->Fetch();
1485 uint32 loguid
= fields
[0].GetUInt32();
1486 uint64 respawn_time
= fields
[1].GetUInt64();
1487 uint32 instance
= fields
[2].GetUInt32();
1489 mGORespawnTimes
[MAKE_PAIR64(loguid
,instance
)] = time_t(respawn_time
);
1492 } while (result
->NextRow());
1496 sLog
.outString( ">> Loaded %lu gameobject respawn times", (unsigned long)mGORespawnTimes
.size() );
1500 // name must be checked to correctness (if received) before call this function
1501 uint64
ObjectMgr::GetPlayerGUIDByName(std::string name
) const
1505 CharacterDatabase
.escape_string(name
);
1507 // Player name safe to sending to DB (checked at login) and this function using
1508 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT guid FROM characters WHERE name = '%s'", name
.c_str());
1511 guid
= MAKE_NEW_GUID((*result
)[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
1519 bool ObjectMgr::GetPlayerNameByGUID(const uint64
&guid
, std::string
&name
) const
1521 // prevent DB access for online player
1522 if(Player
* player
= GetPlayer(guid
))
1524 name
= player
->GetName();
1528 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT name FROM characters WHERE guid = '%u'", GUID_LOPART(guid
));
1532 name
= (*result
)[0].GetCppString();
1540 uint32
ObjectMgr::GetPlayerTeamByGUID(const uint64
&guid
) const
1542 // prevent DB access for online player
1543 if(Player
* player
= GetPlayer(guid
))
1545 return Player::TeamForRace(player
->getRace());
1548 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT race FROM characters WHERE guid = '%u'", GUID_LOPART(guid
));
1552 uint8 race
= (*result
)[0].GetUInt8();
1554 return Player::TeamForRace(race
);
1560 uint32
ObjectMgr::GetPlayerAccountIdByGUID(const uint64
&guid
) const
1562 // prevent DB access for online player
1563 if(Player
* player
= GetPlayer(guid
))
1565 return player
->GetSession()->GetAccountId();
1568 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE guid = '%u'", GUID_LOPART(guid
));
1571 uint32 acc
= (*result
)[0].GetUInt32();
1579 uint32
ObjectMgr::GetPlayerAccountIdByPlayerName(const std::string
& name
) const
1581 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name = '%s'", name
.c_str());
1584 uint32 acc
= (*result
)[0].GetUInt32();
1592 void ObjectMgr::LoadItemLocales()
1594 mItemLocaleMap
.clear(); // need for reload case
1596 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");
1605 sLog
.outString(">> Loaded 0 Item locale strings. DB table `locales_item` is empty.");
1609 barGoLink
bar(result
->GetRowCount());
1613 Field
*fields
= result
->Fetch();
1616 uint32 entry
= fields
[0].GetUInt32();
1618 ItemLocale
& data
= mItemLocaleMap
[entry
];
1620 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
1622 std::string str
= fields
[1+2*(i
-1)].GetCppString();
1625 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
1628 if(data
.Name
.size() <= idx
)
1629 data
.Name
.resize(idx
+1);
1631 data
.Name
[idx
] = str
;
1635 str
= fields
[1+2*(i
-1)+1].GetCppString();
1638 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
1641 if(data
.Description
.size() <= idx
)
1642 data
.Description
.resize(idx
+1);
1644 data
.Description
[idx
] = str
;
1648 } while (result
->NextRow());
1653 sLog
.outString( ">> Loaded %lu Item locale strings", (unsigned long)mItemLocaleMap
.size() );
1656 struct SQLItemLoader
: public SQLStorageLoaderBase
<SQLItemLoader
>
1659 void convert_from_str(uint32
/*field_pos*/, char *src
, D
&dst
)
1661 dst
= D(sObjectMgr
.GetScriptId(src
));
1665 void ObjectMgr::LoadItemPrototypes()
1667 SQLItemLoader loader
;
1668 loader
.Load(sItemStorage
);
1669 sLog
.outString( ">> Loaded %u item prototypes", sItemStorage
.RecordCount
);
1672 // check data correctness
1673 for(uint32 i
= 1; i
< sItemStorage
.MaxEntry
; ++i
)
1675 ItemPrototype
const* proto
= sItemStorage
.LookupEntry
<ItemPrototype
>(i
);
1676 ItemEntry
const *dbcitem
= sItemStore
.LookupEntry(i
);
1679 /* to many errors, and possible not all items really used in game
1681 sLog.outErrorDb("Item (Entry: %u) doesn't exists in DB, but must exist.",i);
1688 if(proto
->Class
!= dbcitem
->Class
)
1690 sLog
.outErrorDb("Item (Entry: %u) not correct class %u, must be %u (still using DB value).",i
,proto
->Class
,dbcitem
->Class
);
1691 // It safe let use Class from DB
1693 /* disabled: have some strange wrong cases for Subclass values.
1694 for enable also uncomment Subclass field in ItemEntry structure and in Itemfmt[]
1695 if(proto->SubClass != dbcitem->SubClass)
1697 sLog.outErrorDb("Item (Entry: %u) not correct (Class: %u, Sub: %u) pair, must be (Class: %u, Sub: %u) (still using DB value).",i,proto->Class,proto->SubClass,dbcitem->Class,dbcitem->SubClass);
1698 // It safe let use Subclass from DB
1702 if(proto
->Unk0
!= dbcitem
->Unk0
)
1704 sLog
.outErrorDb("Item (Entry: %u) not correct %i Unk0, must be %i (still using DB value).",i
,proto
->Unk0
,dbcitem
->Unk0
);
1705 // It safe let use Unk0 from DB
1708 if(proto
->Material
!= dbcitem
->Material
)
1710 sLog
.outErrorDb("Item (Entry: %u) not correct %i material, must be %i (still using DB value).",i
,proto
->Material
,dbcitem
->Material
);
1711 // It safe let use Material from DB
1714 if(proto
->InventoryType
!= dbcitem
->InventoryType
)
1716 sLog
.outErrorDb("Item (Entry: %u) not correct %u inventory type, must be %u (still using DB value).",i
,proto
->InventoryType
,dbcitem
->InventoryType
);
1717 // It safe let use InventoryType from DB
1720 if(proto
->DisplayInfoID
!= dbcitem
->DisplayId
)
1722 sLog
.outErrorDb("Item (Entry: %u) not correct %u display id, must be %u (using it).",i
,proto
->DisplayInfoID
,dbcitem
->DisplayId
);
1723 const_cast<ItemPrototype
*>(proto
)->DisplayInfoID
= dbcitem
->DisplayId
;
1725 if(proto
->Sheath
!= dbcitem
->Sheath
)
1727 sLog
.outErrorDb("Item (Entry: %u) not correct %u sheath, must be %u (using it).",i
,proto
->Sheath
,dbcitem
->Sheath
);
1728 const_cast<ItemPrototype
*>(proto
)->Sheath
= dbcitem
->Sheath
;
1733 sLog
.outErrorDb("Item (Entry: %u) not correct (not listed in list of existed items).",i
);
1736 if(proto
->Class
>= MAX_ITEM_CLASS
)
1738 sLog
.outErrorDb("Item (Entry: %u) has wrong Class value (%u)",i
,proto
->Class
);
1739 const_cast<ItemPrototype
*>(proto
)->Class
= ITEM_CLASS_MISC
;
1742 if(proto
->SubClass
>= MaxItemSubclassValues
[proto
->Class
])
1744 sLog
.outErrorDb("Item (Entry: %u) has wrong Subclass value (%u) for class %u",i
,proto
->SubClass
,proto
->Class
);
1745 const_cast<ItemPrototype
*>(proto
)->SubClass
= 0;// exist for all item classes
1748 if(proto
->Quality
>= MAX_ITEM_QUALITY
)
1750 sLog
.outErrorDb("Item (Entry: %u) has wrong Quality value (%u)",i
,proto
->Quality
);
1751 const_cast<ItemPrototype
*>(proto
)->Quality
= ITEM_QUALITY_NORMAL
;
1754 if(proto
->BuyCount
<= 0)
1756 sLog
.outErrorDb("Item (Entry: %u) has wrong BuyCount value (%u), set to default(1).",i
,proto
->BuyCount
);
1757 const_cast<ItemPrototype
*>(proto
)->BuyCount
= 1;
1760 if(proto
->InventoryType
>= MAX_INVTYPE
)
1762 sLog
.outErrorDb("Item (Entry: %u) has wrong InventoryType value (%u)",i
,proto
->InventoryType
);
1763 const_cast<ItemPrototype
*>(proto
)->InventoryType
= INVTYPE_NON_EQUIP
;
1766 if(proto
->RequiredSkill
>= MAX_SKILL_TYPE
)
1768 sLog
.outErrorDb("Item (Entry: %u) has wrong RequiredSkill value (%u)",i
,proto
->RequiredSkill
);
1769 const_cast<ItemPrototype
*>(proto
)->RequiredSkill
= 0;
1773 // can be used in equip slot, as page read use in inventory, or spell casting at use
1774 bool req
= proto
->InventoryType
!=INVTYPE_NON_EQUIP
|| proto
->PageText
;
1777 for (int j
= 0; j
< MAX_ITEM_PROTO_SPELLS
; ++j
)
1779 if(proto
->Spells
[j
].SpellId
)
1789 if(!(proto
->AllowableClass
& CLASSMASK_ALL_PLAYABLE
))
1790 sLog
.outErrorDb("Item (Entry: %u) not have in `AllowableClass` any playable classes (%u) and can't be equipped or use.",i
,proto
->AllowableClass
);
1792 if(!(proto
->AllowableRace
& RACEMASK_ALL_PLAYABLE
))
1793 sLog
.outErrorDb("Item (Entry: %u) not have in `AllowableRace` any playable races (%u) and can't be equipped or use.",i
,proto
->AllowableRace
);
1797 if(proto
->RequiredSpell
&& !sSpellStore
.LookupEntry(proto
->RequiredSpell
))
1799 sLog
.outErrorDb("Item (Entry: %u) have wrong (non-existed) spell in RequiredSpell (%u)",i
,proto
->RequiredSpell
);
1800 const_cast<ItemPrototype
*>(proto
)->RequiredSpell
= 0;
1803 if(proto
->RequiredReputationRank
>= MAX_REPUTATION_RANK
)
1804 sLog
.outErrorDb("Item (Entry: %u) has wrong reputation rank in RequiredReputationRank (%u), item can't be used.",i
,proto
->RequiredReputationRank
);
1806 if(proto
->RequiredReputationFaction
)
1808 if(!sFactionStore
.LookupEntry(proto
->RequiredReputationFaction
))
1810 sLog
.outErrorDb("Item (Entry: %u) has wrong (not existing) faction in RequiredReputationFaction (%u)",i
,proto
->RequiredReputationFaction
);
1811 const_cast<ItemPrototype
*>(proto
)->RequiredReputationFaction
= 0;
1814 if(proto
->RequiredReputationRank
== MIN_REPUTATION_RANK
)
1815 sLog
.outErrorDb("Item (Entry: %u) has min. reputation rank in RequiredReputationRank (0) but RequiredReputationFaction > 0, faction setting is useless.",i
);
1817 else if(proto
->RequiredReputationRank
> MIN_REPUTATION_RANK
)
1818 sLog
.outErrorDb("Item (Entry: %u) has RequiredReputationFaction ==0 but RequiredReputationRank > 0, rank setting is useless.",i
);
1820 if(proto
->MaxCount
< -1)
1822 sLog
.outErrorDb("Item (Entry: %u) has too large negative in maxcount (%i), replace by value (-1) no storing limits.",i
,proto
->MaxCount
);
1823 const_cast<ItemPrototype
*>(proto
)->MaxCount
= -1;
1826 if(proto
->Stackable
== 0)
1828 sLog
.outErrorDb("Item (Entry: %u) has wrong value in stackable (%i), replace by default 1.",i
,proto
->Stackable
);
1829 const_cast<ItemPrototype
*>(proto
)->Stackable
= 1;
1831 else if(proto
->Stackable
< -1)
1833 sLog
.outErrorDb("Item (Entry: %u) has too large negative in stackable (%i), replace by value (-1) no stacking limits.",i
,proto
->Stackable
);
1834 const_cast<ItemPrototype
*>(proto
)->Stackable
= -1;
1836 else if(proto
->Stackable
> 1000)
1838 sLog
.outErrorDb("Item (Entry: %u) has too large value in stackable (%u), replace by hardcoded upper limit (1000).",i
,proto
->Stackable
);
1839 const_cast<ItemPrototype
*>(proto
)->Stackable
= 1000;
1842 if(proto
->ContainerSlots
> MAX_BAG_SIZE
)
1844 sLog
.outErrorDb("Item (Entry: %u) has too large value in ContainerSlots (%u), replace by hardcoded limit (%u).",i
,proto
->ContainerSlots
,MAX_BAG_SIZE
);
1845 const_cast<ItemPrototype
*>(proto
)->ContainerSlots
= MAX_BAG_SIZE
;
1848 if(proto
->StatsCount
> MAX_ITEM_PROTO_STATS
)
1850 sLog
.outErrorDb("Item (Entry: %u) has too large value in statscount (%u), replace by hardcoded limit (%u).",i
,proto
->StatsCount
,MAX_ITEM_PROTO_STATS
);
1851 const_cast<ItemPrototype
*>(proto
)->StatsCount
= MAX_ITEM_PROTO_STATS
;
1854 for (int j
= 0; j
< MAX_ITEM_PROTO_STATS
; ++j
)
1856 // for ItemStatValue != 0
1857 if(proto
->ItemStat
[j
].ItemStatValue
&& proto
->ItemStat
[j
].ItemStatType
>= MAX_ITEM_MOD
)
1859 sLog
.outErrorDb("Item (Entry: %u) has wrong stat_type%d (%u)",i
,j
+1,proto
->ItemStat
[j
].ItemStatType
);
1860 const_cast<ItemPrototype
*>(proto
)->ItemStat
[j
].ItemStatType
= 0;
1863 switch(proto
->ItemStat
[j
].ItemStatType
)
1865 case ITEM_MOD_SPELL_HEALING_DONE
:
1866 case ITEM_MOD_SPELL_DAMAGE_DONE
:
1867 sLog
.outErrorDb("Item (Entry: %u) has deprecated stat_type%d (%u)",i
,j
+1,proto
->ItemStat
[j
].ItemStatType
);
1874 for (int j
= 0; j
< MAX_ITEM_PROTO_DAMAGES
; ++j
)
1876 if(proto
->Damage
[j
].DamageType
>= MAX_SPELL_SCHOOL
)
1878 sLog
.outErrorDb("Item (Entry: %u) has wrong dmg_type%d (%u)",i
,j
+1,proto
->Damage
[j
].DamageType
);
1879 const_cast<ItemPrototype
*>(proto
)->Damage
[j
].DamageType
= 0;
1884 if((proto
->Spells
[0].SpellId
== SPELL_ID_GENERIC_LEARN
) || (proto
->Spells
[0].SpellId
== SPELL_ID_GENERIC_LEARN_PET
))
1887 if(proto
->Spells
[0].SpellTrigger
!= ITEM_SPELLTRIGGER_ON_USE
)
1889 sLog
.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u) for special learning format",i
,0+1,proto
->Spells
[0].SpellTrigger
);
1890 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1891 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1892 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellId
= 0;
1893 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1896 // spell_2 have learning spell
1897 if(proto
->Spells
[1].SpellTrigger
!= ITEM_SPELLTRIGGER_LEARN_SPELL_ID
)
1899 sLog
.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u) for special learning format.",i
,1+1,proto
->Spells
[1].SpellTrigger
);
1900 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1901 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellId
= 0;
1902 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1904 else if(!proto
->Spells
[1].SpellId
)
1906 sLog
.outErrorDb("Item (Entry: %u) not has expected spell in spellid_%d in special learning format.",i
,1+1);
1907 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1908 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1912 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(proto
->Spells
[1].SpellId
);
1915 sLog
.outErrorDb("Item (Entry: %u) has wrong (not existing) spell in spellid_%d (%u)",i
,1+1,proto
->Spells
[1].SpellId
);
1916 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1917 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellId
= 0;
1918 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1920 // allowed only in special format
1921 else if((proto
->Spells
[1].SpellId
==SPELL_ID_GENERIC_LEARN
) || (proto
->Spells
[1].SpellId
==SPELL_ID_GENERIC_LEARN_PET
))
1923 sLog
.outErrorDb("Item (Entry: %u) has broken spell in spellid_%d (%u)",i
,1+1,proto
->Spells
[1].SpellId
);
1924 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1925 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellId
= 0;
1926 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1930 // spell_3*,spell_4*,spell_5* is empty
1931 for (int j
= 2; j
< MAX_ITEM_PROTO_SPELLS
; ++j
)
1933 if(proto
->Spells
[j
].SpellTrigger
!= ITEM_SPELLTRIGGER_ON_USE
)
1935 sLog
.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u)",i
,j
+1,proto
->Spells
[j
].SpellTrigger
);
1936 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1937 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1939 else if(proto
->Spells
[j
].SpellId
!= 0)
1941 sLog
.outErrorDb("Item (Entry: %u) has wrong spell in spellid_%d (%u) for learning special format",i
,j
+1,proto
->Spells
[j
].SpellId
);
1942 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1946 // normal spell list
1949 for (int j
= 0; j
< MAX_ITEM_PROTO_SPELLS
; ++j
)
1951 if (proto
->Spells
[j
].SpellTrigger
>= MAX_ITEM_SPELLTRIGGER
|| proto
->Spells
[j
].SpellTrigger
== ITEM_SPELLTRIGGER_LEARN_SPELL_ID
)
1953 sLog
.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u)",i
,j
+1,proto
->Spells
[j
].SpellTrigger
);
1954 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1955 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1957 // on hit can be sued only at weapon
1958 else if (proto
->Spells
[j
].SpellTrigger
== ITEM_SPELLTRIGGER_CHANCE_ON_HIT
)
1960 if(proto
->Class
!= ITEM_CLASS_WEAPON
)
1961 sLog
.outErrorDb("Item (Entry: %u) isn't weapon (Class: %u) but has on hit spelltrigger_%d (%u), it will not triggered.",i
,proto
->Class
,j
+1,proto
->Spells
[j
].SpellTrigger
);
1964 if(proto
->Spells
[j
].SpellId
)
1966 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(proto
->Spells
[j
].SpellId
);
1969 sLog
.outErrorDb("Item (Entry: %u) has wrong (not existing) spell in spellid_%d (%u)",i
,j
+1,proto
->Spells
[j
].SpellId
);
1970 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1972 // allowed only in special format
1973 else if((proto
->Spells
[j
].SpellId
==SPELL_ID_GENERIC_LEARN
) || (proto
->Spells
[j
].SpellId
==SPELL_ID_GENERIC_LEARN_PET
))
1975 sLog
.outErrorDb("Item (Entry: %u) has broken spell in spellid_%d (%u)",i
,j
+1,proto
->Spells
[j
].SpellId
);
1976 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1982 if(proto
->Bonding
>= MAX_BIND_TYPE
)
1983 sLog
.outErrorDb("Item (Entry: %u) has wrong Bonding value (%u)",i
,proto
->Bonding
);
1985 if(proto
->PageText
&& !sPageTextStore
.LookupEntry
<PageText
>(proto
->PageText
))
1986 sLog
.outErrorDb("Item (Entry: %u) has non existing first page (Id:%u)", i
,proto
->PageText
);
1988 if(proto
->LockID
&& !sLockStore
.LookupEntry(proto
->LockID
))
1989 sLog
.outErrorDb("Item (Entry: %u) has wrong LockID (%u)",i
,proto
->LockID
);
1991 if(proto
->Sheath
>= MAX_SHEATHETYPE
)
1993 sLog
.outErrorDb("Item (Entry: %u) has wrong Sheath (%u)",i
,proto
->Sheath
);
1994 const_cast<ItemPrototype
*>(proto
)->Sheath
= SHEATHETYPE_NONE
;
1997 if(proto
->RandomProperty
&& !sItemRandomPropertiesStore
.LookupEntry(GetItemEnchantMod(proto
->RandomProperty
)))
1999 sLog
.outErrorDb("Item (Entry: %u) has unknown (wrong or not listed in `item_enchantment_template`) RandomProperty (%u)",i
,proto
->RandomProperty
);
2000 const_cast<ItemPrototype
*>(proto
)->RandomProperty
= 0;
2003 if(proto
->RandomSuffix
&& !sItemRandomSuffixStore
.LookupEntry(GetItemEnchantMod(proto
->RandomSuffix
)))
2005 sLog
.outErrorDb("Item (Entry: %u) has wrong RandomSuffix (%u)",i
,proto
->RandomSuffix
);
2006 const_cast<ItemPrototype
*>(proto
)->RandomSuffix
= 0;
2009 if(proto
->ItemSet
&& !sItemSetStore
.LookupEntry(proto
->ItemSet
))
2011 sLog
.outErrorDb("Item (Entry: %u) have wrong ItemSet (%u)",i
,proto
->ItemSet
);
2012 const_cast<ItemPrototype
*>(proto
)->ItemSet
= 0;
2015 if(proto
->Area
&& !GetAreaEntryByAreaID(proto
->Area
))
2016 sLog
.outErrorDb("Item (Entry: %u) has wrong Area (%u)",i
,proto
->Area
);
2018 if(proto
->Map
&& !sMapStore
.LookupEntry(proto
->Map
))
2019 sLog
.outErrorDb("Item (Entry: %u) has wrong Map (%u)",i
,proto
->Map
);
2021 if(proto
->BagFamily
)
2024 for(uint32 j
= 0; j
< sizeof(proto
->BagFamily
)*8; ++j
)
2026 uint32 mask
= 1 << j
;
2027 if((proto
->BagFamily
& mask
)==0)
2030 ItemBagFamilyEntry
const* bf
= sItemBagFamilyStore
.LookupEntry(j
+1);
2033 sLog
.outErrorDb("Item (Entry: %u) has bag family bit set not listed in ItemBagFamily.dbc, remove bit",i
);
2034 const_cast<ItemPrototype
*>(proto
)->BagFamily
&= ~mask
;
2038 if(BAG_FAMILY_MASK_CURRENCY_TOKENS
& mask
)
2040 CurrencyTypesEntry
const* ctEntry
= sCurrencyTypesStore
.LookupEntry(proto
->ItemId
);
2043 sLog
.outErrorDb("Item (Entry: %u) has currency bag family bit set in BagFamily but not listed in CurrencyTypes.dbc, remove bit",i
);
2044 const_cast<ItemPrototype
*>(proto
)->BagFamily
&= ~mask
;
2050 if(proto
->TotemCategory
&& !sTotemCategoryStore
.LookupEntry(proto
->TotemCategory
))
2051 sLog
.outErrorDb("Item (Entry: %u) has wrong TotemCategory (%u)",i
,proto
->TotemCategory
);
2053 for (int j
= 0; j
< MAX_ITEM_PROTO_SOCKETS
; ++j
)
2055 if(proto
->Socket
[j
].Color
&& (proto
->Socket
[j
].Color
& SOCKET_COLOR_ALL
) != proto
->Socket
[j
].Color
)
2057 sLog
.outErrorDb("Item (Entry: %u) has wrong socketColor_%d (%u)",i
,j
+1,proto
->Socket
[j
].Color
);
2058 const_cast<ItemPrototype
*>(proto
)->Socket
[j
].Color
= 0;
2062 if(proto
->GemProperties
&& !sGemPropertiesStore
.LookupEntry(proto
->GemProperties
))
2063 sLog
.outErrorDb("Item (Entry: %u) has wrong GemProperties (%u)",i
,proto
->GemProperties
);
2065 if(proto
->FoodType
>= MAX_PET_DIET
)
2067 sLog
.outErrorDb("Item (Entry: %u) has wrong FoodType value (%u)",i
,proto
->FoodType
);
2068 const_cast<ItemPrototype
*>(proto
)->FoodType
= 0;
2071 if(proto
->ItemLimitCategory
&& !sItemLimitCategoryStore
.LookupEntry(proto
->ItemLimitCategory
))
2073 sLog
.outErrorDb("Item (Entry: %u) has wrong LimitCategory value (%u)",i
,proto
->ItemLimitCategory
);
2074 const_cast<ItemPrototype
*>(proto
)->ItemLimitCategory
= 0;
2077 if(proto
->HolidayId
&& !sHolidaysStore
.LookupEntry(proto
->HolidayId
))
2079 sLog
.outErrorDb("Item (Entry: %u) has wrong HolidayId value (%u)", i
, proto
->HolidayId
);
2080 const_cast<ItemPrototype
*>(proto
)->HolidayId
= 0;
2084 // check some dbc referenced items (avoid duplicate reports)
2085 std::set
<uint32
> notFoundOutfit
;
2086 for (uint32 i
= 1; i
< sCharStartOutfitStore
.GetNumRows(); ++i
)
2088 CharStartOutfitEntry
const* entry
= sCharStartOutfitStore
.LookupEntry(i
);
2092 for(int j
= 0; j
< MAX_OUTFIT_ITEMS
; ++j
)
2094 if(entry
->ItemId
[j
] <= 0)
2097 uint32 item_id
= entry
->ItemId
[j
];
2099 if(!GetItemPrototype(item_id
))
2100 notFoundOutfit
.insert(item_id
);
2104 for(std::set
<uint32
>::const_iterator itr
= notFoundOutfit
.begin(); itr
!= notFoundOutfit
.end(); ++itr
)
2105 sLog
.outErrorDb("Item (Entry: %u) not exist in `item_template` but referenced in `CharStartOutfit.dbc`", *itr
);
2108 void ObjectMgr::LoadItemRequiredTarget()
2110 m_ItemRequiredTarget
.clear(); // needed for reload case
2114 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,type,targetEntry FROM item_required_target");
2123 sLog
.outErrorDb(">> Loaded 0 ItemRequiredTarget. DB table `item_required_target` is empty.");
2127 barGoLink
bar(result
->GetRowCount());
2131 Field
*fields
= result
->Fetch();
2134 uint32 uiItemId
= fields
[0].GetUInt32();
2135 uint32 uiType
= fields
[1].GetUInt32();
2136 uint32 uiTargetEntry
= fields
[2].GetUInt32();
2138 ItemPrototype
const* pItemProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(uiItemId
);
2142 sLog
.outErrorDb("Table `item_required_target`: Entry %u listed for TargetEntry %u does not exist in `item_template`.",uiItemId
,uiTargetEntry
);
2146 bool bIsItemSpellValid
= false;
2148 for(int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
2150 if (SpellEntry
const* pSpellInfo
= sSpellStore
.LookupEntry(pItemProto
->Spells
[i
].SpellId
))
2152 if (pItemProto
->Spells
[i
].SpellTrigger
== ITEM_SPELLTRIGGER_ON_USE
||
2153 pItemProto
->Spells
[i
].SpellTrigger
== ITEM_SPELLTRIGGER_ON_NO_DELAY_USE
)
2155 SpellScriptTargetBounds bounds
= sSpellMgr
.GetSpellScriptTargetBounds(pSpellInfo
->Id
);
2156 if (bounds
.first
!= bounds
.second
)
2159 for (int j
= 0; j
< 3; ++j
)
2161 if (pSpellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
||
2162 pSpellInfo
->EffectImplicitTargetB
[j
] == TARGET_CHAIN_DAMAGE
||
2163 pSpellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
||
2164 pSpellInfo
->EffectImplicitTargetB
[j
] == TARGET_DUELVSPLAYER
)
2166 bIsItemSpellValid
= true;
2170 if (bIsItemSpellValid
)
2176 if (!bIsItemSpellValid
)
2178 sLog
.outErrorDb("Table `item_required_target`: Spell used by item %u does not have implicit target TARGET_CHAIN_DAMAGE(6), TARGET_DUELVSPLAYER(25), already listed in `spell_script_target` or doesn't have item spelltrigger.",uiItemId
);
2182 if (!uiType
|| uiType
> MAX_ITEM_REQ_TARGET_TYPE
)
2184 sLog
.outErrorDb("Table `item_required_target`: Type %u for TargetEntry %u is incorrect.",uiType
,uiTargetEntry
);
2190 sLog
.outErrorDb("Table `item_required_target`: TargetEntry == 0 for Type (%u).",uiType
);
2194 if (!sCreatureStorage
.LookupEntry
<CreatureInfo
>(uiTargetEntry
))
2196 sLog
.outErrorDb("Table `item_required_target`: creature template entry %u does not exist.",uiTargetEntry
);
2200 m_ItemRequiredTarget
.insert(ItemRequiredTargetMap::value_type(uiItemId
,ItemRequiredTarget(ItemRequiredTargetType(uiType
),uiTargetEntry
)));
2203 } while (result
->NextRow());
2208 sLog
.outString(">> Loaded %u Item required targets", count
);
2211 void ObjectMgr::LoadPetLevelInfo()
2213 // Loading levels data
2215 // 0 1 2 3 4 5 6 7 8 9
2216 QueryResult
*result
= WorldDatabase
.Query("SELECT creature_entry, level, hp, mana, str, agi, sta, inte, spi, armor FROM pet_levelstats");
2226 sLog
.outString(">> Loaded %u level pet stats definitions", count
);
2227 sLog
.outErrorDb("Error loading `pet_levelstats` table or empty table.");
2231 barGoLink
bar( result
->GetRowCount() );
2235 Field
* fields
= result
->Fetch();
2237 uint32 creature_id
= fields
[0].GetUInt32();
2238 if(!sCreatureStorage
.LookupEntry
<CreatureInfo
>(creature_id
))
2240 sLog
.outErrorDb("Wrong creature id %u in `pet_levelstats` table, ignoring.",creature_id
);
2244 uint32 current_level
= fields
[1].GetUInt32();
2245 if(current_level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2247 if(current_level
> STRONG_MAX_LEVEL
) // hardcoded level maximum
2248 sLog
.outErrorDb("Wrong (> %u) level %u in `pet_levelstats` table, ignoring.",STRONG_MAX_LEVEL
,current_level
);
2251 sLog
.outDetail("Unused (> MaxPlayerLevel in mangosd.conf) level %u in `pet_levelstats` table, ignoring.",current_level
);
2252 ++count
; // make result loading percent "expected" correct in case disabled detail mode for example.
2256 else if(current_level
< 1)
2258 sLog
.outErrorDb("Wrong (<1) level %u in `pet_levelstats` table, ignoring.",current_level
);
2262 PetLevelInfo
*& pInfoMapEntry
= petInfo
[creature_id
];
2264 if(pInfoMapEntry
==NULL
)
2265 pInfoMapEntry
= new PetLevelInfo
[sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)];
2267 // data for level 1 stored in [0] array element, ...
2268 PetLevelInfo
* pLevelInfo
= &pInfoMapEntry
[current_level
-1];
2270 pLevelInfo
->health
= fields
[2].GetUInt16();
2271 pLevelInfo
->mana
= fields
[3].GetUInt16();
2272 pLevelInfo
->armor
= fields
[9].GetUInt16();
2274 for (int i
= 0; i
< MAX_STATS
; i
++)
2276 pLevelInfo
->stats
[i
] = fields
[i
+4].GetUInt16();
2282 while (result
->NextRow());
2287 sLog
.outString( ">> Loaded %u level pet stats definitions", count
);
2290 // Fill gaps and check integrity
2291 for (PetLevelInfoMap::iterator itr
= petInfo
.begin(); itr
!= petInfo
.end(); ++itr
)
2293 PetLevelInfo
* pInfo
= itr
->second
;
2295 // fatal error if no level 1 data
2296 if(!pInfo
|| pInfo
[0].health
== 0 )
2298 sLog
.outErrorDb("Creature %u does not have pet stats data for Level 1!",itr
->first
);
2303 for (uint32 level
= 1; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2305 if(pInfo
[level
].health
== 0)
2307 sLog
.outErrorDb("Creature %u has no data for Level %i pet stats data, using data of Level %i.",itr
->first
,level
+1, level
);
2308 pInfo
[level
] = pInfo
[level
-1];
2314 PetLevelInfo
const* ObjectMgr::GetPetLevelInfo(uint32 creature_id
, uint32 level
) const
2316 if(level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2317 level
= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
);
2319 PetLevelInfoMap::const_iterator itr
= petInfo
.find(creature_id
);
2320 if(itr
== petInfo
.end())
2323 return &itr
->second
[level
-1]; // data for level 1 stored in [0] array element, ...
2326 void ObjectMgr::LoadPlayerInfo()
2328 // Load playercreate
2331 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, map, zone, position_x, position_y, position_z FROM playercreateinfo");
2340 sLog
.outString( ">> Loaded %u player create definitions", count
);
2341 sLog
.outErrorDb( "Error loading `playercreateinfo` table or empty table.");
2345 barGoLink
bar( result
->GetRowCount() );
2349 Field
* fields
= result
->Fetch();
2351 uint32 current_race
= fields
[0].GetUInt32();
2352 uint32 current_class
= fields
[1].GetUInt32();
2353 uint32 mapId
= fields
[2].GetUInt32();
2354 uint32 zoneId
= fields
[3].GetUInt32();
2355 float positionX
= fields
[4].GetFloat();
2356 float positionY
= fields
[5].GetFloat();
2357 float positionZ
= fields
[6].GetFloat();
2359 if(current_race
>= MAX_RACES
)
2361 sLog
.outErrorDb("Wrong race %u in `playercreateinfo` table, ignoring.",current_race
);
2365 ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(current_race
);
2368 sLog
.outErrorDb("Wrong race %u in `playercreateinfo` table, ignoring.",current_race
);
2372 if(current_class
>= MAX_CLASSES
)
2374 sLog
.outErrorDb("Wrong class %u in `playercreateinfo` table, ignoring.",current_class
);
2378 if(!sChrClassesStore
.LookupEntry(current_class
))
2380 sLog
.outErrorDb("Wrong class %u in `playercreateinfo` table, ignoring.",current_class
);
2384 // accept DB data only for valid position (and non instanceable)
2385 if( !MapManager::IsValidMapCoord(mapId
,positionX
,positionY
,positionZ
) )
2387 sLog
.outErrorDb("Wrong home position for class %u race %u pair in `playercreateinfo` table, ignoring.",current_class
,current_race
);
2391 if( sMapStore
.LookupEntry(mapId
)->Instanceable() )
2393 sLog
.outErrorDb("Home position in instanceable map for class %u race %u pair in `playercreateinfo` table, ignoring.",current_class
,current_race
);
2397 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2399 pInfo
->mapId
= mapId
;
2400 pInfo
->zoneId
= zoneId
;
2401 pInfo
->positionX
= positionX
;
2402 pInfo
->positionY
= positionY
;
2403 pInfo
->positionZ
= positionZ
;
2405 pInfo
->displayId_m
= rEntry
->model_m
;
2406 pInfo
->displayId_f
= rEntry
->model_f
;
2411 while (result
->NextRow());
2416 sLog
.outString( ">> Loaded %u player create definitions", count
);
2419 // Load playercreate items
2422 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, itemid, amount FROM playercreateinfo_item");
2433 sLog
.outString( ">> Loaded %u custom player create items", count
);
2437 barGoLink
bar( result
->GetRowCount() );
2441 Field
* fields
= result
->Fetch();
2443 uint32 current_race
= fields
[0].GetUInt32();
2444 if(current_race
>= MAX_RACES
)
2446 sLog
.outErrorDb("Wrong race %u in `playercreateinfo_item` table, ignoring.",current_race
);
2450 uint32 current_class
= fields
[1].GetUInt32();
2451 if(current_class
>= MAX_CLASSES
)
2453 sLog
.outErrorDb("Wrong class %u in `playercreateinfo_item` table, ignoring.",current_class
);
2457 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2459 uint32 item_id
= fields
[2].GetUInt32();
2461 if(!GetItemPrototype(item_id
))
2463 sLog
.outErrorDb("Item id %u (race %u class %u) in `playercreateinfo_item` table but not listed in `item_template`, ignoring.",item_id
,current_race
,current_class
);
2467 uint32 amount
= fields
[3].GetUInt32();
2471 sLog
.outErrorDb("Item id %u (class %u race %u) have amount==0 in `playercreateinfo_item` table, ignoring.",item_id
,current_race
,current_class
);
2475 pInfo
->item
.push_back(PlayerCreateInfoItem( item_id
, amount
));
2480 while(result
->NextRow());
2485 sLog
.outString( ">> Loaded %u custom player create items", count
);
2489 // Load playercreate spells
2492 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, Spell FROM playercreateinfo_spell");
2501 sLog
.outString( ">> Loaded %u player create spells", count
);
2502 sLog
.outErrorDb( "Error loading `playercreateinfo_spell` table or empty table.");
2506 barGoLink
bar( result
->GetRowCount() );
2510 Field
* fields
= result
->Fetch();
2512 uint32 current_race
= fields
[0].GetUInt32();
2513 if(current_race
>= MAX_RACES
)
2515 sLog
.outErrorDb("Wrong race %u in `playercreateinfo_spell` table, ignoring.",current_race
);
2519 uint32 current_class
= fields
[1].GetUInt32();
2520 if(current_class
>= MAX_CLASSES
)
2522 sLog
.outErrorDb("Wrong class %u in `playercreateinfo_spell` table, ignoring.",current_class
);
2526 uint32 spell_id
= fields
[2].GetUInt32();
2527 if (!sSpellStore
.LookupEntry(spell_id
))
2529 sLog
.outErrorDb("Non existing spell %u in `playercreateinfo_spell` table, ignoring.", spell_id
);
2533 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2534 pInfo
->spell
.push_back(spell_id
);
2539 while( result
->NextRow() );
2544 sLog
.outString( ">> Loaded %u player create spells", count
);
2548 // Load playercreate actions
2551 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, button, action, type FROM playercreateinfo_action");
2560 sLog
.outString( ">> Loaded %u player create actions", count
);
2561 sLog
.outErrorDb( "Error loading `playercreateinfo_action` table or empty table.");
2565 barGoLink
bar( result
->GetRowCount() );
2569 Field
* fields
= result
->Fetch();
2571 uint32 current_race
= fields
[0].GetUInt32();
2572 if(current_race
>= MAX_RACES
)
2574 sLog
.outErrorDb("Wrong race %u in `playercreateinfo_action` table, ignoring.",current_race
);
2578 uint32 current_class
= fields
[1].GetUInt32();
2579 if(current_class
>= MAX_CLASSES
)
2581 sLog
.outErrorDb("Wrong class %u in `playercreateinfo_action` table, ignoring.",current_class
);
2585 uint8 action_button
= fields
[2].GetUInt8();
2586 uint32 action
= fields
[3].GetUInt32();
2587 uint8 action_type
= fields
[4].GetUInt8();
2589 if (!Player::IsActionButtonDataValid(action_button
,action
,action_type
,NULL
))
2592 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2593 pInfo
->action
.push_back(PlayerCreateInfoAction(action_button
,action
,action_type
));
2598 while( result
->NextRow() );
2603 sLog
.outString( ">> Loaded %u player create actions", count
);
2607 // Loading levels data (class only dependent)
2610 QueryResult
*result
= WorldDatabase
.Query("SELECT class, level, basehp, basemana FROM player_classlevelstats");
2619 sLog
.outString( ">> Loaded %u level health/mana definitions", count
);
2620 sLog
.outErrorDb( "Error loading `player_classlevelstats` table or empty table.");
2624 barGoLink
bar( result
->GetRowCount() );
2628 Field
* fields
= result
->Fetch();
2630 uint32 current_class
= fields
[0].GetUInt32();
2631 if(current_class
>= MAX_CLASSES
)
2633 sLog
.outErrorDb("Wrong class %u in `player_classlevelstats` table, ignoring.",current_class
);
2637 uint32 current_level
= fields
[1].GetUInt32();
2638 if(current_level
== 0)
2640 sLog
.outErrorDb("Wrong level %u in `player_classlevelstats` table, ignoring.",current_level
);
2643 else if(current_level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2645 if(current_level
> STRONG_MAX_LEVEL
) // hardcoded level maximum
2646 sLog
.outErrorDb("Wrong (> %u) level %u in `player_classlevelstats` table, ignoring.",STRONG_MAX_LEVEL
,current_level
);
2649 sLog
.outDetail("Unused (> MaxPlayerLevel in mangosd.conf) level %u in `player_classlevelstats` table, ignoring.",current_level
);
2650 ++count
; // make result loading percent "expected" correct in case disabled detail mode for example.
2655 PlayerClassInfo
* pClassInfo
= &playerClassInfo
[current_class
];
2657 if(!pClassInfo
->levelInfo
)
2658 pClassInfo
->levelInfo
= new PlayerClassLevelInfo
[sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)];
2660 PlayerClassLevelInfo
* pClassLevelInfo
= &pClassInfo
->levelInfo
[current_level
-1];
2662 pClassLevelInfo
->basehealth
= fields
[2].GetUInt16();
2663 pClassLevelInfo
->basemana
= fields
[3].GetUInt16();
2668 while (result
->NextRow());
2673 sLog
.outString( ">> Loaded %u level health/mana definitions", count
);
2676 // Fill gaps and check integrity
2677 for (int class_
= 0; class_
< MAX_CLASSES
; ++class_
)
2679 // skip non existed classes
2680 if(!sChrClassesStore
.LookupEntry(class_
))
2683 PlayerClassInfo
* pClassInfo
= &playerClassInfo
[class_
];
2685 // fatal error if no level 1 data
2686 if(!pClassInfo
->levelInfo
|| pClassInfo
->levelInfo
[0].basehealth
== 0 )
2688 sLog
.outErrorDb("Class %i Level 1 does not have health/mana data!",class_
);
2693 for (uint32 level
= 1; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2695 if(pClassInfo
->levelInfo
[level
].basehealth
== 0)
2697 sLog
.outErrorDb("Class %i Level %i does not have health/mana data. Using stats data of level %i.",class_
,level
+1, level
);
2698 pClassInfo
->levelInfo
[level
] = pClassInfo
->levelInfo
[level
-1];
2703 // Loading levels data (class/race dependent)
2706 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, level, str, agi, sta, inte, spi FROM player_levelstats");
2715 sLog
.outString( ">> Loaded %u level stats definitions", count
);
2716 sLog
.outErrorDb( "Error loading `player_levelstats` table or empty table.");
2720 barGoLink
bar( result
->GetRowCount() );
2724 Field
* fields
= result
->Fetch();
2726 uint32 current_race
= fields
[0].GetUInt32();
2727 if(current_race
>= MAX_RACES
)
2729 sLog
.outErrorDb("Wrong race %u in `player_levelstats` table, ignoring.",current_race
);
2733 uint32 current_class
= fields
[1].GetUInt32();
2734 if(current_class
>= MAX_CLASSES
)
2736 sLog
.outErrorDb("Wrong class %u in `player_levelstats` table, ignoring.",current_class
);
2740 uint32 current_level
= fields
[2].GetUInt32();
2741 if(current_level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2743 if(current_level
> STRONG_MAX_LEVEL
) // hardcoded level maximum
2744 sLog
.outErrorDb("Wrong (> %u) level %u in `player_levelstats` table, ignoring.",STRONG_MAX_LEVEL
,current_level
);
2747 sLog
.outDetail("Unused (> MaxPlayerLevel in mangosd.conf) level %u in `player_levelstats` table, ignoring.",current_level
);
2748 ++count
; // make result loading percent "expected" correct in case disabled detail mode for example.
2753 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2755 if(!pInfo
->levelInfo
)
2756 pInfo
->levelInfo
= new PlayerLevelInfo
[sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)];
2758 PlayerLevelInfo
* pLevelInfo
= &pInfo
->levelInfo
[current_level
-1];
2760 for (int i
= 0; i
< MAX_STATS
; i
++)
2762 pLevelInfo
->stats
[i
] = fields
[i
+3].GetUInt8();
2768 while (result
->NextRow());
2773 sLog
.outString( ">> Loaded %u level stats definitions", count
);
2776 // Fill gaps and check integrity
2777 for (int race
= 0; race
< MAX_RACES
; ++race
)
2779 // skip non existed races
2780 if(!sChrRacesStore
.LookupEntry(race
))
2783 for (int class_
= 0; class_
< MAX_CLASSES
; ++class_
)
2785 // skip non existed classes
2786 if(!sChrClassesStore
.LookupEntry(class_
))
2789 PlayerInfo
* pInfo
= &playerInfo
[race
][class_
];
2791 // skip non loaded combinations
2792 if(!pInfo
->displayId_m
|| !pInfo
->displayId_f
)
2795 // skip expansion races if not playing with expansion
2796 if (sWorld
.getConfig(CONFIG_EXPANSION
) < 1 && (race
== RACE_BLOODELF
|| race
== RACE_DRAENEI
))
2799 // skip expansion classes if not playing with expansion
2800 if (sWorld
.getConfig(CONFIG_EXPANSION
) < 2 && class_
== CLASS_DEATH_KNIGHT
)
2803 // fatal error if no level 1 data
2804 if(!pInfo
->levelInfo
|| pInfo
->levelInfo
[0].stats
[0] == 0 )
2806 sLog
.outErrorDb("Race %i Class %i Level 1 does not have stats data!",race
,class_
);
2811 for (uint32 level
= 1; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2813 if(pInfo
->levelInfo
[level
].stats
[0] == 0)
2815 sLog
.outErrorDb("Race %i Class %i Level %i does not have stats data. Using stats data of level %i.",race
,class_
,level
+1, level
);
2816 pInfo
->levelInfo
[level
] = pInfo
->levelInfo
[level
-1];
2822 // Loading xp per level data
2824 mPlayerXPperLevel
.resize(sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
));
2825 for (uint32 level
= 0; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2826 mPlayerXPperLevel
[level
] = 0;
2829 QueryResult
*result
= WorldDatabase
.Query("SELECT lvl, xp_for_next_level FROM player_xp_for_level");
2838 sLog
.outString( ">> Loaded %u xp for level definitions", count
);
2839 sLog
.outErrorDb( "Error loading `player_xp_for_level` table or empty table.");
2843 barGoLink
bar( result
->GetRowCount() );
2847 Field
* fields
= result
->Fetch();
2849 uint32 current_level
= fields
[0].GetUInt32();
2850 uint32 current_xp
= fields
[1].GetUInt32();
2852 if(current_level
>= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2854 if(current_level
> STRONG_MAX_LEVEL
) // hardcoded level maximum
2855 sLog
.outErrorDb("Wrong (> %u) level %u in `player_xp_for_level` table, ignoring.", STRONG_MAX_LEVEL
,current_level
);
2858 sLog
.outDetail("Unused (> MaxPlayerLevel in mangosd.conf) level %u in `player_xp_for_levels` table, ignoring.",current_level
);
2859 ++count
; // make result loading percent "expected" correct in case disabled detail mode for example.
2864 mPlayerXPperLevel
[current_level
] = current_xp
;
2868 while (result
->NextRow());
2873 sLog
.outString( ">> Loaded %u xp for level definitions", count
);
2877 for (uint32 level
= 1; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2879 if( mPlayerXPperLevel
[level
] == 0)
2881 sLog
.outErrorDb("Level %i does not have XP for level data. Using data of level [%i] + 100.",level
+1, level
);
2882 mPlayerXPperLevel
[level
] = mPlayerXPperLevel
[level
-1]+100;
2887 void ObjectMgr::GetPlayerClassLevelInfo(uint32 class_
, uint32 level
, PlayerClassLevelInfo
* info
) const
2889 if(level
< 1 || class_
>= MAX_CLASSES
)
2892 PlayerClassInfo
const* pInfo
= &playerClassInfo
[class_
];
2894 if(level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2895 level
= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
);
2897 *info
= pInfo
->levelInfo
[level
-1];
2900 void ObjectMgr::GetPlayerLevelInfo(uint32 race
, uint32 class_
, uint32 level
, PlayerLevelInfo
* info
) const
2902 if(level
< 1 || race
>= MAX_RACES
|| class_
>= MAX_CLASSES
)
2905 PlayerInfo
const* pInfo
= &playerInfo
[race
][class_
];
2906 if(pInfo
->displayId_m
==0 || pInfo
->displayId_f
==0)
2909 if(level
<= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2910 *info
= pInfo
->levelInfo
[level
-1];
2912 BuildPlayerLevelInfo(race
,class_
,level
,info
);
2915 void ObjectMgr::BuildPlayerLevelInfo(uint8 race
, uint8 _class
, uint8 level
, PlayerLevelInfo
* info
) const
2917 // base data (last known level)
2918 *info
= playerInfo
[race
][_class
].levelInfo
[sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)-1];
2920 for(int lvl
= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)-1; lvl
< level
; ++lvl
)
2925 info
->stats
[STAT_STRENGTH
] += (lvl
> 23 ? 2: (lvl
> 1 ? 1: 0));
2926 info
->stats
[STAT_STAMINA
] += (lvl
> 23 ? 2: (lvl
> 1 ? 1: 0));
2927 info
->stats
[STAT_AGILITY
] += (lvl
> 36 ? 1: (lvl
> 6 && (lvl
%2) ? 1: 0));
2928 info
->stats
[STAT_INTELLECT
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2929 info
->stats
[STAT_SPIRIT
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2932 info
->stats
[STAT_STRENGTH
] += (lvl
> 3 ? 1: 0);
2933 info
->stats
[STAT_STAMINA
] += (lvl
> 33 ? 2: (lvl
> 1 ? 1: 0));
2934 info
->stats
[STAT_AGILITY
] += (lvl
> 38 ? 1: (lvl
> 7 && !(lvl
%2) ? 1: 0));
2935 info
->stats
[STAT_INTELLECT
] += (lvl
> 6 && (lvl
%2) ? 1: 0);
2936 info
->stats
[STAT_SPIRIT
] += (lvl
> 7 ? 1: 0);
2939 info
->stats
[STAT_STRENGTH
] += (lvl
> 4 ? 1: 0);
2940 info
->stats
[STAT_STAMINA
] += (lvl
> 4 ? 1: 0);
2941 info
->stats
[STAT_AGILITY
] += (lvl
> 33 ? 2: (lvl
> 1 ? 1: 0));
2942 info
->stats
[STAT_INTELLECT
] += (lvl
> 8 && (lvl
%2) ? 1: 0);
2943 info
->stats
[STAT_SPIRIT
] += (lvl
> 38 ? 1: (lvl
> 9 && !(lvl
%2) ? 1: 0));
2946 info
->stats
[STAT_STRENGTH
] += (lvl
> 5 ? 1: 0);
2947 info
->stats
[STAT_STAMINA
] += (lvl
> 4 ? 1: 0);
2948 info
->stats
[STAT_AGILITY
] += (lvl
> 16 ? 2: (lvl
> 1 ? 1: 0));
2949 info
->stats
[STAT_INTELLECT
] += (lvl
> 8 && !(lvl
%2) ? 1: 0);
2950 info
->stats
[STAT_SPIRIT
] += (lvl
> 38 ? 1: (lvl
> 9 && !(lvl
%2) ? 1: 0));
2953 info
->stats
[STAT_STRENGTH
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2954 info
->stats
[STAT_STAMINA
] += (lvl
> 5 ? 1: 0);
2955 info
->stats
[STAT_AGILITY
] += (lvl
> 38 ? 1: (lvl
> 8 && (lvl
%2) ? 1: 0));
2956 info
->stats
[STAT_INTELLECT
] += (lvl
> 22 ? 2: (lvl
> 1 ? 1: 0));
2957 info
->stats
[STAT_SPIRIT
] += (lvl
> 3 ? 1: 0);
2960 info
->stats
[STAT_STRENGTH
] += (lvl
> 34 ? 1: (lvl
> 6 && (lvl
%2) ? 1: 0));
2961 info
->stats
[STAT_STAMINA
] += (lvl
> 4 ? 1: 0);
2962 info
->stats
[STAT_AGILITY
] += (lvl
> 7 && !(lvl
%2) ? 1: 0);
2963 info
->stats
[STAT_INTELLECT
] += (lvl
> 5 ? 1: 0);
2964 info
->stats
[STAT_SPIRIT
] += (lvl
> 4 ? 1: 0);
2967 info
->stats
[STAT_STRENGTH
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2968 info
->stats
[STAT_STAMINA
] += (lvl
> 5 ? 1: 0);
2969 info
->stats
[STAT_AGILITY
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2970 info
->stats
[STAT_INTELLECT
] += (lvl
> 24 ? 2: (lvl
> 1 ? 1: 0));
2971 info
->stats
[STAT_SPIRIT
] += (lvl
> 33 ? 2: (lvl
> 2 ? 1: 0));
2974 info
->stats
[STAT_STRENGTH
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2975 info
->stats
[STAT_STAMINA
] += (lvl
> 38 ? 2: (lvl
> 3 ? 1: 0));
2976 info
->stats
[STAT_AGILITY
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2977 info
->stats
[STAT_INTELLECT
] += (lvl
> 33 ? 2: (lvl
> 2 ? 1: 0));
2978 info
->stats
[STAT_SPIRIT
] += (lvl
> 38 ? 2: (lvl
> 3 ? 1: 0));
2981 info
->stats
[STAT_STRENGTH
] += (lvl
> 38 ? 2: (lvl
> 6 && (lvl
%2) ? 1: 0));
2982 info
->stats
[STAT_STAMINA
] += (lvl
> 32 ? 2: (lvl
> 4 ? 1: 0));
2983 info
->stats
[STAT_AGILITY
] += (lvl
> 38 ? 2: (lvl
> 8 && (lvl
%2) ? 1: 0));
2984 info
->stats
[STAT_INTELLECT
] += (lvl
> 38 ? 3: (lvl
> 4 ? 1: 0));
2985 info
->stats
[STAT_SPIRIT
] += (lvl
> 38 ? 3: (lvl
> 5 ? 1: 0));
2990 void ObjectMgr::LoadGuilds()
2996 QueryResult
*result
= CharacterDatabase
.Query("SELECT guild.guildid,guild.name,leaderguid,EmblemStyle,EmblemColor,BorderStyle,BorderColor,"
2998 "BackgroundColor,info,motd,createdate,BankMoney,(SELECT COUNT(guild_bank_tab.guildid) FROM guild_bank_tab WHERE guild_bank_tab.guildid = guild.guildid) "
2999 "FROM guild ORDER BY guildid ASC");
3009 sLog
.outString( ">> Loaded %u guild definitions", count
);
3015 QueryResult
*guildRanksResult
= CharacterDatabase
.Query("SELECT guildid,rid,rname,rights,BankMoneyPerDay FROM guild_rank ORDER BY guildid ASC, rid ASC");
3017 // load guild members
3019 QueryResult
*guildMembersResult
= CharacterDatabase
.Query("SELECT guildid,guild_member.guid,rank,pnote,offnote,BankResetTimeMoney,BankRemMoney,"
3021 "BankResetTimeTab0,BankRemSlotsTab0,BankResetTimeTab1,BankRemSlotsTab1,BankResetTimeTab2,BankRemSlotsTab2,"
3022 // 13 14 15 16 17 18
3023 "BankResetTimeTab3,BankRemSlotsTab3,BankResetTimeTab4,BankRemSlotsTab4,BankResetTimeTab5,BankRemSlotsTab5,"
3025 "characters.name, characters.level, characters.class, characters.zone, characters.logout_time "
3026 "FROM guild_member LEFT JOIN characters ON characters.guid = guild_member.guid ORDER BY guildid ASC");
3028 // load guild bank tab rights
3030 QueryResult
*guildBankTabRightsResult
= CharacterDatabase
.Query("SELECT guildid,TabId,rid,gbright,SlotPerDay FROM guild_bank_right ORDER BY guildid ASC, TabId ASC");
3032 barGoLink
bar( result
->GetRowCount() );
3036 //Field *fields = result->Fetch();
3041 newGuild
= new Guild
;
3042 if (!newGuild
->LoadGuildFromDB(result
) ||
3043 !newGuild
->LoadRanksFromDB(guildRanksResult
) ||
3044 !newGuild
->LoadMembersFromDB(guildMembersResult
) ||
3045 !newGuild
->LoadBankRightsFromDB(guildBankTabRightsResult
) ||
3046 !newGuild
->CheckGuildStructure()
3049 newGuild
->Disband();
3053 newGuild
->LoadGuildEventLogFromDB();
3054 newGuild
->LoadGuildBankEventLogFromDB();
3055 newGuild
->LoadGuildBankFromDB();
3057 } while( result
->NextRow() );
3060 delete guildRanksResult
;
3061 delete guildMembersResult
;
3062 delete guildBankTabRightsResult
;
3064 //delete unused LogGuid records in guild_eventlog and guild_bank_eventlog table
3065 //you can comment these lines if you don't plan to change CONFIG_GUILD_EVENT_LOG_COUNT and CONFIG_GUILD_BANK_EVENT_LOG_COUNT
3066 CharacterDatabase
.PQuery("DELETE FROM guild_eventlog WHERE LogGuid > '%u'", sWorld
.getConfig(CONFIG_GUILD_EVENT_LOG_COUNT
));
3067 CharacterDatabase
.PQuery("DELETE FROM guild_bank_eventlog WHERE LogGuid > '%u'", sWorld
.getConfig(CONFIG_GUILD_BANK_EVENT_LOG_COUNT
));
3070 sLog
.outString( ">> Loaded %u guild definitions", count
);
3073 void ObjectMgr::LoadArenaTeams()
3078 QueryResult
*result
= CharacterDatabase
.Query( "SELECT arena_team.arenateamid,name,captainguid,type,BackgroundColor,EmblemStyle,"
3079 // 6 7 8 9 10 11 12 13 14
3080 "EmblemColor,BorderStyle,BorderColor, rating,games,wins,played,wins2,rank "
3081 "FROM arena_team LEFT JOIN arena_team_stats ON arena_team.arenateamid = arena_team_stats.arenateamid ORDER BY arena_team.arenateamid ASC" );
3091 sLog
.outString( ">> Loaded %u arenateam definitions", count
);
3095 // load arena_team members
3096 QueryResult
*arenaTeamMembersResult
= CharacterDatabase
.Query(
3097 // 0 1 2 3 4 5 6 7 8
3098 "SELECT arenateamid,member.guid,played_week,wons_week,played_season,wons_season,personal_rating,name,class "
3099 "FROM arena_team_member member LEFT JOIN characters chars on member.guid = chars.guid ORDER BY member.arenateamid ASC");
3101 barGoLink
bar( result
->GetRowCount() );
3105 Field
*fields
= result
->Fetch();
3110 ArenaTeam
*newArenaTeam
= new ArenaTeam
;
3111 if (!newArenaTeam
->LoadArenaTeamFromDB(result
) ||
3112 !newArenaTeam
->LoadMembersFromDB(arenaTeamMembersResult
))
3114 newArenaTeam
->Disband(NULL
);
3115 delete newArenaTeam
;
3118 AddArenaTeam(newArenaTeam
);
3119 }while( result
->NextRow() );
3122 delete arenaTeamMembersResult
;
3125 sLog
.outString( ">> Loaded %u arenateam definitions", count
);
3128 void ObjectMgr::LoadGroups()
3130 // -- loading groups --
3131 Group
*group
= NULL
;
3132 uint64 leaderGuid
= 0;
3134 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
3135 QueryResult
*result
= CharacterDatabase
.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty, leaderGuid FROM groups");
3144 sLog
.outString( ">> Loaded %u group definitions", count
);
3148 barGoLink
bar( result
->GetRowCount() );
3153 Field
*fields
= result
->Fetch();
3155 leaderGuid
= MAKE_NEW_GUID(fields
[16].GetUInt32(),0,HIGHGUID_PLAYER
);
3158 if(!group
->LoadGroupFromDB(leaderGuid
, result
, false))
3165 }while( result
->NextRow() );
3170 sLog
.outString( ">> Loaded %u group definitions", count
);
3172 // -- loading members --
3177 result
= CharacterDatabase
.Query("SELECT memberGuid, assistant, subgroup, leaderGuid FROM group_member ORDER BY leaderGuid");
3180 barGoLink
bar2( 1 );
3185 barGoLink
bar2( result
->GetRowCount() );
3189 Field
*fields
= result
->Fetch();
3191 leaderGuid
= MAKE_NEW_GUID(fields
[3].GetUInt32(), 0, HIGHGUID_PLAYER
);
3192 if(!group
|| group
->GetLeaderGUID() != leaderGuid
)
3194 group
= GetGroupByLeader(leaderGuid
);
3197 sLog
.outErrorDb("Incorrect entry in group_member table : no group with leader %d for member %d!", fields
[3].GetUInt32(), fields
[0].GetUInt32());
3198 CharacterDatabase
.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", fields
[0].GetUInt32());
3203 if(!group
->LoadMemberFromDB(fields
[0].GetUInt32(), fields
[2].GetUInt8(), fields
[1].GetBool()))
3205 sLog
.outErrorDb("Incorrect entry in group_member table : member %d cannot be added to player %d's group!", fields
[0].GetUInt32(), fields
[3].GetUInt32());
3206 CharacterDatabase
.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", fields
[0].GetUInt32());
3208 }while( result
->NextRow() );
3213 // TODO: maybe delete from the DB before loading in this case
3214 for(GroupSet::iterator itr
= mGroupSet
.begin(); itr
!= mGroupSet
.end();)
3216 if((*itr
)->GetMembersCount() < 2)
3220 mGroupSet
.erase(itr
++);
3226 // -- loading instances --
3230 result
= CharacterDatabase
.Query(
3232 "SELECT leaderGuid, map, instance, permanent, difficulty, resettime, "
3234 "(SELECT COUNT(*) FROM character_instance WHERE guid = leaderGuid AND instance = group_instance.instance AND permanent = 1 LIMIT 1) "
3235 "FROM group_instance LEFT JOIN instance ON instance = id ORDER BY leaderGuid"
3240 barGoLink
bar2( 1 );
3245 barGoLink
bar2( result
->GetRowCount() );
3249 Field
*fields
= result
->Fetch();
3251 leaderGuid
= MAKE_NEW_GUID(fields
[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
3252 if(!group
|| group
->GetLeaderGUID() != leaderGuid
)
3254 group
= GetGroupByLeader(leaderGuid
);
3257 sLog
.outErrorDb("Incorrect entry in group_instance table : no group with leader %d", fields
[0].GetUInt32());
3262 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(fields
[1].GetUInt32());
3263 if(!mapEntry
|| !mapEntry
->IsDungeon())
3265 sLog
.outErrorDb("Incorrect entry in group_instance table : no dungeon map %d", fields
[1].GetUInt32());
3269 uint32 diff
= fields
[4].GetUInt8();
3270 if(diff
>= (mapEntry
->IsRaid() ? MAX_RAID_DIFFICULTY
: MAX_DUNGEON_DIFFICULTY
))
3272 sLog
.outErrorDb("Wrong dungeon difficulty use in group_instance table: %d", diff
+ 1);
3273 diff
= 0; // default for both difficaly types
3276 InstanceSave
*save
= sInstanceSaveMgr
.AddInstanceSave(mapEntry
->MapID
, fields
[2].GetUInt32(), Difficulty(diff
), (time_t)fields
[5].GetUInt64(), (fields
[6].GetUInt32() == 0), true);
3277 group
->BindToInstance(save
, fields
[3].GetBool(), true);
3278 }while( result
->NextRow() );
3283 sLog
.outString( ">> Loaded %u group-instance binds total", count
);
3286 sLog
.outString( ">> Loaded %u group members total", count
);
3289 void ObjectMgr::LoadQuests()
3292 for(QuestMap::const_iterator itr
=mQuestTemplates
.begin(); itr
!= mQuestTemplates
.end(); ++itr
)
3294 mQuestTemplates
.clear();
3296 mExclusiveQuestGroups
.clear();
3298 // 0 1 2 3 4 5 6 7 8
3299 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, Method, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue,"
3300 // 9 10 11 12 13 14 15 16
3301 "RepObjectiveFaction, RepObjectiveValue, RequiredMinRepFaction, RequiredMinRepValue, RequiredMaxRepFaction, RequiredMaxRepValue, SuggestedPlayers, LimitTime,"
3302 // 17 18 19 20 21 22 23 24 25 26 27 28
3303 "QuestFlags, SpecialFlags, CharTitleId, PlayersSlain, BonusTalents, PrevQuestId, NextQuestId, ExclusiveGroup, NextQuestInChain, SrcItemId, SrcItemCount, SrcSpell,"
3304 // 29 30 31 32 33 34 35 36 37 38
3305 "Title, Details, Objectives, OfferRewardText, RequestItemsText, EndText, ObjectiveText1, ObjectiveText2, ObjectiveText3, ObjectiveText4,"
3306 // 39 40 41 42 43 44 45 46 47 48 49 50
3307 "ReqItemId1, ReqItemId2, ReqItemId3, ReqItemId4, ReqItemId5, ReqItemId6, ReqItemCount1, ReqItemCount2, ReqItemCount3, ReqItemCount4, ReqItemCount5, ReqItemCount6,"
3308 // 51 52 53 54 55 56 57 58
3309 "ReqSourceId1, ReqSourceId2, ReqSourceId3, ReqSourceId4, ReqSourceCount1, ReqSourceCount2, ReqSourceCount3, ReqSourceCount4,"
3310 // 59 60 61 62 63 64 65 66
3311 "ReqCreatureOrGOId1, ReqCreatureOrGOId2, ReqCreatureOrGOId3, ReqCreatureOrGOId4, ReqCreatureOrGOCount1, ReqCreatureOrGOCount2, ReqCreatureOrGOCount3, ReqCreatureOrGOCount4,"
3313 "ReqSpellCast1, ReqSpellCast2, ReqSpellCast3, ReqSpellCast4,"
3314 // 71 72 73 74 75 76
3315 "RewChoiceItemId1, RewChoiceItemId2, RewChoiceItemId3, RewChoiceItemId4, RewChoiceItemId5, RewChoiceItemId6,"
3316 // 77 78 79 80 81 82
3317 "RewChoiceItemCount1, RewChoiceItemCount2, RewChoiceItemCount3, RewChoiceItemCount4, RewChoiceItemCount5, RewChoiceItemCount6,"
3318 // 83 84 85 86 87 88 89 90
3319 "RewItemId1, RewItemId2, RewItemId3, RewItemId4, RewItemCount1, RewItemCount2, RewItemCount3, RewItemCount4,"
3320 // 91 92 93 94 95 96 97 98 99 100
3321 "RewRepFaction1, RewRepFaction2, RewRepFaction3, RewRepFaction4, RewRepFaction5, RewRepValue1, RewRepValue2, RewRepValue3, RewRepValue4, RewRepValue5,"
3322 // 101 102 103 104 105 106 107 108 109 110 111
3323 "RewHonorableKills, RewOrReqMoney, RewMoneyMaxLevel, RewSpell, RewSpellCast, RewMailTemplateId, RewMailDelaySecs, PointMapId, PointX, PointY, PointOpt,"
3324 // 112 113 114 115 116 117 118 119
3325 "DetailsEmote1, DetailsEmote2, DetailsEmote3, DetailsEmote4, DetailsEmoteDelay1, DetailsEmoteDelay2, DetailsEmoteDelay3, DetailsEmoteDelay4,"
3326 // 120 121 122 123 124 125
3327 "IncompleteEmote, CompleteEmote, OfferRewardEmote1, OfferRewardEmote2, OfferRewardEmote3, OfferRewardEmote4,"
3329 "OfferRewardEmoteDelay1, OfferRewardEmoteDelay2, OfferRewardEmoteDelay3, OfferRewardEmoteDelay4,"
3331 "StartScript, CompleteScript"
3332 " FROM quest_template");
3339 sLog
.outString( ">> Loaded 0 quests definitions" );
3340 sLog
.outErrorDb("`quest_template` table is empty!");
3344 // create multimap previous quest for each existed quest
3345 // some quests can have many previous maps set by NextQuestId in previous quest
3346 // for example set of race quests can lead to single not race specific quest
3347 barGoLink
bar( result
->GetRowCount() );
3351 Field
*fields
= result
->Fetch();
3353 Quest
* newQuest
= new Quest(fields
);
3354 mQuestTemplates
[newQuest
->GetQuestId()] = newQuest
;
3355 } while( result
->NextRow() );
3361 std::map
<uint32
,uint32
> usedMailTemplates
;
3363 for (QuestMap::iterator iter
= mQuestTemplates
.begin(); iter
!= mQuestTemplates
.end(); ++iter
)
3365 Quest
* qinfo
= iter
->second
;
3367 // additional quest integrity checks (GO, creature_template and item_template must be loaded already)
3369 if( qinfo
->GetQuestMethod() >= 3 )
3371 sLog
.outErrorDb("Quest %u has `Method` = %u, expected values are 0, 1 or 2.",qinfo
->GetQuestId(),qinfo
->GetQuestMethod());
3374 if (qinfo
->QuestFlags
& ~QUEST_MANGOS_FLAGS_DB_ALLOWED
)
3376 sLog
.outErrorDb("Quest %u has `SpecialFlags` = %u > max allowed value. Correct `SpecialFlags` to value <= %u",
3377 qinfo
->GetQuestId(),qinfo
->QuestFlags
>> 24,QUEST_MANGOS_FLAGS_DB_ALLOWED
>> 24);
3378 qinfo
->QuestFlags
&= QUEST_MANGOS_FLAGS_DB_ALLOWED
;
3381 if(qinfo
->QuestFlags
& QUEST_FLAGS_DAILY
)
3383 if(!(qinfo
->QuestFlags
& QUEST_MANGOS_FLAGS_REPEATABLE
))
3385 sLog
.outErrorDb("Daily Quest %u not marked as repeatable in `SpecialFlags`, added.",qinfo
->GetQuestId());
3386 qinfo
->QuestFlags
|= QUEST_MANGOS_FLAGS_REPEATABLE
;
3390 if(qinfo
->QuestFlags
& QUEST_FLAGS_AUTO_REWARDED
)
3392 // at auto-reward can be rewarded only RewChoiceItemId[0]
3393 for(int j
= 1; j
< QUEST_REWARD_CHOICES_COUNT
; ++j
)
3395 if(uint32 id
= qinfo
->RewChoiceItemId
[j
])
3397 sLog
.outErrorDb("Quest %u has `RewChoiceItemId%d` = %u but item from `RewChoiceItemId%d` can't be rewarded with quest flag QUEST_FLAGS_AUTO_REWARDED.",
3398 qinfo
->GetQuestId(),j
+1,id
,j
+1);
3399 // no changes, quest ignore this data
3404 // client quest log visual (area case)
3405 if( qinfo
->ZoneOrSort
> 0 )
3407 if(!GetAreaEntryByAreaID(qinfo
->ZoneOrSort
))
3409 sLog
.outErrorDb("Quest %u has `ZoneOrSort` = %u (zone case) but zone with this id does not exist.",
3410 qinfo
->GetQuestId(),qinfo
->ZoneOrSort
);
3411 // no changes, quest not dependent from this value but can have problems at client
3414 // client quest log visual (sort case)
3415 if( qinfo
->ZoneOrSort
< 0 )
3417 QuestSortEntry
const* qSort
= sQuestSortStore
.LookupEntry(-int32(qinfo
->ZoneOrSort
));
3420 sLog
.outErrorDb("Quest %u has `ZoneOrSort` = %i (sort case) but quest sort with this id does not exist.",
3421 qinfo
->GetQuestId(),qinfo
->ZoneOrSort
);
3422 // no changes, quest not dependent from this value but can have problems at client (note some may be 0, we must allow this so no check)
3424 //check SkillOrClass value (class case).
3425 if( ClassByQuestSort(-int32(qinfo
->ZoneOrSort
)) )
3427 // SkillOrClass should not have class case when class case already set in ZoneOrSort.
3428 if(qinfo
->SkillOrClass
< 0)
3430 sLog
.outErrorDb("Quest %u has `ZoneOrSort` = %i (class sort case) and `SkillOrClass` = %i (class case), redundant.",
3431 qinfo
->GetQuestId(),qinfo
->ZoneOrSort
,qinfo
->SkillOrClass
);
3434 //check for proper SkillOrClass value (skill case)
3435 if(int32 skill_id
= SkillByQuestSort(-int32(qinfo
->ZoneOrSort
)))
3437 // skill is positive value in SkillOrClass
3438 if(qinfo
->SkillOrClass
!= skill_id
)
3440 sLog
.outErrorDb("Quest %u has `ZoneOrSort` = %i (skill sort case) but `SkillOrClass` does not have a corresponding value (%i).",
3441 qinfo
->GetQuestId(),qinfo
->ZoneOrSort
,skill_id
);
3442 //override, and force proper value here?
3447 // SkillOrClass (class case)
3448 if( qinfo
->SkillOrClass
< 0 )
3450 if( !sChrClassesStore
.LookupEntry(-int32(qinfo
->SkillOrClass
)) )
3452 sLog
.outErrorDb("Quest %u has `SkillOrClass` = %i (class case) but class (%i) does not exist",
3453 qinfo
->GetQuestId(),qinfo
->SkillOrClass
,-qinfo
->SkillOrClass
);
3456 // SkillOrClass (skill case)
3457 if( qinfo
->SkillOrClass
> 0 )
3459 if( !sSkillLineStore
.LookupEntry(qinfo
->SkillOrClass
) )
3461 sLog
.outErrorDb("Quest %u has `SkillOrClass` = %u (skill case) but skill (%i) does not exist",
3462 qinfo
->GetQuestId(),qinfo
->SkillOrClass
,qinfo
->SkillOrClass
);
3466 if( qinfo
->RequiredSkillValue
)
3468 if( qinfo
->RequiredSkillValue
> sWorld
.GetConfigMaxSkillValue() )
3470 sLog
.outErrorDb("Quest %u has `RequiredSkillValue` = %u but max possible skill is %u, quest can't be done.",
3471 qinfo
->GetQuestId(),qinfo
->RequiredSkillValue
,sWorld
.GetConfigMaxSkillValue());
3472 // no changes, quest can't be done for this requirement
3475 if( qinfo
->SkillOrClass
<= 0 )
3477 sLog
.outErrorDb("Quest %u has `RequiredSkillValue` = %u but `SkillOrClass` = %i (class case), value ignored.",
3478 qinfo
->GetQuestId(),qinfo
->RequiredSkillValue
,qinfo
->SkillOrClass
);
3479 // no changes, quest can't be done for this requirement (fail at wrong skill id)
3482 // else Skill quests can have 0 skill level, this is ok
3484 if(qinfo
->RepObjectiveFaction
&& !sFactionStore
.LookupEntry(qinfo
->RepObjectiveFaction
))
3486 sLog
.outErrorDb("Quest %u has `RepObjectiveFaction` = %u but faction template %u does not exist, quest can't be done.",
3487 qinfo
->GetQuestId(),qinfo
->RepObjectiveFaction
,qinfo
->RepObjectiveFaction
);
3488 // no changes, quest can't be done for this requirement
3491 if(qinfo
->RequiredMinRepFaction
&& !sFactionStore
.LookupEntry(qinfo
->RequiredMinRepFaction
))
3493 sLog
.outErrorDb("Quest %u has `RequiredMinRepFaction` = %u but faction template %u does not exist, quest can't be done.",
3494 qinfo
->GetQuestId(),qinfo
->RequiredMinRepFaction
,qinfo
->RequiredMinRepFaction
);
3495 // no changes, quest can't be done for this requirement
3498 if(qinfo
->RequiredMaxRepFaction
&& !sFactionStore
.LookupEntry(qinfo
->RequiredMaxRepFaction
))
3500 sLog
.outErrorDb("Quest %u has `RequiredMaxRepFaction` = %u but faction template %u does not exist, quest can't be done.",
3501 qinfo
->GetQuestId(),qinfo
->RequiredMaxRepFaction
,qinfo
->RequiredMaxRepFaction
);
3502 // no changes, quest can't be done for this requirement
3505 if(qinfo
->RequiredMinRepValue
&& qinfo
->RequiredMinRepValue
> ReputationMgr::Reputation_Cap
)
3507 sLog
.outErrorDb("Quest %u has `RequiredMinRepValue` = %d but max reputation is %u, quest can't be done.",
3508 qinfo
->GetQuestId(),qinfo
->RequiredMinRepValue
,ReputationMgr::Reputation_Cap
);
3509 // no changes, quest can't be done for this requirement
3512 if(qinfo
->RequiredMinRepValue
&& qinfo
->RequiredMaxRepValue
&& qinfo
->RequiredMaxRepValue
<= qinfo
->RequiredMinRepValue
)
3514 sLog
.outErrorDb("Quest %u has `RequiredMaxRepValue` = %d and `RequiredMinRepValue` = %d, quest can't be done.",
3515 qinfo
->GetQuestId(),qinfo
->RequiredMaxRepValue
,qinfo
->RequiredMinRepValue
);
3516 // no changes, quest can't be done for this requirement
3519 if(!qinfo
->RepObjectiveFaction
&& qinfo
->RepObjectiveValue
> 0 )
3521 sLog
.outErrorDb("Quest %u has `RepObjectiveValue` = %d but `RepObjectiveFaction` is 0, value has no effect",
3522 qinfo
->GetQuestId(),qinfo
->RepObjectiveValue
);
3526 if(!qinfo
->RequiredMinRepFaction
&& qinfo
->RequiredMinRepValue
> 0 )
3528 sLog
.outErrorDb("Quest %u has `RequiredMinRepValue` = %d but `RequiredMinRepFaction` is 0, value has no effect",
3529 qinfo
->GetQuestId(),qinfo
->RequiredMinRepValue
);
3533 if(!qinfo
->RequiredMaxRepFaction
&& qinfo
->RequiredMaxRepValue
> 0 )
3535 sLog
.outErrorDb("Quest %u has `RequiredMaxRepValue` = %d but `RequiredMaxRepFaction` is 0, value has no effect",
3536 qinfo
->GetQuestId(),qinfo
->RequiredMaxRepValue
);
3540 if(qinfo
->CharTitleId
&& !sCharTitlesStore
.LookupEntry(qinfo
->CharTitleId
))
3542 sLog
.outErrorDb("Quest %u has `CharTitleId` = %u but CharTitle Id %u does not exist, quest can't be rewarded with title.",
3543 qinfo
->GetQuestId(),qinfo
->GetCharTitleId(),qinfo
->GetCharTitleId());
3544 qinfo
->CharTitleId
= 0;
3545 // quest can't reward this title
3548 if(qinfo
->SrcItemId
)
3550 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(qinfo
->SrcItemId
))
3552 sLog
.outErrorDb("Quest %u has `SrcItemId` = %u but item with entry %u does not exist, quest can't be done.",
3553 qinfo
->GetQuestId(),qinfo
->SrcItemId
,qinfo
->SrcItemId
);
3554 qinfo
->SrcItemId
= 0; // quest can't be done for this requirement
3556 else if(qinfo
->SrcItemCount
==0)
3558 sLog
.outErrorDb("Quest %u has `SrcItemId` = %u but `SrcItemCount` = 0, set to 1 but need fix in DB.",
3559 qinfo
->GetQuestId(),qinfo
->SrcItemId
);
3560 qinfo
->SrcItemCount
= 1; // update to 1 for allow quest work for backward compatibility with DB
3563 else if(qinfo
->SrcItemCount
>0)
3565 sLog
.outErrorDb("Quest %u has `SrcItemId` = 0 but `SrcItemCount` = %u, useless value.",
3566 qinfo
->GetQuestId(),qinfo
->SrcItemCount
);
3567 qinfo
->SrcItemCount
=0; // no quest work changes in fact
3572 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(qinfo
->SrcSpell
);
3575 sLog
.outErrorDb("Quest %u has `SrcSpell` = %u but spell %u doesn't exist, quest can't be done.",
3576 qinfo
->GetQuestId(),qinfo
->SrcSpell
,qinfo
->SrcSpell
);
3577 qinfo
->SrcSpell
= 0; // quest can't be done for this requirement
3579 else if(!SpellMgr::IsSpellValid(spellInfo
))
3581 sLog
.outErrorDb("Quest %u has `SrcSpell` = %u but spell %u is broken, quest can't be done.",
3582 qinfo
->GetQuestId(),qinfo
->SrcSpell
,qinfo
->SrcSpell
);
3583 qinfo
->SrcSpell
= 0; // quest can't be done for this requirement
3587 for(int j
= 0; j
< QUEST_ITEM_OBJECTIVES_COUNT
; ++j
)
3589 uint32 id
= qinfo
->ReqItemId
[j
];
3592 if(qinfo
->ReqItemCount
[j
] == 0)
3594 sLog
.outErrorDb("Quest %u has `ReqItemId%d` = %u but `ReqItemCount%d` = 0, quest can't be done.",
3595 qinfo
->GetQuestId(), j
+1, id
, j
+1);
3596 // no changes, quest can't be done for this requirement
3599 qinfo
->SetFlag(QUEST_MANGOS_FLAGS_DELIVER
);
3601 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(id
))
3603 sLog
.outErrorDb("Quest %u has `ReqItemId%d` = %u but item with entry %u does not exist, quest can't be done.",
3604 qinfo
->GetQuestId(), j
+1, id
, id
);
3605 qinfo
->ReqItemCount
[j
] = 0; // prevent incorrect work of quest
3608 else if(qinfo
->ReqItemCount
[j
] > 0)
3610 sLog
.outErrorDb("Quest %u has `ReqItemId%d` = 0 but `ReqItemCount%d` = %u, quest can't be done.",
3611 qinfo
->GetQuestId(), j
+1, j
+1, qinfo
->ReqItemCount
[j
]);
3612 qinfo
->ReqItemCount
[j
] = 0; // prevent incorrect work of quest
3616 for(int j
= 0; j
< QUEST_SOURCE_ITEM_IDS_COUNT
; ++j
)
3618 uint32 id
= qinfo
->ReqSourceId
[j
];
3621 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(id
))
3623 sLog
.outErrorDb("Quest %u has `ReqSourceId%d` = %u but item with entry %u does not exist, quest can't be done.",
3624 qinfo
->GetQuestId(),j
+1,id
,id
);
3625 // no changes, quest can't be done for this requirement
3630 if(qinfo
->ReqSourceCount
[j
]>0)
3632 sLog
.outErrorDb("Quest %u has `ReqSourceId%d` = 0 but `ReqSourceCount%d` = %u.",
3633 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->ReqSourceCount
[j
]);
3634 // no changes, quest ignore this data
3639 for(int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; ++j
)
3641 uint32 id
= qinfo
->ReqSpell
[j
];
3644 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(id
);
3647 sLog
.outErrorDb("Quest %u has `ReqSpellCast%d` = %u but spell %u does not exist, quest can't be done.",
3648 qinfo
->GetQuestId(),j
+1,id
,id
);
3652 if(!qinfo
->ReqCreatureOrGOId
[j
])
3655 for(int k
= 0; k
< 3; ++k
)
3657 if ((spellInfo
->Effect
[k
] == SPELL_EFFECT_QUEST_COMPLETE
&& uint32(spellInfo
->EffectMiscValue
[k
]) == qinfo
->QuestId
) ||
3658 spellInfo
->Effect
[k
] == SPELL_EFFECT_SEND_EVENT
)
3667 if(!qinfo
->HasFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
))
3669 sLog
.outErrorDb("Spell (id: %u) have SPELL_EFFECT_QUEST_COMPLETE or SPELL_EFFECT_SEND_EVENT for quest %u and ReqCreatureOrGOId%d = 0, but quest not have flag QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT. Quest flags or ReqCreatureOrGOId%d must be fixed, quest modified to enable objective.",spellInfo
->Id
,qinfo
->QuestId
,j
+1,j
+1);
3671 // this will prevent quest completing without objective
3672 const_cast<Quest
*>(qinfo
)->SetFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
);
3677 sLog
.outErrorDb("Quest %u has `ReqSpellCast%d` = %u and ReqCreatureOrGOId%d = 0 but spell %u does not have SPELL_EFFECT_QUEST_COMPLETE or SPELL_EFFECT_SEND_EVENT effect for this quest, quest can't be done.",
3678 qinfo
->GetQuestId(),j
+1,id
,j
+1,id
);
3679 // no changes, quest can't be done for this requirement
3685 for(int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; ++j
)
3687 int32 id
= qinfo
->ReqCreatureOrGOId
[j
];
3688 if(id
< 0 && !sGOStorage
.LookupEntry
<GameObjectInfo
>(-id
))
3690 sLog
.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = %i but gameobject %u does not exist, quest can't be done.",
3691 qinfo
->GetQuestId(),j
+1,id
,uint32(-id
));
3692 qinfo
->ReqCreatureOrGOId
[j
] = 0; // quest can't be done for this requirement
3695 if(id
> 0 && !sCreatureStorage
.LookupEntry
<CreatureInfo
>(id
))
3697 sLog
.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = %i but creature with entry %u does not exist, quest can't be done.",
3698 qinfo
->GetQuestId(),j
+1,id
,uint32(id
));
3699 qinfo
->ReqCreatureOrGOId
[j
] = 0; // quest can't be done for this requirement
3704 // In fact SpeakTo and Kill are quite same: either you can speak to mob:SpeakTo or you can't:Kill/Cast
3706 qinfo
->SetFlag(QUEST_MANGOS_FLAGS_KILL_OR_CAST
| QUEST_MANGOS_FLAGS_SPEAKTO
);
3708 if(!qinfo
->ReqCreatureOrGOCount
[j
])
3710 sLog
.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = %u but `ReqCreatureOrGOCount%d` = 0, quest can't be done.",
3711 qinfo
->GetQuestId(),j
+1,id
,j
+1);
3712 // no changes, quest can be incorrectly done, but we already report this
3715 else if(qinfo
->ReqCreatureOrGOCount
[j
]>0)
3717 sLog
.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = 0 but `ReqCreatureOrGOCount%d` = %u.",
3718 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->ReqCreatureOrGOCount
[j
]);
3719 // no changes, quest ignore this data
3723 for(int j
= 0; j
< QUEST_REWARD_CHOICES_COUNT
; ++j
)
3725 uint32 id
= qinfo
->RewChoiceItemId
[j
];
3728 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(id
))
3730 sLog
.outErrorDb("Quest %u has `RewChoiceItemId%d` = %u but item with entry %u does not exist, quest will not reward this item.",
3731 qinfo
->GetQuestId(),j
+1,id
,id
);
3732 qinfo
->RewChoiceItemId
[j
] = 0; // no changes, quest will not reward this
3735 if(!qinfo
->RewChoiceItemCount
[j
])
3737 sLog
.outErrorDb("Quest %u has `RewChoiceItemId%d` = %u but `RewChoiceItemCount%d` = 0, quest can't be done.",
3738 qinfo
->GetQuestId(),j
+1,id
,j
+1);
3739 // no changes, quest can't be done
3742 else if(qinfo
->RewChoiceItemCount
[j
]>0)
3744 sLog
.outErrorDb("Quest %u has `RewChoiceItemId%d` = 0 but `RewChoiceItemCount%d` = %u.",
3745 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->RewChoiceItemCount
[j
]);
3746 // no changes, quest ignore this data
3750 for(int j
= 0; j
< QUEST_REWARDS_COUNT
; ++j
)
3752 uint32 id
= qinfo
->RewItemId
[j
];
3755 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(id
))
3757 sLog
.outErrorDb("Quest %u has `RewItemId%d` = %u but item with entry %u does not exist, quest will not reward this item.",
3758 qinfo
->GetQuestId(),j
+1,id
,id
);
3759 qinfo
->RewItemId
[j
] = 0; // no changes, quest will not reward this item
3762 if(!qinfo
->RewItemCount
[j
])
3764 sLog
.outErrorDb("Quest %u has `RewItemId%d` = %u but `RewItemCount%d` = 0, quest will not reward this item.",
3765 qinfo
->GetQuestId(),j
+1,id
,j
+1);
3769 else if(qinfo
->RewItemCount
[j
]>0)
3771 sLog
.outErrorDb("Quest %u has `RewItemId%d` = 0 but `RewItemCount%d` = %u.",
3772 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->RewItemCount
[j
]);
3773 // no changes, quest ignore this data
3777 for(int j
= 0; j
< QUEST_REPUTATIONS_COUNT
; ++j
)
3779 if(qinfo
->RewRepFaction
[j
])
3781 if(!qinfo
->RewRepValue
[j
])
3783 sLog
.outErrorDb("Quest %u has `RewRepFaction%d` = %u but `RewRepValue%d` = 0, quest will not reward this reputation.",
3784 qinfo
->GetQuestId(),j
+1,qinfo
->RewRepValue
[j
],j
+1);
3788 if(!sFactionStore
.LookupEntry(qinfo
->RewRepFaction
[j
]))
3790 sLog
.outErrorDb("Quest %u has `RewRepFaction%d` = %u but raw faction (faction.dbc) %u does not exist, quest will not reward reputation for this faction.",
3791 qinfo
->GetQuestId(),j
+1,qinfo
->RewRepFaction
[j
] ,qinfo
->RewRepFaction
[j
] );
3792 qinfo
->RewRepFaction
[j
] = 0; // quest will not reward this
3795 else if(qinfo
->RewRepValue
[j
]!=0)
3797 sLog
.outErrorDb("Quest %u has `RewRepFaction%d` = 0 but `RewRepValue%d` = %u.",
3798 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->RewRepValue
[j
]);
3799 // no changes, quest ignore this data
3805 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(qinfo
->RewSpell
);
3809 sLog
.outErrorDb("Quest %u has `RewSpell` = %u but spell %u does not exist, spell removed as display reward.",
3810 qinfo
->GetQuestId(),qinfo
->RewSpell
,qinfo
->RewSpell
);
3811 qinfo
->RewSpell
= 0; // no spell reward will display for this quest
3813 else if(!SpellMgr::IsSpellValid(spellInfo
))
3815 sLog
.outErrorDb("Quest %u has `RewSpell` = %u but spell %u is broken, quest will not have a spell reward.",
3816 qinfo
->GetQuestId(),qinfo
->RewSpell
,qinfo
->RewSpell
);
3817 qinfo
->RewSpell
= 0; // no spell reward will display for this quest
3819 else if(GetTalentSpellCost(qinfo
->RewSpell
))
3821 sLog
.outErrorDb("Quest %u has `RewSpell` = %u but spell %u is talent, quest will not have a spell reward.",
3822 qinfo
->GetQuestId(),qinfo
->RewSpell
,qinfo
->RewSpell
);
3823 qinfo
->RewSpell
= 0; // no spell reward will display for this quest
3827 if(qinfo
->RewSpellCast
)
3829 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(qinfo
->RewSpellCast
);
3833 sLog
.outErrorDb("Quest %u has `RewSpellCast` = %u but spell %u does not exist, quest will not have a spell reward.",
3834 qinfo
->GetQuestId(),qinfo
->RewSpellCast
,qinfo
->RewSpellCast
);
3835 qinfo
->RewSpellCast
= 0; // no spell will be casted on player
3837 else if(!SpellMgr::IsSpellValid(spellInfo
))
3839 sLog
.outErrorDb("Quest %u has `RewSpellCast` = %u but spell %u is broken, quest will not have a spell reward.",
3840 qinfo
->GetQuestId(),qinfo
->RewSpellCast
,qinfo
->RewSpellCast
);
3841 qinfo
->RewSpellCast
= 0; // no spell will be casted on player
3843 else if(GetTalentSpellCost(qinfo
->RewSpellCast
))
3845 sLog
.outErrorDb("Quest %u has `RewSpell` = %u but spell %u is talent, quest will not have a spell reward.",
3846 qinfo
->GetQuestId(),qinfo
->RewSpellCast
,qinfo
->RewSpellCast
);
3847 qinfo
->RewSpellCast
= 0; // no spell will be casted on player
3851 if (qinfo
->RewMailTemplateId
)
3853 if (!sMailTemplateStore
.LookupEntry(qinfo
->RewMailTemplateId
))
3855 sLog
.outErrorDb("Quest %u has `RewMailTemplateId` = %u but mail template %u does not exist, quest will not have a mail reward.",
3856 qinfo
->GetQuestId(),qinfo
->RewMailTemplateId
,qinfo
->RewMailTemplateId
);
3857 qinfo
->RewMailTemplateId
= 0; // no mail will send to player
3858 qinfo
->RewMailDelaySecs
= 0; // no mail will send to player
3860 else if (usedMailTemplates
.find(qinfo
->RewMailTemplateId
) != usedMailTemplates
.end())
3862 std::map
<uint32
,uint32
>::const_iterator used_mt_itr
= usedMailTemplates
.find(qinfo
->RewMailTemplateId
);
3863 sLog
.outErrorDb("Quest %u has `RewMailTemplateId` = %u but mail template %u already used for quest %u, quest will not have a mail reward.",
3864 qinfo
->GetQuestId(),qinfo
->RewMailTemplateId
,qinfo
->RewMailTemplateId
,used_mt_itr
->second
);
3865 qinfo
->RewMailTemplateId
= 0; // no mail will send to player
3866 qinfo
->RewMailDelaySecs
= 0; // no mail will send to player
3869 usedMailTemplates
[qinfo
->RewMailTemplateId
] = qinfo
->GetQuestId();
3872 if (qinfo
->NextQuestInChain
)
3874 QuestMap::iterator qNextItr
= mQuestTemplates
.find(qinfo
->NextQuestInChain
);
3875 if (qNextItr
== mQuestTemplates
.end())
3877 sLog
.outErrorDb("Quest %u has `NextQuestInChain` = %u but quest %u does not exist, quest chain will not work.",
3878 qinfo
->GetQuestId(),qinfo
->NextQuestInChain
,qinfo
->NextQuestInChain
);
3879 qinfo
->NextQuestInChain
= 0;
3882 qNextItr
->second
->prevChainQuests
.push_back(qinfo
->GetQuestId());
3885 // fill additional data stores
3886 if (qinfo
->PrevQuestId
)
3888 if (mQuestTemplates
.find(abs(qinfo
->GetPrevQuestId())) == mQuestTemplates
.end())
3890 sLog
.outErrorDb("Quest %d has PrevQuestId %i, but no such quest", qinfo
->GetQuestId(), qinfo
->GetPrevQuestId());
3894 qinfo
->prevQuests
.push_back(qinfo
->PrevQuestId
);
3898 if(qinfo
->NextQuestId
)
3900 QuestMap::iterator qNextItr
= mQuestTemplates
.find(abs(qinfo
->GetNextQuestId()));
3901 if (qNextItr
== mQuestTemplates
.end())
3903 sLog
.outErrorDb("Quest %d has NextQuestId %i, but no such quest", qinfo
->GetQuestId(), qinfo
->GetNextQuestId());
3907 int32 signedQuestId
= qinfo
->NextQuestId
< 0 ? -int32(qinfo
->GetQuestId()) : int32(qinfo
->GetQuestId());
3908 qNextItr
->second
->prevQuests
.push_back(signedQuestId
);
3912 if(qinfo
->ExclusiveGroup
)
3913 mExclusiveQuestGroups
.insert(std::pair
<int32
, uint32
>(qinfo
->ExclusiveGroup
, qinfo
->GetQuestId()));
3914 if(qinfo
->LimitTime
)
3915 qinfo
->SetFlag(QUEST_MANGOS_FLAGS_TIMED
);
3918 // check QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT for spell with SPELL_EFFECT_QUEST_COMPLETE
3919 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); ++i
)
3921 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
3925 for(int j
= 0; j
< 3; ++j
)
3927 if(spellInfo
->Effect
[j
] != SPELL_EFFECT_QUEST_COMPLETE
)
3930 uint32 quest_id
= spellInfo
->EffectMiscValue
[j
];
3932 Quest
const* quest
= GetQuestTemplate(quest_id
);
3934 // some quest referenced in spells not exist (outdated spells)
3938 if(!quest
->HasFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
))
3940 sLog
.outErrorDb("Spell (id: %u) have SPELL_EFFECT_QUEST_COMPLETE for quest %u , but quest not have flag QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT. Quest flags must be fixed, quest modified to enable objective.",spellInfo
->Id
,quest_id
);
3942 // this will prevent quest completing without objective
3943 const_cast<Quest
*>(quest
)->SetFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
);
3949 sLog
.outString( ">> Loaded %lu quests definitions", (unsigned long)mQuestTemplates
.size() );
3952 void ObjectMgr::LoadQuestLocales()
3954 mQuestLocaleMap
.clear(); // need for reload case
3956 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,"
3957 "Title_loc1,Details_loc1,Objectives_loc1,OfferRewardText_loc1,RequestItemsText_loc1,EndText_loc1,ObjectiveText1_loc1,ObjectiveText2_loc1,ObjectiveText3_loc1,ObjectiveText4_loc1,"
3958 "Title_loc2,Details_loc2,Objectives_loc2,OfferRewardText_loc2,RequestItemsText_loc2,EndText_loc2,ObjectiveText1_loc2,ObjectiveText2_loc2,ObjectiveText3_loc2,ObjectiveText4_loc2,"
3959 "Title_loc3,Details_loc3,Objectives_loc3,OfferRewardText_loc3,RequestItemsText_loc3,EndText_loc3,ObjectiveText1_loc3,ObjectiveText2_loc3,ObjectiveText3_loc3,ObjectiveText4_loc3,"
3960 "Title_loc4,Details_loc4,Objectives_loc4,OfferRewardText_loc4,RequestItemsText_loc4,EndText_loc4,ObjectiveText1_loc4,ObjectiveText2_loc4,ObjectiveText3_loc4,ObjectiveText4_loc4,"
3961 "Title_loc5,Details_loc5,Objectives_loc5,OfferRewardText_loc5,RequestItemsText_loc5,EndText_loc5,ObjectiveText1_loc5,ObjectiveText2_loc5,ObjectiveText3_loc5,ObjectiveText4_loc5,"
3962 "Title_loc6,Details_loc6,Objectives_loc6,OfferRewardText_loc6,RequestItemsText_loc6,EndText_loc6,ObjectiveText1_loc6,ObjectiveText2_loc6,ObjectiveText3_loc6,ObjectiveText4_loc6,"
3963 "Title_loc7,Details_loc7,Objectives_loc7,OfferRewardText_loc7,RequestItemsText_loc7,EndText_loc7,ObjectiveText1_loc7,ObjectiveText2_loc7,ObjectiveText3_loc7,ObjectiveText4_loc7,"
3964 "Title_loc8,Details_loc8,Objectives_loc8,OfferRewardText_loc8,RequestItemsText_loc8,EndText_loc8,ObjectiveText1_loc8,ObjectiveText2_loc8,ObjectiveText3_loc8,ObjectiveText4_loc8"
3965 " FROM locales_quest"
3975 sLog
.outString(">> Loaded 0 Quest locale strings. DB table `locales_quest` is empty.");
3979 barGoLink
bar(result
->GetRowCount());
3983 Field
*fields
= result
->Fetch();
3986 uint32 entry
= fields
[0].GetUInt32();
3988 QuestLocale
& data
= mQuestLocaleMap
[entry
];
3990 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
3992 std::string str
= fields
[1+10*(i
-1)].GetCppString();
3995 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
3998 if(data
.Title
.size() <= idx
)
3999 data
.Title
.resize(idx
+1);
4001 data
.Title
[idx
] = str
;
4004 str
= fields
[1+10*(i
-1)+1].GetCppString();
4007 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4010 if(data
.Details
.size() <= idx
)
4011 data
.Details
.resize(idx
+1);
4013 data
.Details
[idx
] = str
;
4016 str
= fields
[1+10*(i
-1)+2].GetCppString();
4019 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4022 if(data
.Objectives
.size() <= idx
)
4023 data
.Objectives
.resize(idx
+1);
4025 data
.Objectives
[idx
] = str
;
4028 str
= fields
[1+10*(i
-1)+3].GetCppString();
4031 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4034 if(data
.OfferRewardText
.size() <= idx
)
4035 data
.OfferRewardText
.resize(idx
+1);
4037 data
.OfferRewardText
[idx
] = str
;
4040 str
= fields
[1+10*(i
-1)+4].GetCppString();
4043 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4046 if(data
.RequestItemsText
.size() <= idx
)
4047 data
.RequestItemsText
.resize(idx
+1);
4049 data
.RequestItemsText
[idx
] = str
;
4052 str
= fields
[1+10*(i
-1)+5].GetCppString();
4055 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4058 if(data
.EndText
.size() <= idx
)
4059 data
.EndText
.resize(idx
+1);
4061 data
.EndText
[idx
] = str
;
4064 for(int k
= 0; k
< 4; ++k
)
4066 str
= fields
[1+10*(i
-1)+6+k
].GetCppString();
4069 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4072 if(data
.ObjectiveText
[k
].size() <= idx
)
4073 data
.ObjectiveText
[k
].resize(idx
+1);
4075 data
.ObjectiveText
[k
][idx
] = str
;
4080 } while (result
->NextRow());
4085 sLog
.outString( ">> Loaded %lu Quest locale strings", (unsigned long)mQuestLocaleMap
.size() );
4088 void ObjectMgr::LoadScripts(ScriptMapMap
& scripts
, char const* tablename
)
4090 if(sWorld
.IsScriptScheduled()) // function don't must be called in time scripts use.
4093 sLog
.outString( "%s :", tablename
);
4095 scripts
.clear(); // need for reload support
4097 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT id,delay,command,datalong,datalong2,dataint, x, y, z, o FROM %s", tablename
);
4107 sLog
.outString( ">> Loaded %u script definitions", count
);
4111 barGoLink
bar( result
->GetRowCount() );
4117 Field
*fields
= result
->Fetch();
4119 tmp
.id
= fields
[0].GetUInt32();
4120 tmp
.delay
= fields
[1].GetUInt32();
4121 tmp
.command
= fields
[2].GetUInt32();
4122 tmp
.datalong
= fields
[3].GetUInt32();
4123 tmp
.datalong2
= fields
[4].GetUInt32();
4124 tmp
.dataint
= fields
[5].GetInt32();
4125 tmp
.x
= fields
[6].GetFloat();
4126 tmp
.y
= fields
[7].GetFloat();
4127 tmp
.z
= fields
[8].GetFloat();
4128 tmp
.o
= fields
[9].GetFloat();
4130 // generic command args check
4133 case SCRIPT_COMMAND_TALK
:
4135 if(tmp
.datalong
> 3)
4137 sLog
.outErrorDb("Table `%s` has invalid talk type (datalong = %u) in SCRIPT_COMMAND_TALK for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
4142 sLog
.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u",tablename
,tmp
.dataint
,tmp
.id
);
4145 if(tmp
.dataint
< MIN_DB_SCRIPT_STRING_ID
|| tmp
.dataint
>= MAX_DB_SCRIPT_STRING_ID
)
4147 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
);
4151 // if(!GetMangosStringLocale(tmp.dataint)) will checked after db_script_string loading
4155 case SCRIPT_COMMAND_EMOTE
:
4157 if(!sEmotesStore
.LookupEntry(tmp
.datalong
))
4159 sLog
.outErrorDb("Table `%s` has invalid emote id (datalong = %u) in SCRIPT_COMMAND_EMOTE for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
4165 case SCRIPT_COMMAND_TELEPORT_TO
:
4167 if(!sMapStore
.LookupEntry(tmp
.datalong
))
4169 sLog
.outErrorDb("Table `%s` has invalid map (Id: %u) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
4173 if(!MaNGOS::IsValidMapCoord(tmp
.x
,tmp
.y
,tmp
.z
,tmp
.o
))
4175 sLog
.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",tablename
,tmp
.x
,tmp
.y
,tmp
.id
);
4181 case SCRIPT_COMMAND_KILL_CREDIT
:
4183 if (!GetCreatureTemplate(tmp
.datalong
))
4185 sLog
.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_KILL_CREDIT for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
4191 case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE
:
4193 if(!MaNGOS::IsValidMapCoord(tmp
.x
,tmp
.y
,tmp
.z
,tmp
.o
))
4195 sLog
.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",tablename
,tmp
.x
,tmp
.y
,tmp
.id
);
4199 if(!GetCreatureTemplate(tmp
.datalong
))
4201 sLog
.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
4207 case SCRIPT_COMMAND_RESPAWN_GAMEOBJECT
:
4209 GameObjectData
const* data
= GetGOData(tmp
.datalong
);
4212 sLog
.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
4216 GameObjectInfo
const* info
= GetGameObjectInfo(data
->id
);
4219 sLog
.outErrorDb("Table `%s` has gameobject with invalid entry (GUID: %u Entry: %u) in SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",tablename
,tmp
.datalong
,data
->id
,tmp
.id
);
4223 if( info
->type
==GAMEOBJECT_TYPE_FISHINGNODE
||
4224 info
->type
==GAMEOBJECT_TYPE_FISHINGHOLE
||
4225 info
->type
==GAMEOBJECT_TYPE_DOOR
||
4226 info
->type
==GAMEOBJECT_TYPE_BUTTON
||
4227 info
->type
==GAMEOBJECT_TYPE_TRAP
)
4229 sLog
.outErrorDb("Table `%s` have gameobject type (%u) unsupported by command SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",tablename
,info
->id
,tmp
.id
);
4234 case SCRIPT_COMMAND_OPEN_DOOR
:
4235 case SCRIPT_COMMAND_CLOSE_DOOR
:
4237 GameObjectData
const* data
= GetGOData(tmp
.datalong
);
4240 sLog
.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in %s for script id %u",tablename
,tmp
.datalong
,(tmp
.command
==SCRIPT_COMMAND_OPEN_DOOR
? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp
.id
);
4244 GameObjectInfo
const* info
= GetGameObjectInfo(data
->id
);
4247 sLog
.outErrorDb("Table `%s` has gameobject with invalid entry (GUID: %u Entry: %u) in %s for script id %u",tablename
,tmp
.datalong
,data
->id
,(tmp
.command
==SCRIPT_COMMAND_OPEN_DOOR
? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp
.id
);
4251 if( info
->type
!=GAMEOBJECT_TYPE_DOOR
)
4253 sLog
.outErrorDb("Table `%s` has gameobject type (%u) non supported by command %s for script id %u",tablename
,info
->id
,(tmp
.command
==SCRIPT_COMMAND_OPEN_DOOR
? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp
.id
);
4259 case SCRIPT_COMMAND_QUEST_EXPLORED
:
4261 Quest
const* quest
= GetQuestTemplate(tmp
.datalong
);
4264 sLog
.outErrorDb("Table `%s` has invalid quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
4268 if(!quest
->HasFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
))
4270 sLog
.outErrorDb("Table `%s` has quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, but quest not have flag QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT in quest flags. Script command or quest flags wrong. Quest modified to require objective.",tablename
,tmp
.datalong
,tmp
.id
);
4272 // this will prevent quest completing without objective
4273 const_cast<Quest
*>(quest
)->SetFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
);
4275 // continue; - quest objective requirement set and command can be allowed
4278 if(float(tmp
.datalong2
) > DEFAULT_VISIBILITY_DISTANCE
)
4280 sLog
.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",
4281 tablename
,tmp
.datalong2
,tmp
.id
);
4285 if(tmp
.datalong2
&& float(tmp
.datalong2
) > DEFAULT_VISIBILITY_DISTANCE
)
4287 sLog
.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, max distance is %f or 0 for disable distance check",
4288 tablename
,tmp
.datalong2
,tmp
.id
,DEFAULT_VISIBILITY_DISTANCE
);
4292 if(tmp
.datalong2
&& float(tmp
.datalong2
) < INTERACTION_DISTANCE
)
4294 sLog
.outErrorDb("Table `%s` has too small distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, min distance is %f or 0 for disable distance check",
4295 tablename
,tmp
.datalong2
,tmp
.id
,INTERACTION_DISTANCE
);
4302 case SCRIPT_COMMAND_REMOVE_AURA
:
4304 if(!sSpellStore
.LookupEntry(tmp
.datalong
))
4306 sLog
.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA or SCRIPT_COMMAND_CAST_SPELL for script id %u",
4307 tablename
,tmp
.datalong
,tmp
.id
);
4310 if(tmp
.datalong2
& ~0x1) // 1 bits (0,1)
4312 sLog
.outErrorDb("Table `%s` using unknown flags in datalong2 (%u)i n SCRIPT_COMMAND_CAST_SPELL for script id %u",
4313 tablename
,tmp
.datalong2
,tmp
.id
);
4318 case SCRIPT_COMMAND_CAST_SPELL
:
4320 if(!sSpellStore
.LookupEntry(tmp
.datalong
))
4322 sLog
.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA or SCRIPT_COMMAND_CAST_SPELL for script id %u",
4323 tablename
,tmp
.datalong
,tmp
.id
);
4326 if(tmp
.datalong2
& ~0x3) // 2 bits
4328 sLog
.outErrorDb("Table `%s` using unknown flags in datalong2 (%u)i n SCRIPT_COMMAND_CAST_SPELL for script id %u",
4329 tablename
,tmp
.datalong2
,tmp
.id
);
4336 if (scripts
.find(tmp
.id
) == scripts
.end())
4339 scripts
[tmp
.id
] = emptyMap
;
4341 scripts
[tmp
.id
].insert(std::pair
<uint32
, ScriptInfo
>(tmp
.delay
, tmp
));
4344 } while( result
->NextRow() );
4349 sLog
.outString( ">> Loaded %u script definitions", count
);
4352 void ObjectMgr::LoadGameObjectScripts()
4354 LoadScripts(sGameObjectScripts
, "gameobject_scripts");
4357 for(ScriptMapMap::const_iterator itr
= sGameObjectScripts
.begin(); itr
!= sGameObjectScripts
.end(); ++itr
)
4359 if(!GetGOData(itr
->first
))
4360 sLog
.outErrorDb("Table `gameobject_scripts` has not existing gameobject (GUID: %u) as script id",itr
->first
);
4364 void ObjectMgr::LoadQuestEndScripts()
4366 LoadScripts(sQuestEndScripts
, "quest_end_scripts");
4369 for(ScriptMapMap::const_iterator itr
= sQuestEndScripts
.begin(); itr
!= sQuestEndScripts
.end(); ++itr
)
4371 if(!GetQuestTemplate(itr
->first
))
4372 sLog
.outErrorDb("Table `quest_end_scripts` has not existing quest (Id: %u) as script id",itr
->first
);
4376 void ObjectMgr::LoadQuestStartScripts()
4378 LoadScripts(sQuestStartScripts
,"quest_start_scripts");
4381 for(ScriptMapMap::const_iterator itr
= sQuestStartScripts
.begin(); itr
!= sQuestStartScripts
.end(); ++itr
)
4383 if(!GetQuestTemplate(itr
->first
))
4384 sLog
.outErrorDb("Table `quest_start_scripts` has not existing quest (Id: %u) as script id",itr
->first
);
4388 void ObjectMgr::LoadSpellScripts()
4390 LoadScripts(sSpellScripts
, "spell_scripts");
4393 for(ScriptMapMap::const_iterator itr
= sSpellScripts
.begin(); itr
!= sSpellScripts
.end(); ++itr
)
4395 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
4399 sLog
.outErrorDb("Table `spell_scripts` has not existing spell (Id: %u) as script id",itr
->first
);
4403 //check for correct spellEffect
4405 for(int i
=0; i
<3; ++i
)
4407 // skip empty effects
4408 if( !spellInfo
->Effect
[i
] )
4411 if( spellInfo
->Effect
[i
] == SPELL_EFFECT_SCRIPT_EFFECT
)
4419 sLog
.outErrorDb("Table `spell_scripts` has unsupported spell (Id: %u) without SPELL_EFFECT_SCRIPT_EFFECT (%u) spell effect",itr
->first
,SPELL_EFFECT_SCRIPT_EFFECT
);
4423 void ObjectMgr::LoadEventScripts()
4425 LoadScripts(sEventScripts
, "event_scripts");
4427 std::set
<uint32
> evt_scripts
;
4428 // Load all possible script entries from gameobjects
4429 for(uint32 i
= 1; i
< sGOStorage
.MaxEntry
; ++i
)
4431 GameObjectInfo
const * goInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(i
);
4434 switch(goInfo
->type
)
4436 case GAMEOBJECT_TYPE_GOOBER
:
4437 if (goInfo
->goober
.eventId
)
4438 evt_scripts
.insert(goInfo
->goober
.eventId
);
4440 case GAMEOBJECT_TYPE_CHEST
:
4441 if (goInfo
->chest
.eventId
)
4442 evt_scripts
.insert(goInfo
->chest
.eventId
);
4444 case GAMEOBJECT_TYPE_CAMERA
:
4445 if (goInfo
->camera
.eventID
)
4446 evt_scripts
.insert(goInfo
->camera
.eventID
);
4452 // Load all possible script entries from spells
4453 for(uint32 i
= 1; i
< sSpellStore
.GetNumRows(); ++i
)
4455 SpellEntry
const * spell
= sSpellStore
.LookupEntry(i
);
4458 for(int j
=0; j
<3; ++j
)
4460 if( spell
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
)
4462 if (spell
->EffectMiscValue
[j
])
4463 evt_scripts
.insert(spell
->EffectMiscValue
[j
]);
4468 // Then check if all scripts are in above list of possible script entries
4469 for(ScriptMapMap::const_iterator itr
= sEventScripts
.begin(); itr
!= sEventScripts
.end(); ++itr
)
4471 std::set
<uint32
>::const_iterator itr2
= evt_scripts
.find(itr
->first
);
4472 if (itr2
== evt_scripts
.end())
4473 sLog
.outErrorDb("Table `event_scripts` has script (Id: %u) not referring to any gameobject_template type 10 data2 field, type 3 data6 field, type 13 data 2 field or any spell effect %u",
4474 itr
->first
, SPELL_EFFECT_SEND_EVENT
);
4478 void ObjectMgr::LoadGossipScripts()
4480 LoadScripts(sGossipScripts
, "gossip_scripts");
4482 // checks are done in LoadGossipMenuItems
4485 void ObjectMgr::LoadItemTexts()
4487 QueryResult
*result
= CharacterDatabase
.Query("SELECT id, text FROM item_text");
4497 sLog
.outString( ">> Loaded %u item pages", count
);
4501 barGoLink
bar( result
->GetRowCount() );
4508 fields
= result
->Fetch();
4510 mItemTexts
[ fields
[0].GetUInt32() ] = fields
[1].GetCppString();
4514 } while ( result
->NextRow() );
4519 sLog
.outString( ">> Loaded %u item texts", count
);
4522 void ObjectMgr::LoadPageTexts()
4524 sPageTextStore
.Free(); // for reload case
4526 sPageTextStore
.Load();
4527 sLog
.outString( ">> Loaded %u page texts", sPageTextStore
.RecordCount
);
4530 for(uint32 i
= 1; i
< sPageTextStore
.MaxEntry
; ++i
)
4532 // check data correctness
4533 PageText
const* page
= sPageTextStore
.LookupEntry
<PageText
>(i
);
4537 if(page
->Next_Page
&& !sPageTextStore
.LookupEntry
<PageText
>(page
->Next_Page
))
4539 sLog
.outErrorDb("Page text (Id: %u) has not existing next page (Id:%u)", i
,page
->Next_Page
);
4543 // detect circular reference
4544 std::set
<uint32
> checkedPages
;
4545 for(PageText
const* pageItr
= page
; pageItr
; pageItr
= sPageTextStore
.LookupEntry
<PageText
>(pageItr
->Next_Page
))
4547 if(!pageItr
->Next_Page
)
4549 checkedPages
.insert(pageItr
->Page_ID
);
4550 if(checkedPages
.find(pageItr
->Next_Page
)!=checkedPages
.end())
4552 std::ostringstream ss
;
4553 ss
<< "The text page(s) ";
4554 for (std::set
<uint32
>::iterator itr
= checkedPages
.begin();itr
!=checkedPages
.end(); ++itr
)
4556 ss
<< "create(s) a circular reference, which can cause the server to freeze. Changing Next_Page of page "
4557 << pageItr
->Page_ID
<<" to 0";
4558 sLog
.outErrorDb("%s", ss
.str().c_str());
4559 const_cast<PageText
*>(pageItr
)->Next_Page
= 0;
4566 void ObjectMgr::LoadPageTextLocales()
4568 mPageTextLocaleMap
.clear(); // need for reload case
4570 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");
4579 sLog
.outString(">> Loaded 0 PageText locale strings. DB table `locales_page_text` is empty.");
4583 barGoLink
bar(result
->GetRowCount());
4587 Field
*fields
= result
->Fetch();
4590 uint32 entry
= fields
[0].GetUInt32();
4592 PageTextLocale
& data
= mPageTextLocaleMap
[entry
];
4594 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
4596 std::string str
= fields
[i
].GetCppString();
4600 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4603 if(data
.Text
.size() <= idx
)
4604 data
.Text
.resize(idx
+1);
4606 data
.Text
[idx
] = str
;
4610 } while (result
->NextRow());
4615 sLog
.outString( ">> Loaded %lu PageText locale strings", (unsigned long)mPageTextLocaleMap
.size() );
4618 struct SQLInstanceLoader
: public SQLStorageLoaderBase
<SQLInstanceLoader
>
4621 void convert_from_str(uint32
/*field_pos*/, char *src
, D
&dst
)
4623 dst
= D(sObjectMgr
.GetScriptId(src
));
4627 void ObjectMgr::LoadInstanceTemplate()
4629 SQLInstanceLoader loader
;
4630 loader
.Load(sInstanceTemplate
);
4632 for(uint32 i
= 0; i
< sInstanceTemplate
.MaxEntry
; i
++)
4634 InstanceTemplate
* temp
= (InstanceTemplate
*)GetInstanceTemplate(i
);
4638 if(!MapManager::IsValidMAP(temp
->map
))
4639 sLog
.outErrorDb("ObjectMgr::LoadInstanceTemplate: bad mapid %d for template!", temp
->map
);
4641 if(!MapManager::IsValidMapCoord(temp
->parent
,temp
->startLocX
,temp
->startLocY
,temp
->startLocZ
,temp
->startLocO
))
4643 sLog
.outErrorDb("ObjectMgr::LoadInstanceTemplate: bad parent entrance coordinates for map id %d template!", temp
->map
);
4644 temp
->parent
= 0; // will have wrong continent 0 parent, at least existed
4648 sLog
.outString( ">> Loaded %u Instance Template definitions", sInstanceTemplate
.RecordCount
);
4652 GossipText
const *ObjectMgr::GetGossipText(uint32 Text_ID
) const
4654 GossipTextMap::const_iterator itr
= mGossipText
.find(Text_ID
);
4655 if(itr
!= mGossipText
.end())
4656 return &itr
->second
;
4660 void ObjectMgr::LoadGossipText()
4662 QueryResult
*result
= WorldDatabase
.Query( "SELECT * FROM npc_text" );
4671 sLog
.outString( ">> Loaded %u npc texts", count
);
4677 barGoLink
bar( result
->GetRowCount() );
4684 Field
*fields
= result
->Fetch();
4688 uint32 Text_ID
= fields
[cic
++].GetUInt32();
4691 sLog
.outErrorDb("Table `npc_text` has record wit reserved id 0, ignore.");
4695 GossipText
& gText
= mGossipText
[Text_ID
];
4697 for (int i
=0; i
< 8; i
++)
4699 gText
.Options
[i
].Text_0
= fields
[cic
++].GetCppString();
4700 gText
.Options
[i
].Text_1
= fields
[cic
++].GetCppString();
4702 gText
.Options
[i
].Language
= fields
[cic
++].GetUInt32();
4703 gText
.Options
[i
].Probability
= fields
[cic
++].GetFloat();
4705 for(int j
=0; j
< 3; ++j
)
4707 gText
.Options
[i
].Emotes
[j
]._Delay
= fields
[cic
++].GetUInt32();
4708 gText
.Options
[i
].Emotes
[j
]._Emote
= fields
[cic
++].GetUInt32();
4711 } while( result
->NextRow() );
4714 sLog
.outString( ">> Loaded %u npc texts", count
);
4718 void ObjectMgr::LoadNpcTextLocales()
4720 mNpcTextLocaleMap
.clear(); // need for reload case
4722 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,"
4723 "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,"
4724 "Text0_0_loc2,Text0_1_loc2,Text1_0_loc2,Text1_1_loc2,Text2_0_loc2,Text2_1_loc2,Text3_0_loc2,Text3_1_loc1,Text4_0_loc2,Text4_1_loc2,Text5_0_loc2,Text5_1_loc2,Text6_0_loc2,Text6_1_loc2,Text7_0_loc2,Text7_1_loc2,"
4725 "Text0_0_loc3,Text0_1_loc3,Text1_0_loc3,Text1_1_loc3,Text2_0_loc3,Text2_1_loc3,Text3_0_loc3,Text3_1_loc1,Text4_0_loc3,Text4_1_loc3,Text5_0_loc3,Text5_1_loc3,Text6_0_loc3,Text6_1_loc3,Text7_0_loc3,Text7_1_loc3,"
4726 "Text0_0_loc4,Text0_1_loc4,Text1_0_loc4,Text1_1_loc4,Text2_0_loc4,Text2_1_loc4,Text3_0_loc4,Text3_1_loc1,Text4_0_loc4,Text4_1_loc4,Text5_0_loc4,Text5_1_loc4,Text6_0_loc4,Text6_1_loc4,Text7_0_loc4,Text7_1_loc4,"
4727 "Text0_0_loc5,Text0_1_loc5,Text1_0_loc5,Text1_1_loc5,Text2_0_loc5,Text2_1_loc5,Text3_0_loc5,Text3_1_loc1,Text4_0_loc5,Text4_1_loc5,Text5_0_loc5,Text5_1_loc5,Text6_0_loc5,Text6_1_loc5,Text7_0_loc5,Text7_1_loc5,"
4728 "Text0_0_loc6,Text0_1_loc6,Text1_0_loc6,Text1_1_loc6,Text2_0_loc6,Text2_1_loc6,Text3_0_loc6,Text3_1_loc1,Text4_0_loc6,Text4_1_loc6,Text5_0_loc6,Text5_1_loc6,Text6_0_loc6,Text6_1_loc6,Text7_0_loc6,Text7_1_loc6,"
4729 "Text0_0_loc7,Text0_1_loc7,Text1_0_loc7,Text1_1_loc7,Text2_0_loc7,Text2_1_loc7,Text3_0_loc7,Text3_1_loc1,Text4_0_loc7,Text4_1_loc7,Text5_0_loc7,Text5_1_loc7,Text6_0_loc7,Text6_1_loc7,Text7_0_loc7,Text7_1_loc7, "
4730 "Text0_0_loc8,Text0_1_loc8,Text1_0_loc8,Text1_1_loc8,Text2_0_loc8,Text2_1_loc8,Text3_0_loc8,Text3_1_loc1,Text4_0_loc8,Text4_1_loc8,Text5_0_loc8,Text5_1_loc8,Text6_0_loc8,Text6_1_loc8,Text7_0_loc8,Text7_1_loc8 "
4731 " FROM locales_npc_text");
4740 sLog
.outString(">> Loaded 0 Quest locale strings. DB table `locales_npc_text` is empty.");
4744 barGoLink
bar(result
->GetRowCount());
4748 Field
*fields
= result
->Fetch();
4751 uint32 entry
= fields
[0].GetUInt32();
4753 NpcTextLocale
& data
= mNpcTextLocaleMap
[entry
];
4755 for(int i
=1; i
<MAX_LOCALE
; ++i
)
4757 for(int j
=0; j
<8; ++j
)
4759 std::string str0
= fields
[1+8*2*(i
-1)+2*j
].GetCppString();
4762 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4765 if(data
.Text_0
[j
].size() <= idx
)
4766 data
.Text_0
[j
].resize(idx
+1);
4768 data
.Text_0
[j
][idx
] = str0
;
4771 std::string str1
= fields
[1+8*2*(i
-1)+2*j
+1].GetCppString();
4774 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4777 if(data
.Text_1
[j
].size() <= idx
)
4778 data
.Text_1
[j
].resize(idx
+1);
4780 data
.Text_1
[j
][idx
] = str1
;
4785 } while (result
->NextRow());
4790 sLog
.outString( ">> Loaded %lu NpcText locale strings", (unsigned long)mNpcTextLocaleMap
.size() );
4793 //not very fast function but it is called only once a day, or on starting-up
4794 void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp
)
4796 time_t basetime
= time(NULL
);
4797 sLog
.outDebug("Returning mails current time: hour: %d, minute: %d, second: %d ", localtime(&basetime
)->tm_hour
, localtime(&basetime
)->tm_min
, localtime(&basetime
)->tm_sec
);
4798 //delete all old mails without item and without body immediately, if starting server
4800 CharacterDatabase
.PExecute("DELETE FROM mail WHERE expire_time < '" UI64FMTD
"' AND has_items = '0' AND itemTextId = 0", (uint64
)basetime
);
4801 // 0 1 2 3 4 5 6 7 8 9
4802 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT id,messageType,sender,receiver,itemTextId,has_items,expire_time,cod,checked,mailTemplateId FROM mail WHERE expire_time < '" UI64FMTD
"'", (uint64
)basetime
);
4808 sLog
.outString(">> Only expired mails (need to be return or delete) or DB table `mail` is empty.");
4809 return; // any mails need to be returned or deleted
4812 //std::ostringstream delitems, delmails; //will be here for optimization
4813 //bool deletemail = false, deleteitem = false;
4814 //delitems << "DELETE FROM item_instance WHERE guid IN ( ";
4815 //delmails << "DELETE FROM mail WHERE id IN ( "
4817 barGoLink
bar( result
->GetRowCount() );
4825 fields
= result
->Fetch();
4827 m
->messageID
= fields
[0].GetUInt32();
4828 m
->messageType
= fields
[1].GetUInt8();
4829 m
->sender
= fields
[2].GetUInt32();
4830 m
->receiver
= fields
[3].GetUInt32();
4831 m
->itemTextId
= fields
[4].GetUInt32();
4832 bool has_items
= fields
[5].GetBool();
4833 m
->expire_time
= (time_t)fields
[6].GetUInt64();
4834 m
->deliver_time
= 0;
4835 m
->COD
= fields
[7].GetUInt32();
4836 m
->checked
= fields
[8].GetUInt32();
4837 m
->mailTemplateId
= fields
[9].GetInt16();
4841 pl
= GetPlayer((uint64
)m
->receiver
);
4843 { //this code will run very improbably (the time is between 4 and 5 am, in game is online a player, who has old mail
4844 //his in mailbox and he has already listed his mails )
4848 //delete or return mail:
4851 QueryResult
*resultItems
= CharacterDatabase
.PQuery("SELECT item_guid,item_template FROM mail_items WHERE mail_id='%u'", m
->messageID
);
4856 Field
*fields2
= resultItems
->Fetch();
4858 uint32 item_guid_low
= fields2
[0].GetUInt32();
4859 uint32 item_template
= fields2
[1].GetUInt32();
4861 m
->AddItem(item_guid_low
, item_template
);
4863 while (resultItems
->NextRow());
4867 //if it is mail from AH, it shouldn't be returned, but deleted
4868 if (m
->messageType
!= MAIL_NORMAL
|| (m
->checked
& (MAIL_CHECK_MASK_AUCTION
| MAIL_CHECK_MASK_COD_PAYMENT
| MAIL_CHECK_MASK_RETURNED
)))
4870 // mail open and then not returned
4871 for(std::vector
<MailItemInfo
>::iterator itr2
= m
->items
.begin(); itr2
!= m
->items
.end(); ++itr2
)
4872 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", itr2
->item_guid
);
4876 //mail will be returned:
4877 CharacterDatabase
.PExecute("UPDATE mail SET sender = '%u', receiver = '%u', expire_time = '" UI64FMTD
"', deliver_time = '" UI64FMTD
"',cod = '0', checked = '%u' WHERE id = '%u'", m
->receiver
, m
->sender
, (uint64
)(basetime
+ 30*DAY
), (uint64
)basetime
, MAIL_CHECK_MASK_RETURNED
, m
->messageID
);
4884 CharacterDatabase
.PExecute("DELETE FROM item_text WHERE id = '%u'", m
->itemTextId
);
4886 //deletemail = true;
4887 //delmails << m->messageID << ", ";
4888 CharacterDatabase
.PExecute("DELETE FROM mail WHERE id = '%u'", m
->messageID
);
4891 } while (result
->NextRow());
4895 sLog
.outString( ">> Loaded %u mails", count
);
4898 void ObjectMgr::LoadQuestAreaTriggers()
4900 mQuestAreaTriggerMap
.clear(); // need for reload case
4902 QueryResult
*result
= WorldDatabase
.Query( "SELECT id,quest FROM areatrigger_involvedrelation" );
4912 sLog
.outString( ">> Loaded %u quest trigger points", count
);
4916 barGoLink
bar( result
->GetRowCount() );
4923 Field
*fields
= result
->Fetch();
4925 uint32 trigger_ID
= fields
[0].GetUInt32();
4926 uint32 quest_ID
= fields
[1].GetUInt32();
4928 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(trigger_ID
);
4931 sLog
.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",trigger_ID
);
4935 Quest
const* quest
= GetQuestTemplate(quest_ID
);
4939 sLog
.outErrorDb("Table `areatrigger_involvedrelation` has record (id: %u) for not existing quest %u",trigger_ID
,quest_ID
);
4943 if(!quest
->HasFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
))
4945 sLog
.outErrorDb("Table `areatrigger_involvedrelation` has record (id: %u) for not quest %u, but quest not have flag QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT. Trigger or quest flags must be fixed, quest modified to require objective.",trigger_ID
,quest_ID
);
4947 // this will prevent quest completing without objective
4948 const_cast<Quest
*>(quest
)->SetFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
);
4950 // continue; - quest modified to required objective and trigger can be allowed.
4953 mQuestAreaTriggerMap
[trigger_ID
] = quest_ID
;
4955 } while( result
->NextRow() );
4960 sLog
.outString( ">> Loaded %u quest trigger points", count
);
4963 void ObjectMgr::LoadTavernAreaTriggers()
4965 mTavernAreaTriggerSet
.clear(); // need for reload case
4967 QueryResult
*result
= WorldDatabase
.Query("SELECT id FROM areatrigger_tavern");
4977 sLog
.outString( ">> Loaded %u tavern triggers", count
);
4981 barGoLink
bar( result
->GetRowCount() );
4988 Field
*fields
= result
->Fetch();
4990 uint32 Trigger_ID
= fields
[0].GetUInt32();
4992 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(Trigger_ID
);
4995 sLog
.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID
);
4999 mTavernAreaTriggerSet
.insert(Trigger_ID
);
5000 } while( result
->NextRow() );
5005 sLog
.outString( ">> Loaded %u tavern triggers", count
);
5008 void ObjectMgr::LoadAreaTriggerScripts()
5010 mAreaTriggerScripts
.clear(); // need for reload case
5011 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, ScriptName FROM areatrigger_scripts");
5021 sLog
.outString( ">> Loaded %u areatrigger scripts", count
);
5025 barGoLink
bar( result
->GetRowCount() );
5032 Field
*fields
= result
->Fetch();
5034 uint32 Trigger_ID
= fields
[0].GetUInt32();
5035 const char *scriptName
= fields
[1].GetString();
5037 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(Trigger_ID
);
5040 sLog
.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID
);
5043 mAreaTriggerScripts
[Trigger_ID
] = GetScriptId(scriptName
);
5044 } while( result
->NextRow() );
5049 sLog
.outString( ">> Loaded %u areatrigger scripts", count
);
5052 uint32
ObjectMgr::GetNearestTaxiNode( float x
, float y
, float z
, uint32 mapid
, uint32 team
)
5058 for(uint32 i
= 1; i
< sTaxiNodesStore
.GetNumRows(); ++i
)
5060 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(i
);
5061 if(!node
|| node
->map_id
!= mapid
|| !node
->MountCreatureID
[team
== ALLIANCE
? 1 : 0])
5064 uint8 field
= (uint8
)((i
- 1) / 32);
5065 uint32 submask
= 1<<((i
-1)%32);
5067 // skip not taxi network nodes
5068 if((sTaxiNodesMask
[field
] & submask
)==0)
5071 float dist2
= (node
->x
- x
)*(node
->x
- x
)+(node
->y
- y
)*(node
->y
- y
)+(node
->z
- z
)*(node
->z
- z
);
5091 void ObjectMgr::GetTaxiPath( uint32 source
, uint32 destination
, uint32
&path
, uint32
&cost
)
5093 TaxiPathSetBySource::iterator src_i
= sTaxiPathSetBySource
.find(source
);
5094 if(src_i
==sTaxiPathSetBySource
.end())
5101 TaxiPathSetForSource
& pathSet
= src_i
->second
;
5103 TaxiPathSetForSource::iterator dest_i
= pathSet
.find(destination
);
5104 if(dest_i
==pathSet
.end())
5111 cost
= dest_i
->second
.price
;
5112 path
= dest_i
->second
.ID
;
5115 uint32
ObjectMgr::GetTaxiMountDisplayId( uint32 id
, uint32 team
, bool allowed_alt_team
/* = false */)
5117 uint16 mount_entry
= 0;
5119 // select mount creature id
5120 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(id
);
5123 if (team
== ALLIANCE
)
5125 mount_entry
= node
->MountCreatureID
[1];
5126 if(!mount_entry
&& allowed_alt_team
)
5127 mount_entry
= node
->MountCreatureID
[0];
5129 else if (team
== HORDE
)
5131 mount_entry
= node
->MountCreatureID
[0];
5133 if(!mount_entry
&& allowed_alt_team
)
5134 mount_entry
= node
->MountCreatureID
[1];
5138 CreatureInfo
const *mount_info
= GetCreatureTemplate(mount_entry
);
5142 uint16 mount_id
= ChooseDisplayId(team
,mount_info
);
5146 CreatureModelInfo
const *minfo
= GetCreatureModelRandomGender(mount_id
);
5148 mount_id
= minfo
->modelid
;
5153 void ObjectMgr::GetTaxiPathNodes( uint32 path
, Path
&pathnodes
, std::vector
<uint32
>& mapIds
)
5155 if(path
>= sTaxiPathNodesByPath
.size())
5158 TaxiPathNodeList
& nodeList
= sTaxiPathNodesByPath
[path
];
5160 pathnodes
.Resize(nodeList
.size());
5161 mapIds
.resize(nodeList
.size());
5163 for(size_t i
= 0; i
< nodeList
.size(); ++i
)
5165 pathnodes
[ i
].x
= nodeList
[i
].x
;
5166 pathnodes
[ i
].y
= nodeList
[i
].y
;
5167 pathnodes
[ i
].z
= nodeList
[i
].z
;
5169 mapIds
[i
] = nodeList
[i
].mapid
;
5173 void ObjectMgr::GetTransportPathNodes( uint32 path
, TransportPath
&pathnodes
)
5175 if(path
>= sTaxiPathNodesByPath
.size())
5178 TaxiPathNodeList
& nodeList
= sTaxiPathNodesByPath
[path
];
5180 pathnodes
.Resize(nodeList
.size());
5182 for(size_t i
= 0; i
< nodeList
.size(); ++i
)
5184 pathnodes
[ i
].mapid
= nodeList
[i
].mapid
;
5185 pathnodes
[ i
].x
= nodeList
[i
].x
;
5186 pathnodes
[ i
].y
= nodeList
[i
].y
;
5187 pathnodes
[ i
].z
= nodeList
[i
].z
;
5188 pathnodes
[ i
].actionFlag
= nodeList
[i
].actionFlag
;
5189 pathnodes
[ i
].delay
= nodeList
[i
].delay
;
5193 void ObjectMgr::LoadGraveyardZones()
5195 mGraveYardMap
.clear(); // need for reload case
5197 QueryResult
*result
= WorldDatabase
.Query("SELECT id,ghost_zone,faction FROM game_graveyard_zone");
5207 sLog
.outString( ">> Loaded %u graveyard-zone links", count
);
5211 barGoLink
bar( result
->GetRowCount() );
5218 Field
*fields
= result
->Fetch();
5220 uint32 safeLocId
= fields
[0].GetUInt32();
5221 uint32 zoneId
= fields
[1].GetUInt32();
5222 uint32 team
= fields
[2].GetUInt32();
5224 WorldSafeLocsEntry
const* entry
= sWorldSafeLocsStore
.LookupEntry(safeLocId
);
5227 sLog
.outErrorDb("Table `game_graveyard_zone` has record for not existing graveyard (WorldSafeLocs.dbc id) %u, skipped.",safeLocId
);
5231 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
5234 sLog
.outErrorDb("Table `game_graveyard_zone` has record for not existing zone id (%u), skipped.",zoneId
);
5238 if(areaEntry
->zone
!= 0)
5240 sLog
.outErrorDb("Table `game_graveyard_zone` has record subzone id (%u) instead of zone, skipped.",zoneId
);
5244 if(team
!=0 && team
!=HORDE
&& team
!=ALLIANCE
)
5246 sLog
.outErrorDb("Table `game_graveyard_zone` has record for non player faction (%u), skipped.",team
);
5250 if(!AddGraveYardLink(safeLocId
,zoneId
,team
,false))
5251 sLog
.outErrorDb("Table `game_graveyard_zone` has a duplicate record for Graveyard (ID: %u) and Zone (ID: %u), skipped.",safeLocId
,zoneId
);
5252 } while( result
->NextRow() );
5257 sLog
.outString( ">> Loaded %u graveyard-zone links", count
);
5260 WorldSafeLocsEntry
const *ObjectMgr::GetClosestGraveYard(float x
, float y
, float z
, uint32 MapId
, uint32 team
)
5262 // search for zone associated closest graveyard
5263 uint32 zoneId
= sMapMgr
.GetZoneId(MapId
,x
,y
,z
);
5265 // Simulate std. algorithm:
5266 // found some graveyard associated to (ghost_zone,ghost_map)
5268 // if mapId == graveyard.mapId (ghost in plain zone or city or battleground) and search graveyard at same map
5269 // then check faction
5270 // if mapId != graveyard.mapId (ghost in instance) and search any graveyard associated
5271 // then check faction
5272 GraveYardMap::const_iterator graveLow
= mGraveYardMap
.lower_bound(zoneId
);
5273 GraveYardMap::const_iterator graveUp
= mGraveYardMap
.upper_bound(zoneId
);
5274 if(graveLow
==graveUp
)
5276 sLog
.outErrorDb("Table `game_graveyard_zone` incomplete: Zone %u Team %u does not have a linked graveyard.",zoneId
,team
);
5281 bool foundNear
= false;
5283 WorldSafeLocsEntry
const* entryNear
= NULL
;
5285 // at entrance map for corpse map
5286 bool foundEntr
= false;
5288 WorldSafeLocsEntry
const* entryEntr
= NULL
;
5291 WorldSafeLocsEntry
const* entryFar
= NULL
;
5293 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(MapId
);
5295 for(GraveYardMap::const_iterator itr
= graveLow
; itr
!= graveUp
; ++itr
)
5297 GraveYardData
const& data
= itr
->second
;
5299 WorldSafeLocsEntry
const* entry
= sWorldSafeLocsStore
.LookupEntry(data
.safeLocId
);
5302 sLog
.outErrorDb("Table `game_graveyard_zone` has record for not existing graveyard (WorldSafeLocs.dbc id) %u, skipped.",data
.safeLocId
);
5306 // skip enemy faction graveyard
5307 // team == 0 case can be at call from .neargrave
5308 if(data
.team
!= 0 && team
!= 0 && data
.team
!= team
)
5311 // find now nearest graveyard at other map
5312 if(MapId
!= entry
->map_id
)
5314 // if find graveyard at different map from where entrance placed (or no entrance data), use any first
5316 mapEntry
->entrance_map
< 0 ||
5317 mapEntry
->entrance_map
!= entry
->map_id
||
5318 (mapEntry
->entrance_x
== 0 && mapEntry
->entrance_y
== 0))
5320 // not have any corrdinates for check distance anyway
5325 // at entrance map calculate distance (2D);
5326 float dist2
= (entry
->x
- mapEntry
->entrance_x
)*(entry
->x
- mapEntry
->entrance_x
)
5327 +(entry
->y
- mapEntry
->entrance_y
)*(entry
->y
- mapEntry
->entrance_y
);
5330 if(dist2
< distEntr
)
5343 // find now nearest graveyard at same map
5346 float dist2
= (entry
->x
- x
)*(entry
->x
- x
)+(entry
->y
- y
)*(entry
->y
- y
)+(entry
->z
- z
)*(entry
->z
- z
);
5349 if(dist2
< distNear
)
5373 GraveYardData
const* ObjectMgr::FindGraveYardData(uint32 id
, uint32 zoneId
)
5375 GraveYardMap::const_iterator graveLow
= mGraveYardMap
.lower_bound(zoneId
);
5376 GraveYardMap::const_iterator graveUp
= mGraveYardMap
.upper_bound(zoneId
);
5378 for(GraveYardMap::const_iterator itr
= graveLow
; itr
!= graveUp
; ++itr
)
5380 if(itr
->second
.safeLocId
==id
)
5381 return &itr
->second
;
5387 bool ObjectMgr::AddGraveYardLink(uint32 id
, uint32 zoneId
, uint32 team
, bool inDB
)
5389 if(FindGraveYardData(id
,zoneId
))
5392 // add link to loaded data
5394 data
.safeLocId
= id
;
5397 mGraveYardMap
.insert(GraveYardMap::value_type(zoneId
,data
));
5402 WorldDatabase
.PExecuteLog("INSERT INTO game_graveyard_zone ( id,ghost_zone,faction) "
5403 "VALUES ('%u', '%u','%u')",id
,zoneId
,team
);
5409 void ObjectMgr::LoadAreaTriggerTeleports()
5411 mAreaTriggers
.clear(); // need for reload case
5415 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13
5416 QueryResult
*result
= WorldDatabase
.Query("SELECT id, required_level, required_item, required_item2, heroic_key, heroic_key2, required_quest_done, required_quest_done_heroic, required_failed_text, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM areatrigger_teleport");
5425 sLog
.outString( ">> Loaded %u area trigger teleport definitions", count
);
5429 barGoLink
bar( result
->GetRowCount() );
5433 Field
*fields
= result
->Fetch();
5439 uint32 Trigger_ID
= fields
[0].GetUInt32();
5443 at
.requiredLevel
= fields
[1].GetUInt8();
5444 at
.requiredItem
= fields
[2].GetUInt32();
5445 at
.requiredItem2
= fields
[3].GetUInt32();
5446 at
.heroicKey
= fields
[4].GetUInt32();
5447 at
.heroicKey2
= fields
[5].GetUInt32();
5448 at
.requiredQuest
= fields
[6].GetUInt32();
5449 at
.requiredQuestHeroic
= fields
[7].GetUInt32();
5450 at
.requiredFailedText
= fields
[8].GetCppString();
5451 at
.target_mapId
= fields
[9].GetUInt32();
5452 at
.target_X
= fields
[10].GetFloat();
5453 at
.target_Y
= fields
[11].GetFloat();
5454 at
.target_Z
= fields
[12].GetFloat();
5455 at
.target_Orientation
= fields
[13].GetFloat();
5457 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(Trigger_ID
);
5460 sLog
.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID
);
5466 ItemPrototype
const *pProto
= GetItemPrototype(at
.requiredItem
);
5469 sLog
.outError("Key item %u does not exist for trigger %u, removing key requirement.", at
.requiredItem
, Trigger_ID
);
5470 at
.requiredItem
= 0;
5473 if(at
.requiredItem2
)
5475 ItemPrototype
const *pProto
= GetItemPrototype(at
.requiredItem2
);
5478 sLog
.outError("Second item %u not exist for trigger %u, remove key requirement.", at
.requiredItem2
, Trigger_ID
);
5479 at
.requiredItem2
= 0;
5485 ItemPrototype
const *pProto
= GetItemPrototype(at
.heroicKey
);
5488 sLog
.outError("Heroic key item %u not exist for trigger %u, remove key requirement.", at
.heroicKey
, Trigger_ID
);
5495 ItemPrototype
const *pProto
= GetItemPrototype(at
.heroicKey2
);
5498 sLog
.outError("Heroic second key item %u not exist for trigger %u, remove key requirement.", at
.heroicKey2
, Trigger_ID
);
5503 if(at
.requiredQuest
)
5505 QuestMap::iterator qReqItr
= mQuestTemplates
.find(at
.requiredQuest
);
5506 if(qReqItr
== mQuestTemplates
.end())
5508 sLog
.outErrorDb("Required Quest %u not exist for trigger %u, remove quest done requirement.",at
.requiredQuest
,Trigger_ID
);
5509 at
.requiredQuest
= 0;
5513 if(at
.requiredQuestHeroic
)
5515 QuestMap::iterator qReqItr
= mQuestTemplates
.find(at
.requiredQuestHeroic
);
5516 if(qReqItr
== mQuestTemplates
.end())
5518 sLog
.outErrorDb("Required Quest %u not exist for trigger %u, remove quest done requirement.",at
.requiredQuestHeroic
,Trigger_ID
);
5519 at
.requiredQuestHeroic
= 0;
5523 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(at
.target_mapId
);
5526 sLog
.outErrorDb("Area trigger (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Trigger_ID
,at
.target_mapId
);
5530 if(at
.target_X
==0 && at
.target_Y
==0 && at
.target_Z
==0)
5532 sLog
.outErrorDb("Area trigger (ID:%u) target coordinates not provided.",Trigger_ID
);
5536 mAreaTriggers
[Trigger_ID
] = at
;
5538 } while( result
->NextRow() );
5543 sLog
.outString( ">> Loaded %u area trigger teleport definitions", count
);
5547 * Searches for the areatrigger which teleports players out of the given map
5549 AreaTrigger
const* ObjectMgr::GetGoBackTrigger(uint32 Map
) const
5551 const MapEntry
*mapEntry
= sMapStore
.LookupEntry(Map
);
5552 if(!mapEntry
) return NULL
;
5553 for (AreaTriggerMap::const_iterator itr
= mAreaTriggers
.begin(); itr
!= mAreaTriggers
.end(); ++itr
)
5555 if(itr
->second
.target_mapId
== mapEntry
->entrance_map
)
5557 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(itr
->first
);
5558 if(atEntry
&& atEntry
->mapid
== Map
)
5559 return &itr
->second
;
5566 * Searches for the areatrigger which teleports players to the given map
5568 AreaTrigger
const* ObjectMgr::GetMapEntranceTrigger(uint32 Map
) const
5570 for (AreaTriggerMap::const_iterator itr
= mAreaTriggers
.begin(); itr
!= mAreaTriggers
.end(); ++itr
)
5572 if(itr
->second
.target_mapId
== Map
)
5574 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(itr
->first
);
5576 return &itr
->second
;
5582 void ObjectMgr::SetHighestGuids()
5584 QueryResult
*result
= CharacterDatabase
.Query( "SELECT MAX(guid) FROM characters" );
5587 m_hiCharGuid
= (*result
)[0].GetUInt32()+1;
5591 result
= WorldDatabase
.Query( "SELECT MAX(guid) FROM creature" );
5594 m_hiCreatureGuid
= (*result
)[0].GetUInt32()+1;
5598 result
= CharacterDatabase
.Query( "SELECT MAX(guid) FROM item_instance" );
5601 m_hiItemGuid
= (*result
)[0].GetUInt32()+1;
5605 // Cleanup other tables from not existed guids (>=m_hiItemGuid)
5606 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", m_hiItemGuid
);
5607 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE item_guid >= '%u'", m_hiItemGuid
);
5608 CharacterDatabase
.PExecute("DELETE FROM auctionhouse WHERE itemguid >= '%u'", m_hiItemGuid
);
5609 CharacterDatabase
.PExecute("DELETE FROM guild_bank_item WHERE item_guid >= '%u'", m_hiItemGuid
);
5611 result
= WorldDatabase
.Query("SELECT MAX(guid) FROM gameobject" );
5614 m_hiGoGuid
= (*result
)[0].GetUInt32()+1;
5618 result
= CharacterDatabase
.Query("SELECT MAX(id) FROM auctionhouse" );
5621 m_auctionid
= (*result
)[0].GetUInt32()+1;
5625 result
= CharacterDatabase
.Query( "SELECT MAX(id) FROM mail" );
5628 m_mailid
= (*result
)[0].GetUInt32()+1;
5632 result
= CharacterDatabase
.Query( "SELECT MAX(id) FROM item_text" );
5635 m_ItemTextId
= (*result
)[0].GetUInt32()+1;
5639 result
= CharacterDatabase
.Query( "SELECT MAX(guid) FROM corpse" );
5642 m_hiCorpseGuid
= (*result
)[0].GetUInt32()+1;
5646 result
= CharacterDatabase
.Query("SELECT MAX(arenateamid) FROM arena_team");
5649 m_arenaTeamId
= (*result
)[0].GetUInt32()+1;
5653 result
= CharacterDatabase
.Query("SELECT MAX(setguid) FROM character_equipmentsets");
5656 m_equipmentSetGuid
= (*result
)[0].GetUInt64()+1;
5660 result
= CharacterDatabase
.Query( "SELECT MAX(guildid) FROM guild" );
5663 m_guildId
= (*result
)[0].GetUInt32()+1;
5668 uint32
ObjectMgr::GenerateArenaTeamId()
5670 if(m_arenaTeamId
>=0xFFFFFFFE)
5672 sLog
.outError("Arena team ids overflow!! Can't continue, shutting down server. ");
5673 World::StopNow(ERROR_EXIT_CODE
);
5675 return m_arenaTeamId
++;
5678 uint32
ObjectMgr::GenerateAuctionID()
5680 if(m_auctionid
>=0xFFFFFFFE)
5682 sLog
.outError("Auctions ids overflow!! Can't continue, shutting down server. ");
5683 World::StopNow(ERROR_EXIT_CODE
);
5685 return m_auctionid
++;
5688 uint64
ObjectMgr::GenerateEquipmentSetGuid()
5690 if(m_equipmentSetGuid
>=0xFFFFFFFFFFFFFFFEll
)
5692 sLog
.outError("EquipmentSet guid overflow!! Can't continue, shutting down server. ");
5693 World::StopNow(ERROR_EXIT_CODE
);
5695 return m_equipmentSetGuid
++;
5698 uint32
ObjectMgr::GenerateGuildId()
5700 if(m_guildId
>=0xFFFFFFFE)
5702 sLog
.outError("Guild ids overflow!! Can't continue, shutting down server. ");
5703 World::StopNow(ERROR_EXIT_CODE
);
5708 uint32
ObjectMgr::GenerateMailID()
5710 if(m_mailid
>=0xFFFFFFFE)
5712 sLog
.outError("Mail ids overflow!! Can't continue, shutting down server. ");
5713 World::StopNow(ERROR_EXIT_CODE
);
5718 uint32
ObjectMgr::GenerateItemTextID()
5720 if(m_ItemTextId
>=0xFFFFFFFE)
5722 sLog
.outError("Item text ids overflow!! Can't continue, shutting down server. ");
5723 World::StopNow(ERROR_EXIT_CODE
);
5725 return m_ItemTextId
++;
5728 uint32
ObjectMgr::CreateItemText(std::string text
)
5730 uint32 newItemTextId
= GenerateItemTextID();
5731 //insert new itempage to container
5732 mItemTexts
[ newItemTextId
] = text
;
5734 CharacterDatabase
.escape_string(text
);
5735 //any Delete query needed, itemTextId is maximum of all ids
5736 std::ostringstream query
;
5737 query
<< "INSERT INTO item_text (id,text) VALUES ( '" << newItemTextId
<< "', '" << text
<< "')";
5738 CharacterDatabase
.Execute(query
.str().c_str()); //needs to be run this way, because mail body may be more than 1024 characters
5739 return newItemTextId
;
5742 uint32
ObjectMgr::GenerateLowGuid(HighGuid guidhigh
)
5747 if(m_hiItemGuid
>=0xFFFFFFFE)
5749 sLog
.outError("Item guid overflow!! Can't continue, shutting down server. ");
5750 World::StopNow(ERROR_EXIT_CODE
);
5752 return m_hiItemGuid
++;
5754 if(m_hiCreatureGuid
>=0x00FFFFFE)
5756 sLog
.outError("Creature guid overflow!! Can't continue, shutting down server. ");
5757 World::StopNow(ERROR_EXIT_CODE
);
5759 return m_hiCreatureGuid
++;
5760 case HIGHGUID_PLAYER
:
5761 if(m_hiCharGuid
>=0xFFFFFFFE)
5763 sLog
.outError("Players guid overflow!! Can't continue, shutting down server. ");
5764 World::StopNow(ERROR_EXIT_CODE
);
5766 return m_hiCharGuid
++;
5767 case HIGHGUID_GAMEOBJECT
:
5768 if(m_hiGoGuid
>=0x00FFFFFE)
5770 sLog
.outError("Gameobject guid overflow!! Can't continue, shutting down server. ");
5771 World::StopNow(ERROR_EXIT_CODE
);
5773 return m_hiGoGuid
++;
5774 case HIGHGUID_CORPSE
:
5775 if(m_hiCorpseGuid
>=0xFFFFFFFE)
5777 sLog
.outError("Corpse guid overflow!! Can't continue, shutting down server. ");
5778 World::StopNow(ERROR_EXIT_CODE
);
5780 return m_hiCorpseGuid
++;
5789 void ObjectMgr::LoadGameObjectLocales()
5791 mGameObjectLocaleMap
.clear(); // need for reload case
5793 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,"
5794 "name_loc1,name_loc2,name_loc3,name_loc4,name_loc5,name_loc6,name_loc7,name_loc8,"
5795 "castbarcaption_loc1,castbarcaption_loc2,castbarcaption_loc3,castbarcaption_loc4,"
5796 "castbarcaption_loc5,castbarcaption_loc6,castbarcaption_loc7,castbarcaption_loc8 FROM locales_gameobject");
5805 sLog
.outString(">> Loaded 0 gameobject locale strings. DB table `locales_gameobject` is empty.");
5809 barGoLink
bar(result
->GetRowCount());
5813 Field
*fields
= result
->Fetch();
5816 uint32 entry
= fields
[0].GetUInt32();
5818 GameObjectLocale
& data
= mGameObjectLocaleMap
[entry
];
5820 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
5822 std::string str
= fields
[i
].GetCppString();
5825 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
5828 if(data
.Name
.size() <= idx
)
5829 data
.Name
.resize(idx
+1);
5831 data
.Name
[idx
] = str
;
5836 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
5838 std::string str
= fields
[i
+(MAX_LOCALE
-1)].GetCppString();
5841 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
5844 if(data
.CastBarCaption
.size() <= idx
)
5845 data
.CastBarCaption
.resize(idx
+1);
5847 data
.CastBarCaption
[idx
] = str
;
5852 } while (result
->NextRow());
5857 sLog
.outString( ">> Loaded %lu gameobject locale strings", (unsigned long)mGameObjectLocaleMap
.size() );
5860 struct SQLGameObjectLoader
: public SQLStorageLoaderBase
<SQLGameObjectLoader
>
5863 void convert_from_str(uint32
/*field_pos*/, char *src
, D
&dst
)
5865 dst
= D(sObjectMgr
.GetScriptId(src
));
5869 inline void CheckGOLockId(GameObjectInfo
const* goInfo
,uint32 dataN
,uint32 N
)
5871 if (sLockStore
.LookupEntry(dataN
))
5874 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but lock (Id: %u) not found.",
5875 goInfo
->id
,goInfo
->type
,N
,dataN
,dataN
);
5878 inline void CheckGOLinkedTrapId(GameObjectInfo
const* goInfo
,uint32 dataN
,uint32 N
)
5880 if (GameObjectInfo
const* trapInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(dataN
))
5882 if (trapInfo
->type
!=GAMEOBJECT_TYPE_TRAP
)
5883 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but GO (Entry %u) have not GAMEOBJECT_TYPE_TRAP (%u) type.",
5884 goInfo
->id
,goInfo
->type
,N
,dataN
,dataN
,GAMEOBJECT_TYPE_TRAP
);
5886 /* disable check for while (too many error reports baout not existed in trap templates
5888 sLog.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but trap GO (Entry %u) not exist in `gameobject_template`.",
5889 goInfo->id,goInfo->type,N,dataN,dataN);
5893 inline void CheckGOSpellId(GameObjectInfo
const* goInfo
,uint32 dataN
,uint32 N
)
5895 if (sSpellStore
.LookupEntry(dataN
))
5898 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but Spell (Entry %u) not exist.",
5899 goInfo
->id
,goInfo
->type
,N
,dataN
,dataN
);
5902 inline void CheckAndFixGOChairHeightId(GameObjectInfo
const* goInfo
,uint32
const& dataN
,uint32 N
)
5904 if (dataN
<= (UNIT_STAND_STATE_SIT_HIGH_CHAIR
-UNIT_STAND_STATE_SIT_LOW_CHAIR
) )
5907 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but correct chair height in range 0..%i.",
5908 goInfo
->id
,goInfo
->type
,N
,dataN
,UNIT_STAND_STATE_SIT_HIGH_CHAIR
-UNIT_STAND_STATE_SIT_LOW_CHAIR
);
5910 // prevent client and server unexpected work
5911 const_cast<uint32
&>(dataN
) = 0;
5914 inline void CheckGONoDamageImmuneId(GameObjectInfo
const* goInfo
,uint32 dataN
,uint32 N
)
5916 // 0/1 correct values
5920 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but expected boolean (0/1) noDamageImmune field value.",
5921 goInfo
->id
,goInfo
->type
,N
,dataN
);
5924 inline void CheckGOConsumable(GameObjectInfo
const* goInfo
,uint32 dataN
,uint32 N
)
5926 // 0/1 correct values
5930 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but expected boolean (0/1) consumable field value.",
5931 goInfo
->id
,goInfo
->type
,N
,dataN
);
5934 void ObjectMgr::LoadGameobjectInfo()
5936 SQLGameObjectLoader loader
;
5937 loader
.Load(sGOStorage
);
5940 for(uint32 id
= 1; id
< sGOStorage
.MaxEntry
; id
++)
5942 GameObjectInfo
const* goInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
5946 // some GO types have unused go template, check goInfo->displayId at GO spawn data loading or ignore
5948 switch(goInfo
->type
)
5950 case GAMEOBJECT_TYPE_DOOR
: //0
5952 if (goInfo
->door
.lockId
)
5953 CheckGOLockId(goInfo
,goInfo
->door
.lockId
,1);
5954 CheckGONoDamageImmuneId(goInfo
,goInfo
->door
.noDamageImmune
,3);
5957 case GAMEOBJECT_TYPE_BUTTON
: //1
5959 if (goInfo
->button
.lockId
)
5960 CheckGOLockId(goInfo
,goInfo
->button
.lockId
,1);
5961 CheckGONoDamageImmuneId(goInfo
,goInfo
->button
.noDamageImmune
,4);
5964 case GAMEOBJECT_TYPE_QUESTGIVER
: //2
5966 if (goInfo
->questgiver
.lockId
)
5967 CheckGOLockId(goInfo
,goInfo
->questgiver
.lockId
,0);
5968 CheckGONoDamageImmuneId(goInfo
,goInfo
->questgiver
.noDamageImmune
,5);
5971 case GAMEOBJECT_TYPE_CHEST
: //3
5973 if (goInfo
->chest
.lockId
)
5974 CheckGOLockId(goInfo
,goInfo
->chest
.lockId
,0);
5976 CheckGOConsumable(goInfo
,goInfo
->chest
.consumable
,3);
5978 if (goInfo
->chest
.linkedTrapId
) // linked trap
5979 CheckGOLinkedTrapId(goInfo
,goInfo
->chest
.linkedTrapId
,7);
5982 case GAMEOBJECT_TYPE_TRAP
: //6
5984 if (goInfo
->trap
.lockId
)
5985 CheckGOLockId(goInfo
,goInfo
->trap
.lockId
,0);
5986 /* disable check for while, too many not existed spells
5987 if (goInfo->trap.spellId) // spell
5988 CheckGOSpellId(goInfo,goInfo->trap.spellId,3);
5992 case GAMEOBJECT_TYPE_CHAIR
: //7
5993 CheckAndFixGOChairHeightId(goInfo
,goInfo
->chair
.height
,1);
5995 case GAMEOBJECT_TYPE_SPELL_FOCUS
: //8
5997 if (goInfo
->spellFocus
.focusId
)
5999 if (!sSpellFocusObjectStore
.LookupEntry(goInfo
->spellFocus
.focusId
))
6000 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data0=%u but SpellFocus (Id: %u) not exist.",
6001 id
,goInfo
->type
,goInfo
->spellFocus
.focusId
,goInfo
->spellFocus
.focusId
);
6004 if (goInfo
->spellFocus
.linkedTrapId
) // linked trap
6005 CheckGOLinkedTrapId(goInfo
,goInfo
->spellFocus
.linkedTrapId
,2);
6008 case GAMEOBJECT_TYPE_GOOBER
: //10
6010 if (goInfo
->goober
.lockId
)
6011 CheckGOLockId(goInfo
,goInfo
->goober
.lockId
,0);
6013 CheckGOConsumable(goInfo
,goInfo
->goober
.consumable
,3);
6015 if (goInfo
->goober
.pageId
) // pageId
6017 if (!sPageTextStore
.LookupEntry
<PageText
>(goInfo
->goober
.pageId
))
6018 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data7=%u but PageText (Entry %u) not exist.",
6019 id
,goInfo
->type
,goInfo
->goober
.pageId
,goInfo
->goober
.pageId
);
6021 /* disable check for while, too many not existed spells
6022 if (goInfo->goober.spellId) // spell
6023 CheckGOSpellId(goInfo,goInfo->goober.spellId,10);
6025 CheckGONoDamageImmuneId(goInfo
,goInfo
->goober
.noDamageImmune
,11);
6026 if (goInfo
->goober
.linkedTrapId
) // linked trap
6027 CheckGOLinkedTrapId(goInfo
,goInfo
->goober
.linkedTrapId
,12);
6030 case GAMEOBJECT_TYPE_AREADAMAGE
: //12
6032 if (goInfo
->areadamage
.lockId
)
6033 CheckGOLockId(goInfo
,goInfo
->areadamage
.lockId
,0);
6036 case GAMEOBJECT_TYPE_CAMERA
: //13
6038 if (goInfo
->camera
.lockId
)
6039 CheckGOLockId(goInfo
,goInfo
->camera
.lockId
,0);
6042 case GAMEOBJECT_TYPE_MO_TRANSPORT
: //15
6044 if (goInfo
->moTransport
.taxiPathId
)
6046 if (goInfo
->moTransport
.taxiPathId
>= sTaxiPathNodesByPath
.size() || sTaxiPathNodesByPath
[goInfo
->moTransport
.taxiPathId
].empty())
6047 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data0=%u but TaxiPath (Id: %u) not exist.",
6048 id
,goInfo
->type
,goInfo
->moTransport
.taxiPathId
,goInfo
->moTransport
.taxiPathId
);
6052 case GAMEOBJECT_TYPE_SUMMONING_RITUAL
: //18
6054 /* disable check for while, too many not existed spells
6055 // always must have spell
6056 CheckGOSpellId(goInfo,goInfo->summoningRitual.spellId,1);
6060 case GAMEOBJECT_TYPE_SPELLCASTER
: //22
6062 // always must have spell
6063 CheckGOSpellId(goInfo
,goInfo
->spellcaster
.spellId
,0);
6066 case GAMEOBJECT_TYPE_FLAGSTAND
: //24
6068 if (goInfo
->flagstand
.lockId
)
6069 CheckGOLockId(goInfo
,goInfo
->flagstand
.lockId
,0);
6070 CheckGONoDamageImmuneId(goInfo
,goInfo
->flagstand
.noDamageImmune
,5);
6073 case GAMEOBJECT_TYPE_FISHINGHOLE
: //25
6075 if (goInfo
->fishinghole
.lockId
)
6076 CheckGOLockId(goInfo
,goInfo
->fishinghole
.lockId
,4);
6079 case GAMEOBJECT_TYPE_FLAGDROP
: //26
6081 if (goInfo
->flagdrop
.lockId
)
6082 CheckGOLockId(goInfo
,goInfo
->flagdrop
.lockId
,0);
6083 CheckGONoDamageImmuneId(goInfo
,goInfo
->flagdrop
.noDamageImmune
,3);
6086 case GAMEOBJECT_TYPE_BARBER_CHAIR
: //32
6087 CheckAndFixGOChairHeightId(goInfo
,goInfo
->barberChair
.chairheight
,0);
6092 sLog
.outString( ">> Loaded %u game object templates", sGOStorage
.RecordCount
);
6096 void ObjectMgr::LoadExplorationBaseXP()
6099 QueryResult
*result
= WorldDatabase
.Query("SELECT level,basexp FROM exploration_basexp");
6108 sLog
.outString( ">> Loaded %u BaseXP definitions", count
);
6112 barGoLink
bar( result
->GetRowCount() );
6118 Field
*fields
= result
->Fetch();
6119 uint32 level
= fields
[0].GetUInt32();
6120 uint32 basexp
= fields
[1].GetUInt32();
6121 mBaseXPTable
[level
] = basexp
;
6124 while (result
->NextRow());
6129 sLog
.outString( ">> Loaded %u BaseXP definitions", count
);
6132 uint32
ObjectMgr::GetBaseXP(uint32 level
)
6134 return mBaseXPTable
[level
] ? mBaseXPTable
[level
] : 0;
6137 uint32
ObjectMgr::GetXPForLevel(uint32 level
)
6139 if (level
< mPlayerXPperLevel
.size())
6140 return mPlayerXPperLevel
[level
];
6144 void ObjectMgr::LoadPetNames()
6147 QueryResult
*result
= WorldDatabase
.Query("SELECT word,entry,half FROM pet_name_generation");
6156 sLog
.outString( ">> Loaded %u pet name parts", count
);
6160 barGoLink
bar( result
->GetRowCount() );
6166 Field
*fields
= result
->Fetch();
6167 std::string word
= fields
[0].GetString();
6168 uint32 entry
= fields
[1].GetUInt32();
6169 bool half
= fields
[2].GetBool();
6171 PetHalfName1
[entry
].push_back(word
);
6173 PetHalfName0
[entry
].push_back(word
);
6176 while (result
->NextRow());
6180 sLog
.outString( ">> Loaded %u pet name parts", count
);
6183 void ObjectMgr::LoadPetNumber()
6185 QueryResult
* result
= CharacterDatabase
.Query("SELECT MAX(id) FROM character_pet");
6188 Field
*fields
= result
->Fetch();
6189 m_hiPetNumber
= fields
[0].GetUInt32()+1;
6197 sLog
.outString( ">> Loaded the max pet number: %d", m_hiPetNumber
-1);
6200 std::string
ObjectMgr::GeneratePetName(uint32 entry
)
6202 std::vector
<std::string
> & list0
= PetHalfName0
[entry
];
6203 std::vector
<std::string
> & list1
= PetHalfName1
[entry
];
6205 if(list0
.empty() || list1
.empty())
6207 CreatureInfo
const *cinfo
= GetCreatureTemplate(entry
);
6208 char* petname
= GetPetName(cinfo
->family
, sWorld
.GetDefaultDbcLocale());
6210 petname
= cinfo
->Name
;
6211 return std::string(petname
);
6214 return *(list0
.begin()+urand(0, list0
.size()-1)) + *(list1
.begin()+urand(0, list1
.size()-1));
6217 uint32
ObjectMgr::GeneratePetNumber()
6219 return ++m_hiPetNumber
;
6222 void ObjectMgr::LoadCorpses()
6225 // 0 1 2 3 4 5 6 7 8 10
6226 QueryResult
*result
= CharacterDatabase
.Query("SELECT position_x, position_y, position_z, orientation, map, data, time, corpse_type, instance, guid FROM corpse WHERE corpse_type <> 0");
6235 sLog
.outString( ">> Loaded %u corpses", count
);
6239 barGoLink
bar( result
->GetRowCount() );
6245 Field
*fields
= result
->Fetch();
6247 uint32 guid
= fields
[result
->GetFieldCount()-1].GetUInt32();
6249 Corpse
*corpse
= new Corpse
;
6250 if(!corpse
->LoadFromDB(guid
,fields
))
6256 sObjectAccessor
.AddCorpse(corpse
);
6260 while (result
->NextRow());
6264 sLog
.outString( ">> Loaded %u corpses", count
);
6267 void ObjectMgr::LoadReputationOnKill()
6272 QueryResult
*result
= WorldDatabase
.Query("SELECT creature_id, RewOnKillRepFaction1, RewOnKillRepFaction2,"
6274 "IsTeamAward1, MaxStanding1, RewOnKillRepValue1, IsTeamAward2, MaxStanding2, RewOnKillRepValue2, TeamDependent "
6275 "FROM creature_onkill_reputation");
6284 sLog
.outErrorDb(">> Loaded 0 creature award reputation definitions. DB table `creature_onkill_reputation` is empty.");
6288 barGoLink
bar(result
->GetRowCount());
6292 Field
*fields
= result
->Fetch();
6295 uint32 creature_id
= fields
[0].GetUInt32();
6297 ReputationOnKillEntry repOnKill
;
6298 repOnKill
.repfaction1
= fields
[1].GetUInt32();
6299 repOnKill
.repfaction2
= fields
[2].GetUInt32();
6300 repOnKill
.is_teamaward1
= fields
[3].GetBool();
6301 repOnKill
.reputation_max_cap1
= fields
[4].GetUInt32();
6302 repOnKill
.repvalue1
= fields
[5].GetInt32();
6303 repOnKill
.is_teamaward2
= fields
[6].GetBool();
6304 repOnKill
.reputation_max_cap2
= fields
[7].GetUInt32();
6305 repOnKill
.repvalue2
= fields
[8].GetInt32();
6306 repOnKill
.team_dependent
= fields
[9].GetUInt8();
6308 if(!GetCreatureTemplate(creature_id
))
6310 sLog
.outErrorDb("Table `creature_onkill_reputation` have data for not existed creature entry (%u), skipped",creature_id
);
6314 if(repOnKill
.repfaction1
)
6316 FactionEntry
const *factionEntry1
= sFactionStore
.LookupEntry(repOnKill
.repfaction1
);
6319 sLog
.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `creature_onkill_reputation`",repOnKill
.repfaction1
);
6324 if(repOnKill
.repfaction2
)
6326 FactionEntry
const *factionEntry2
= sFactionStore
.LookupEntry(repOnKill
.repfaction2
);
6329 sLog
.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `creature_onkill_reputation`",repOnKill
.repfaction2
);
6334 mRepOnKill
[creature_id
] = repOnKill
;
6337 } while (result
->NextRow());
6342 sLog
.outString(">> Loaded %u creature award reputation definitions", count
);
6345 void ObjectMgr::LoadPointsOfInterest()
6350 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, x, y, icon, flags, data, icon_name FROM points_of_interest");
6359 sLog
.outErrorDb(">> Loaded 0 Points of Interest definitions. DB table `points_of_interest` is empty.");
6363 barGoLink
bar(result
->GetRowCount());
6367 Field
*fields
= result
->Fetch();
6370 uint32 point_id
= fields
[0].GetUInt32();
6372 PointOfInterest POI
;
6373 POI
.x
= fields
[1].GetFloat();
6374 POI
.y
= fields
[2].GetFloat();
6375 POI
.icon
= fields
[3].GetUInt32();
6376 POI
.flags
= fields
[4].GetUInt32();
6377 POI
.data
= fields
[5].GetUInt32();
6378 POI
.icon_name
= fields
[6].GetCppString();
6380 if(!MaNGOS::IsValidMapCoord(POI
.x
,POI
.y
))
6382 sLog
.outErrorDb("Table `points_of_interest` (Entry: %u) have invalid coordinates (X: %f Y: %f), ignored.",point_id
,POI
.x
,POI
.y
);
6386 mPointsOfInterest
[point_id
] = POI
;
6389 } while (result
->NextRow());
6394 sLog
.outString(">> Loaded %u Points of Interest definitions", count
);
6397 void ObjectMgr::LoadQuestPOI()
6402 QueryResult
*result
= WorldDatabase
.Query("SELECT questId, objIndex, mapId, unk1, unk2, unk3, unk4 FROM quest_poi");
6411 sLog
.outErrorDb(">> Loaded 0 quest POI definitions. DB table `quest_poi` is empty.");
6415 barGoLink
bar(result
->GetRowCount());
6419 Field
*fields
= result
->Fetch();
6422 uint32 questId
= fields
[0].GetUInt32();
6423 int32 objIndex
= fields
[1].GetInt32();
6424 uint32 mapId
= fields
[2].GetUInt32();
6425 uint32 unk1
= fields
[3].GetUInt32();
6426 uint32 unk2
= fields
[4].GetUInt32();
6427 uint32 unk3
= fields
[5].GetUInt32();
6428 uint32 unk4
= fields
[6].GetUInt32();
6430 QuestPOI
POI(objIndex
, mapId
, unk1
, unk2
, unk3
, unk4
);
6432 QueryResult
*points
= WorldDatabase
.PQuery("SELECT x, y FROM quest_poi_points WHERE questId='%u' AND objIndex='%i'", questId
, objIndex
);
6438 Field
*pointFields
= points
->Fetch();
6439 int32 x
= pointFields
[0].GetInt32();
6440 int32 y
= pointFields
[1].GetInt32();
6441 QuestPOIPoint
point(x
, y
);
6442 POI
.points
.push_back(point
);
6443 } while (points
->NextRow());
6448 mQuestPOIMap
[questId
].push_back(POI
);
6451 } while (result
->NextRow());
6456 sLog
.outString(">> Loaded %u quest POI definitions", count
);
6459 void ObjectMgr::LoadNPCSpellClickSpells()
6463 mSpellClickInfoMap
.clear();
6465 QueryResult
*result
= WorldDatabase
.Query("SELECT npc_entry, spell_id, quest_start, quest_start_active, quest_end, cast_flags FROM npc_spellclick_spells");
6474 sLog
.outErrorDb(">> Loaded 0 spellclick spells. DB table `npc_spellclick_spells` is empty.");
6478 barGoLink
bar(result
->GetRowCount());
6482 Field
*fields
= result
->Fetch();
6485 uint32 npc_entry
= fields
[0].GetUInt32();
6486 CreatureInfo
const* cInfo
= GetCreatureTemplate(npc_entry
);
6489 sLog
.outErrorDb("Table npc_spellclick_spells references unknown creature_template %u. Skipping entry.", npc_entry
);
6493 uint32 spellid
= fields
[1].GetUInt32();
6494 SpellEntry
const *spellinfo
= sSpellStore
.LookupEntry(spellid
);
6497 sLog
.outErrorDb("Table npc_spellclick_spells references unknown spellid %u. Skipping entry.", spellid
);
6501 uint32 quest_start
= fields
[2].GetUInt32();
6503 // quest might be 0 to enable spellclick independent of any quest
6506 if(mQuestTemplates
.find(quest_start
) == mQuestTemplates
.end())
6508 sLog
.outErrorDb("Table npc_spellclick_spells references unknown start quest %u. Skipping entry.", quest_start
);
6514 bool quest_start_active
= fields
[3].GetBool();
6516 uint32 quest_end
= fields
[4].GetUInt32();
6517 // quest might be 0 to enable spellclick active infinity after start quest
6520 if(mQuestTemplates
.find(quest_end
) == mQuestTemplates
.end())
6522 sLog
.outErrorDb("Table npc_spellclick_spells references unknown end quest %u. Skipping entry.", quest_end
);
6528 uint8 castFlags
= fields
[5].GetUInt8();
6529 SpellClickInfo info
;
6530 info
.spellId
= spellid
;
6531 info
.questStart
= quest_start
;
6532 info
.questStartCanActive
= quest_start_active
;
6533 info
.questEnd
= quest_end
;
6534 info
.castFlags
= castFlags
;
6535 mSpellClickInfoMap
.insert(SpellClickInfoMap::value_type(npc_entry
, info
));
6537 // mark creature template as spell clickable
6538 const_cast<CreatureInfo
*>(cInfo
)->npcflag
|= UNIT_NPC_FLAG_SPELLCLICK
;
6541 } while (result
->NextRow());
6546 sLog
.outString(">> Loaded %u spellclick definitions", count
);
6549 void ObjectMgr::LoadWeatherZoneChances()
6553 // 0 1 2 3 4 5 6 7 8 9 10 11 12
6554 QueryResult
*result
= WorldDatabase
.Query("SELECT zone, spring_rain_chance, spring_snow_chance, spring_storm_chance, summer_rain_chance, summer_snow_chance, summer_storm_chance, fall_rain_chance, fall_snow_chance, fall_storm_chance, winter_rain_chance, winter_snow_chance, winter_storm_chance FROM game_weather");
6563 sLog
.outErrorDb(">> Loaded 0 weather definitions. DB table `game_weather` is empty.");
6567 barGoLink
bar(result
->GetRowCount());
6571 Field
*fields
= result
->Fetch();
6574 uint32 zone_id
= fields
[0].GetUInt32();
6576 WeatherZoneChances
& wzc
= mWeatherZoneMap
[zone_id
];
6578 for(int season
= 0; season
< WEATHER_SEASONS
; ++season
)
6580 wzc
.data
[season
].rainChance
= fields
[season
* (MAX_WEATHER_TYPE
-1) + 1].GetUInt32();
6581 wzc
.data
[season
].snowChance
= fields
[season
* (MAX_WEATHER_TYPE
-1) + 2].GetUInt32();
6582 wzc
.data
[season
].stormChance
= fields
[season
* (MAX_WEATHER_TYPE
-1) + 3].GetUInt32();
6584 if(wzc
.data
[season
].rainChance
> 100)
6586 wzc
.data
[season
].rainChance
= 25;
6587 sLog
.outErrorDb("Weather for zone %u season %u has wrong rain chance > 100%%",zone_id
,season
);
6590 if(wzc
.data
[season
].snowChance
> 100)
6592 wzc
.data
[season
].snowChance
= 25;
6593 sLog
.outErrorDb("Weather for zone %u season %u has wrong snow chance > 100%%",zone_id
,season
);
6596 if(wzc
.data
[season
].stormChance
> 100)
6598 wzc
.data
[season
].stormChance
= 25;
6599 sLog
.outErrorDb("Weather for zone %u season %u has wrong storm chance > 100%%",zone_id
,season
);
6604 } while (result
->NextRow());
6609 sLog
.outString(">> Loaded %u weather definitions", count
);
6612 void ObjectMgr::SaveCreatureRespawnTime(uint32 loguid
, uint32 instance
, time_t t
)
6614 mCreatureRespawnTimes
[MAKE_PAIR64(loguid
,instance
)] = t
;
6615 WorldDatabase
.PExecute("DELETE FROM creature_respawn WHERE guid = '%u' AND instance = '%u'", loguid
, instance
);
6617 WorldDatabase
.PExecute("INSERT INTO creature_respawn VALUES ( '%u', '" UI64FMTD
"', '%u' )", loguid
, uint64(t
), instance
);
6620 void ObjectMgr::DeleteCreatureData(uint32 guid
)
6622 // remove mapid*cellid -> guid_set map
6623 CreatureData
const* data
= GetCreatureData(guid
);
6625 RemoveCreatureFromGrid(guid
, data
);
6627 mCreatureDataMap
.erase(guid
);
6630 void ObjectMgr::SaveGORespawnTime(uint32 loguid
, uint32 instance
, time_t t
)
6632 mGORespawnTimes
[MAKE_PAIR64(loguid
,instance
)] = t
;
6633 WorldDatabase
.PExecute("DELETE FROM gameobject_respawn WHERE guid = '%u' AND instance = '%u'", loguid
, instance
);
6635 WorldDatabase
.PExecute("INSERT INTO gameobject_respawn VALUES ( '%u', '" UI64FMTD
"', '%u' )", loguid
, uint64(t
), instance
);
6638 void ObjectMgr::DeleteRespawnTimeForInstance(uint32 instance
)
6640 RespawnTimes::iterator next
;
6642 for(RespawnTimes::iterator itr
= mGORespawnTimes
.begin(); itr
!= mGORespawnTimes
.end(); itr
= next
)
6647 if(GUID_HIPART(itr
->first
)==instance
)
6648 mGORespawnTimes
.erase(itr
);
6651 for(RespawnTimes::iterator itr
= mCreatureRespawnTimes
.begin(); itr
!= mCreatureRespawnTimes
.end(); itr
= next
)
6656 if(GUID_HIPART(itr
->first
)==instance
)
6657 mCreatureRespawnTimes
.erase(itr
);
6660 WorldDatabase
.PExecute("DELETE FROM creature_respawn WHERE instance = '%u'", instance
);
6661 WorldDatabase
.PExecute("DELETE FROM gameobject_respawn WHERE instance = '%u'", instance
);
6664 void ObjectMgr::DeleteGOData(uint32 guid
)
6666 // remove mapid*cellid -> guid_set map
6667 GameObjectData
const* data
= GetGOData(guid
);
6669 RemoveGameobjectFromGrid(guid
, data
);
6671 mGameObjectDataMap
.erase(guid
);
6674 void ObjectMgr::AddCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
, uint32 instance
)
6676 // corpses are always added to spawn mode 0 and they are spawned by their instance id
6677 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(mapid
,0)][cellid
];
6678 cell_guids
.corpses
[player_guid
] = instance
;
6681 void ObjectMgr::DeleteCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
)
6683 // corpses are always added to spawn mode 0 and they are spawned by their instance id
6684 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(mapid
,0)][cellid
];
6685 cell_guids
.corpses
.erase(player_guid
);
6688 void ObjectMgr::LoadQuestRelationsHelper(QuestRelations
& map
,char const* table
)
6690 map
.clear(); // need for reload case
6694 QueryResult
*result
= WorldDatabase
.PQuery("SELECT id,quest FROM %s",table
);
6703 sLog
.outErrorDb(">> Loaded 0 quest relations from %s. DB table `%s` is empty.",table
,table
);
6707 barGoLink
bar(result
->GetRowCount());
6711 Field
*fields
= result
->Fetch();
6714 uint32 id
= fields
[0].GetUInt32();
6715 uint32 quest
= fields
[1].GetUInt32();
6717 if(mQuestTemplates
.find(quest
) == mQuestTemplates
.end())
6719 sLog
.outErrorDb("Table `%s: Quest %u listed for entry %u does not exist.",table
,quest
,id
);
6723 map
.insert(QuestRelations::value_type(id
,quest
));
6726 } while (result
->NextRow());
6731 sLog
.outString(">> Loaded %u quest relations from %s", count
,table
);
6734 void ObjectMgr::LoadGameobjectQuestRelations()
6736 LoadQuestRelationsHelper(mGOQuestRelations
,"gameobject_questrelation");
6738 for(QuestRelations::iterator itr
= mGOQuestRelations
.begin(); itr
!= mGOQuestRelations
.end(); ++itr
)
6740 GameObjectInfo
const* goInfo
= GetGameObjectInfo(itr
->first
);
6742 sLog
.outErrorDb("Table `gameobject_questrelation` have data for not existed gameobject entry (%u) and existed quest %u",itr
->first
,itr
->second
);
6743 else if(goInfo
->type
!= GAMEOBJECT_TYPE_QUESTGIVER
)
6744 sLog
.outErrorDb("Table `gameobject_questrelation` have data gameobject entry (%u) for quest %u, but GO is not GAMEOBJECT_TYPE_QUESTGIVER",itr
->first
,itr
->second
);
6748 void ObjectMgr::LoadGameobjectInvolvedRelations()
6750 LoadQuestRelationsHelper(mGOQuestInvolvedRelations
,"gameobject_involvedrelation");
6752 for(QuestRelations::iterator itr
= mGOQuestInvolvedRelations
.begin(); itr
!= mGOQuestInvolvedRelations
.end(); ++itr
)
6754 GameObjectInfo
const* goInfo
= GetGameObjectInfo(itr
->first
);
6756 sLog
.outErrorDb("Table `gameobject_involvedrelation` have data for not existed gameobject entry (%u) and existed quest %u",itr
->first
,itr
->second
);
6757 else if(goInfo
->type
!= GAMEOBJECT_TYPE_QUESTGIVER
)
6758 sLog
.outErrorDb("Table `gameobject_involvedrelation` have data gameobject entry (%u) for quest %u, but GO is not GAMEOBJECT_TYPE_QUESTGIVER",itr
->first
,itr
->second
);
6762 void ObjectMgr::LoadCreatureQuestRelations()
6764 LoadQuestRelationsHelper(mCreatureQuestRelations
,"creature_questrelation");
6766 for(QuestRelations::iterator itr
= mCreatureQuestRelations
.begin(); itr
!= mCreatureQuestRelations
.end(); ++itr
)
6768 CreatureInfo
const* cInfo
= GetCreatureTemplate(itr
->first
);
6770 sLog
.outErrorDb("Table `creature_questrelation` have data for not existed creature entry (%u) and existed quest %u",itr
->first
,itr
->second
);
6771 else if(!(cInfo
->npcflag
& UNIT_NPC_FLAG_QUESTGIVER
))
6772 sLog
.outErrorDb("Table `creature_questrelation` has creature entry (%u) for quest %u, but npcflag does not include UNIT_NPC_FLAG_QUESTGIVER",itr
->first
,itr
->second
);
6776 void ObjectMgr::LoadCreatureInvolvedRelations()
6778 LoadQuestRelationsHelper(mCreatureQuestInvolvedRelations
,"creature_involvedrelation");
6780 for(QuestRelations::iterator itr
= mCreatureQuestInvolvedRelations
.begin(); itr
!= mCreatureQuestInvolvedRelations
.end(); ++itr
)
6782 CreatureInfo
const* cInfo
= GetCreatureTemplate(itr
->first
);
6784 sLog
.outErrorDb("Table `creature_involvedrelation` have data for not existed creature entry (%u) and existed quest %u",itr
->first
,itr
->second
);
6785 else if(!(cInfo
->npcflag
& UNIT_NPC_FLAG_QUESTGIVER
))
6786 sLog
.outErrorDb("Table `creature_involvedrelation` has creature entry (%u) for quest %u, but npcflag does not include UNIT_NPC_FLAG_QUESTGIVER",itr
->first
,itr
->second
);
6790 void ObjectMgr::LoadReservedPlayersNames()
6792 m_ReservedNames
.clear(); // need for reload case
6794 QueryResult
*result
= WorldDatabase
.Query("SELECT name FROM reserved_name");
6804 sLog
.outString( ">> Loaded %u reserved player names", count
);
6808 barGoLink
bar( result
->GetRowCount() );
6814 fields
= result
->Fetch();
6815 std::string name
= fields
[0].GetCppString();
6818 if(!Utf8toWStr (name
,wstr
))
6820 sLog
.outError("Table `reserved_name` have invalid name: %s", name
.c_str() );
6826 m_ReservedNames
.insert(wstr
);
6828 } while ( result
->NextRow() );
6833 sLog
.outString( ">> Loaded %u reserved player names", count
);
6836 bool ObjectMgr::IsReservedName( const std::string
& name
) const
6839 if(!Utf8toWStr (name
,wstr
))
6844 return m_ReservedNames
.find(wstr
) != m_ReservedNames
.end();
6849 LT_BASIC_LATIN
= 0x0000,
6850 LT_EXTENDEN_LATIN
= 0x0001,
6851 LT_CYRILLIC
= 0x0002,
6852 LT_EAST_ASIA
= 0x0004,
6856 static LanguageType
GetRealmLanguageType(bool create
)
6858 switch(sWorld
.getConfig(CONFIG_REALM_ZONE
))
6860 case REALM_ZONE_UNKNOWN
: // any language
6861 case REALM_ZONE_DEVELOPMENT
:
6862 case REALM_ZONE_TEST_SERVER
:
6863 case REALM_ZONE_QA_SERVER
:
6865 case REALM_ZONE_UNITED_STATES
: // extended-Latin
6866 case REALM_ZONE_OCEANIC
:
6867 case REALM_ZONE_LATIN_AMERICA
:
6868 case REALM_ZONE_ENGLISH
:
6869 case REALM_ZONE_GERMAN
:
6870 case REALM_ZONE_FRENCH
:
6871 case REALM_ZONE_SPANISH
:
6872 return LT_EXTENDEN_LATIN
;
6873 case REALM_ZONE_KOREA
: // East-Asian
6874 case REALM_ZONE_TAIWAN
:
6875 case REALM_ZONE_CHINA
:
6876 return LT_EAST_ASIA
;
6877 case REALM_ZONE_RUSSIAN
: // Cyrillic
6880 return create
? LT_BASIC_LATIN
: LT_ANY
; // basic-Latin at create, any at login
6884 bool isValidString(std::wstring wstr
, uint32 strictMask
, bool numericOrSpace
, bool create
= false)
6886 if(strictMask
==0) // any language, ignore realm
6888 if(isExtendedLatinString(wstr
,numericOrSpace
))
6890 if(isCyrillicString(wstr
,numericOrSpace
))
6892 if(isEastAsianString(wstr
,numericOrSpace
))
6897 if(strictMask
& 0x2) // realm zone specific
6899 LanguageType lt
= GetRealmLanguageType(create
);
6900 if(lt
& LT_EXTENDEN_LATIN
)
6901 if(isExtendedLatinString(wstr
,numericOrSpace
))
6903 if(lt
& LT_CYRILLIC
)
6904 if(isCyrillicString(wstr
,numericOrSpace
))
6906 if(lt
& LT_EAST_ASIA
)
6907 if(isEastAsianString(wstr
,numericOrSpace
))
6911 if(strictMask
& 0x1) // basic Latin
6913 if(isBasicLatinString(wstr
,numericOrSpace
))
6920 uint8
ObjectMgr::CheckPlayerName( const std::string
& name
, bool create
)
6923 if(!Utf8toWStr(name
,wname
))
6924 return CHAR_NAME_INVALID_CHARACTER
;
6926 if(wname
.size() > MAX_PLAYER_NAME
)
6927 return CHAR_NAME_TOO_LONG
;
6929 uint32 minName
= sWorld
.getConfig(CONFIG_MIN_PLAYER_NAME
);
6930 if(wname
.size() < minName
)
6931 return CHAR_NAME_TOO_SHORT
;
6933 uint32 strictMask
= sWorld
.getConfig(CONFIG_STRICT_PLAYER_NAMES
);
6934 if(!isValidString(wname
,strictMask
,false,create
))
6935 return CHAR_NAME_MIXED_LANGUAGES
;
6937 return CHAR_NAME_SUCCESS
;
6940 bool ObjectMgr::IsValidCharterName( const std::string
& name
)
6943 if(!Utf8toWStr(name
,wname
))
6946 if(wname
.size() > MAX_CHARTER_NAME
)
6949 uint32 minName
= sWorld
.getConfig(CONFIG_MIN_CHARTER_NAME
);
6950 if(wname
.size() < minName
)
6953 uint32 strictMask
= sWorld
.getConfig(CONFIG_STRICT_CHARTER_NAMES
);
6955 return isValidString(wname
,strictMask
,true);
6958 PetNameInvalidReason
ObjectMgr::CheckPetName( const std::string
& name
)
6961 if(!Utf8toWStr(name
,wname
))
6962 return PET_NAME_INVALID
;
6964 if(wname
.size() > MAX_PET_NAME
)
6965 return PET_NAME_TOO_LONG
;
6967 uint32 minName
= sWorld
.getConfig(CONFIG_MIN_PET_NAME
);
6968 if(wname
.size() < minName
)
6969 return PET_NAME_TOO_SHORT
;
6971 uint32 strictMask
= sWorld
.getConfig(CONFIG_STRICT_PET_NAMES
);
6972 if(!isValidString(wname
,strictMask
,false))
6973 return PET_NAME_MIXED_LANGUAGES
;
6975 return PET_NAME_SUCCESS
;
6978 int ObjectMgr::GetIndexForLocale( LocaleConstant loc
)
6980 if(loc
==LOCALE_enUS
)
6983 for(size_t i
=0;i
< m_LocalForIndex
.size(); ++i
)
6984 if(m_LocalForIndex
[i
]==loc
)
6990 LocaleConstant
ObjectMgr::GetLocaleForIndex(int i
)
6992 if (i
<0 || i
>=m_LocalForIndex
.size())
6995 return m_LocalForIndex
[i
];
6998 int ObjectMgr::GetOrNewIndexForLocale( LocaleConstant loc
)
7000 if(loc
==LOCALE_enUS
)
7003 for(size_t i
=0;i
< m_LocalForIndex
.size(); ++i
)
7004 if(m_LocalForIndex
[i
]==loc
)
7007 m_LocalForIndex
.push_back(loc
);
7008 return m_LocalForIndex
.size()-1;
7011 void ObjectMgr::LoadGameObjectForQuests()
7013 mGameObjectForQuestSet
.clear(); // need for reload case
7015 if( !sGOStorage
.MaxEntry
)
7020 sLog
.outString( ">> Loaded 0 GameObjects for quests" );
7024 barGoLink
bar( sGOStorage
.MaxEntry
- 1 );
7027 // collect GO entries for GO that must activated
7028 for(uint32 go_entry
= 1; go_entry
< sGOStorage
.MaxEntry
; ++go_entry
)
7031 GameObjectInfo
const* goInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(go_entry
);
7035 switch(goInfo
->type
)
7037 // scan GO chest with loot including quest items
7038 case GAMEOBJECT_TYPE_CHEST
:
7040 uint32 loot_id
= goInfo
->GetLootId();
7042 // find quest loot for GO
7043 if(LootTemplates_Gameobject
.HaveQuestLootFor(loot_id
))
7045 mGameObjectForQuestSet
.insert(go_entry
);
7050 case GAMEOBJECT_TYPE_GOOBER
:
7052 if(goInfo
->goober
.questId
) //quests objects
7054 mGameObjectForQuestSet
.insert(go_entry
);
7065 sLog
.outString( ">> Loaded %u GameObjects for quests", count
);
7068 bool ObjectMgr::LoadMangosStrings(DatabaseType
& db
, char const* table
, int32 min_value
, int32 max_value
)
7070 int32 start_value
= min_value
;
7071 int32 end_value
= max_value
;
7072 // some string can have negative indexes range
7073 if (start_value
< 0)
7075 if (end_value
>= start_value
)
7077 sLog
.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.",table
,min_value
,max_value
);
7081 // real range (max+1,min+1) exaple: (-10,-1000) -> -999...-10+1
7082 std::swap(start_value
,end_value
);
7088 if (start_value
>= end_value
)
7090 sLog
.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.",table
,min_value
,max_value
);
7095 // cleanup affected map part for reloading case
7096 for(MangosStringLocaleMap::iterator itr
= mMangosStringLocaleMap
.begin(); itr
!= mMangosStringLocaleMap
.end();)
7098 if (itr
->first
>= start_value
&& itr
->first
< end_value
)
7099 mMangosStringLocaleMap
.erase(itr
++);
7104 QueryResult
*result
= db
.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 FROM %s",table
);
7113 if (min_value
== MIN_MANGOS_STRING_ID
) // error only in case internal strings
7114 sLog
.outErrorDb(">> Loaded 0 mangos strings. DB table `%s` is empty. Cannot continue.",table
);
7116 sLog
.outString(">> Loaded 0 string templates. DB table `%s` is empty.",table
);
7122 barGoLink
bar(result
->GetRowCount());
7126 Field
*fields
= result
->Fetch();
7129 int32 entry
= fields
[0].GetInt32();
7133 sLog
.outErrorDb("Table `%s` contain reserved entry 0, ignored.",table
);
7136 else if (entry
< start_value
|| entry
>= end_value
)
7138 sLog
.outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table
,entry
,min_value
,max_value
);
7142 MangosStringLocale
& data
= mMangosStringLocaleMap
[entry
];
7144 if (data
.Content
.size() > 0)
7146 sLog
.outErrorDb("Table `%s` contain data for already loaded entry %i (from another table?), ignored.",table
,entry
);
7150 data
.Content
.resize(1);
7153 // 0 -> default, idx in to idx+1
7154 data
.Content
[0] = fields
[1].GetCppString();
7156 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
7158 std::string str
= fields
[i
+1].GetCppString();
7161 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
7164 // 0 -> default, idx in to idx+1
7165 if (data
.Content
.size() <= idx
+1)
7166 data
.Content
.resize(idx
+2);
7168 data
.Content
[idx
+1] = str
;
7172 } while (result
->NextRow());
7177 if (min_value
== MIN_MANGOS_STRING_ID
)
7178 sLog
.outString( ">> Loaded %u MaNGOS strings from table %s", count
,table
);
7180 sLog
.outString( ">> Loaded %u string templates from %s", count
,table
);
7185 const char *ObjectMgr::GetMangosString(int32 entry
, int locale_idx
) const
7187 // locale_idx==-1 -> default, locale_idx >= 0 in to idx+1
7188 // Content[0] always exist if exist MangosStringLocale
7189 if(MangosStringLocale
const *msl
= GetMangosStringLocale(entry
))
7191 if(msl
->Content
.size() > locale_idx
+1 && !msl
->Content
[locale_idx
+1].empty())
7192 return msl
->Content
[locale_idx
+1].c_str();
7194 return msl
->Content
[0].c_str();
7198 sLog
.outErrorDb("Entry %i not found in `mangos_string` table.",entry
);
7200 sLog
.outErrorDb("Mangos string entry %i not found in DB.",entry
);
7204 void ObjectMgr::LoadFishingBaseSkillLevel()
7206 mFishingBaseForArea
.clear(); // for reload case
7209 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,skill FROM skill_fishing_base_level");
7218 sLog
.outErrorDb(">> Loaded `skill_fishing_base_level`, table is empty!");
7222 barGoLink
bar( result
->GetRowCount() );
7228 Field
*fields
= result
->Fetch();
7229 uint32 entry
= fields
[0].GetUInt32();
7230 int32 skill
= fields
[1].GetInt32();
7232 AreaTableEntry
const* fArea
= GetAreaEntryByAreaID(entry
);
7235 sLog
.outErrorDb("AreaId %u defined in `skill_fishing_base_level` does not exist",entry
);
7239 mFishingBaseForArea
[entry
] = skill
;
7242 while (result
->NextRow());
7247 sLog
.outString( ">> Loaded %u areas for fishing base skill level", count
);
7250 // Searches for the same condition already in Conditions store
7251 // Returns Id if found, else adds it to Conditions and returns Id
7252 uint16
ObjectMgr::GetConditionId( ConditionType condition
, uint32 value1
, uint32 value2
)
7254 PlayerCondition lc
= PlayerCondition(condition
, value1
, value2
);
7255 for (uint16 i
=0; i
< mConditions
.size(); ++i
)
7257 if (lc
== mConditions
[i
])
7261 mConditions
.push_back(lc
);
7263 if(mConditions
.size() > 0xFFFF)
7265 sLog
.outError("Conditions store overflow! Current and later loaded conditions will ignored!");
7269 return mConditions
.size() - 1;
7272 bool ObjectMgr::CheckDeclinedNames( std::wstring mainpart
, DeclinedName
const& names
)
7274 for(int i
=0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
7277 if(!Utf8toWStr(names
.name
[i
],wname
))
7280 if(mainpart
!=GetMainPartOfName(wname
,i
+1))
7286 uint32
ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id
)
7288 AreaTriggerScriptMap::const_iterator i
= mAreaTriggerScripts
.find(trigger_id
);
7289 if(i
!= mAreaTriggerScripts
.end())
7294 // Checks if player meets the condition
7295 bool PlayerCondition::Meets(Player
const * player
) const
7298 return false; // player not present, return false
7302 case CONDITION_NONE
:
7303 return true; // empty condition, always met
7304 case CONDITION_AURA
:
7305 return player
->HasAura(value1
, value2
);
7306 case CONDITION_ITEM
:
7307 return player
->HasItemCount(value1
, value2
);
7308 case CONDITION_ITEM_EQUIPPED
:
7309 return player
->HasItemOrGemWithIdEquipped(value1
,1);
7310 case CONDITION_ZONEID
:
7311 return player
->GetZoneId() == value1
;
7312 case CONDITION_REPUTATION_RANK
:
7314 FactionEntry
const* faction
= sFactionStore
.LookupEntry(value1
);
7315 return faction
&& player
->GetReputationMgr().GetRank(faction
) >= int32(value2
);
7317 case CONDITION_TEAM
:
7318 return player
->GetTeam() == value1
;
7319 case CONDITION_SKILL
:
7320 return player
->HasSkill(value1
) && player
->GetBaseSkillValue(value1
) >= value2
;
7321 case CONDITION_QUESTREWARDED
:
7322 return player
->GetQuestRewardStatus(value1
);
7323 case CONDITION_QUESTTAKEN
:
7325 QuestStatus status
= player
->GetQuestStatus(value1
);
7326 return (status
== QUEST_STATUS_INCOMPLETE
);
7328 case CONDITION_AD_COMMISSION_AURA
:
7330 Unit::AuraMap
const& auras
= player
->GetAuras();
7331 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
7332 if((itr
->second
->GetSpellProto()->Attributes
& 0x1000010) && itr
->second
->GetSpellProto()->SpellVisual
[0]==3580)
7336 case CONDITION_NO_AURA
:
7337 return !player
->HasAura(value1
, value2
);
7338 case CONDITION_ACTIVE_EVENT
:
7339 return sGameEventMgr
.IsActiveEvent(value1
);
7340 case CONDITION_AREA_FLAG
:
7342 if (AreaTableEntry
const *pAreaEntry
= GetAreaEntryByAreaID(player
->GetAreaId()))
7344 if ((!value1
|| (pAreaEntry
->flags
& value1
)) && (!value2
|| !(pAreaEntry
->flags
& value2
)))
7349 case CONDITION_RACE_CLASS
:
7350 if ((!value1
|| (player
->getRaceMask() & value1
)) && (!value2
|| (player
->getClassMask() & value2
)))
7353 case CONDITION_LEVEL
:
7357 case 0: return player
->getLevel() == value1
;
7358 case 1: return player
->getLevel() >= value1
;
7359 case 2: return player
->getLevel() <= value1
;
7368 // Verification of condition values validity
7369 bool PlayerCondition::IsValid(ConditionType condition
, uint32 value1
, uint32 value2
)
7371 if( condition
>= MAX_CONDITION
) // Wrong condition type
7373 sLog
.outErrorDb("Condition has bad type of %u, skipped ", condition
);
7379 case CONDITION_AURA
:
7381 if(!sSpellStore
.LookupEntry(value1
))
7383 sLog
.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1
);
7388 sLog
.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2
);
7393 case CONDITION_ITEM
:
7395 ItemPrototype
const *proto
= ObjectMgr::GetItemPrototype(value1
);
7398 sLog
.outErrorDb("Item condition requires to have non existing item (%u), skipped", value1
);
7403 case CONDITION_ITEM_EQUIPPED
:
7405 ItemPrototype
const *proto
= ObjectMgr::GetItemPrototype(value1
);
7408 sLog
.outErrorDb("ItemEquipped condition requires to have non existing item (%u) equipped, skipped", value1
);
7413 case CONDITION_ZONEID
:
7415 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(value1
);
7418 sLog
.outErrorDb("Zone condition requires to be in non existing area (%u), skipped", value1
);
7421 if(areaEntry
->zone
!= 0)
7423 sLog
.outErrorDb("Zone condition requires to be in area (%u) which is a subzone but zone expected, skipped", value1
);
7428 case CONDITION_REPUTATION_RANK
:
7430 FactionEntry
const* factionEntry
= sFactionStore
.LookupEntry(value1
);
7433 sLog
.outErrorDb("Reputation condition requires to have reputation non existing faction (%u), skipped", value1
);
7438 case CONDITION_TEAM
:
7440 if (value1
!= ALLIANCE
&& value1
!= HORDE
)
7442 sLog
.outErrorDb("Team condition specifies unknown team (%u), skipped", value1
);
7447 case CONDITION_SKILL
:
7449 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(value1
);
7452 sLog
.outErrorDb("Skill condition specifies non-existing skill (%u), skipped", value1
);
7455 if (value2
< 1 || value2
> sWorld
.GetConfigMaxSkillValue() )
7457 sLog
.outErrorDb("Skill condition specifies invalid skill value (%u), skipped", value2
);
7462 case CONDITION_QUESTREWARDED
:
7463 case CONDITION_QUESTTAKEN
:
7465 Quest
const *Quest
= sObjectMgr
.GetQuestTemplate(value1
);
7468 sLog
.outErrorDb("Quest condition specifies non-existing quest (%u), skipped", value1
);
7472 sLog
.outErrorDb("Quest condition has useless data in value2 (%u)!", value2
);
7475 case CONDITION_AD_COMMISSION_AURA
:
7478 sLog
.outErrorDb("Quest condition has useless data in value1 (%u)!", value1
);
7480 sLog
.outErrorDb("Quest condition has useless data in value2 (%u)!", value2
);
7483 case CONDITION_NO_AURA
:
7485 if(!sSpellStore
.LookupEntry(value1
))
7487 sLog
.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1
);
7492 sLog
.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2
);
7497 case CONDITION_ACTIVE_EVENT
:
7499 GameEventMgr::GameEventDataMap
const& events
= sGameEventMgr
.GetEventMap();
7500 if(value1
>=events
.size() || !events
[value1
].isValid())
7502 sLog
.outErrorDb("Active event condition requires existed event id (%u), skipped", value1
);
7507 case CONDITION_AREA_FLAG
:
7509 if (!value1
&& !value2
)
7511 sLog
.outErrorDb("Area flag condition has both values like 0, skipped");
7516 case CONDITION_RACE_CLASS
:
7518 if (!value1
&& !value2
)
7520 sLog
.outErrorDb("Race_class condition has both values like 0, skipped");
7524 if (value1
&& !(value1
& RACEMASK_ALL_PLAYABLE
))
7526 sLog
.outErrorDb("Race_class condition has invalid player class %u, skipped", value1
);
7530 if (value2
&& !(value2
& CLASSMASK_ALL_PLAYABLE
))
7532 sLog
.outErrorDb("Race_class condition has invalid race mask %u, skipped", value2
);
7537 case CONDITION_LEVEL
:
7539 if (!value1
|| value1
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
7541 sLog
.outErrorDb("Level condition has invalid level %u, skipped", value1
);
7547 sLog
.outErrorDb("Level condition has invalid argument %u (must be 0..2), skipped", value2
);
7553 case CONDITION_NONE
:
7559 SkillRangeType
GetSkillRangeType(SkillLineEntry
const *pSkill
, bool racial
)
7561 switch(pSkill
->categoryId
)
7563 case SKILL_CATEGORY_LANGUAGES
: return SKILL_RANGE_LANGUAGE
;
7564 case SKILL_CATEGORY_WEAPON
:
7565 if(pSkill
->id
!=SKILL_FIST_WEAPONS
)
7566 return SKILL_RANGE_LEVEL
;
7568 return SKILL_RANGE_MONO
;
7569 case SKILL_CATEGORY_ARMOR
:
7570 case SKILL_CATEGORY_CLASS
:
7571 if(pSkill
->id
!= SKILL_LOCKPICKING
)
7572 return SKILL_RANGE_MONO
;
7574 return SKILL_RANGE_LEVEL
;
7575 case SKILL_CATEGORY_SECONDARY
:
7576 case SKILL_CATEGORY_PROFESSION
:
7577 // not set skills for professions and racial abilities
7578 if(IsProfessionSkill(pSkill
->id
))
7579 return SKILL_RANGE_RANK
;
7581 return SKILL_RANGE_NONE
;
7583 return SKILL_RANGE_MONO
;
7585 case SKILL_CATEGORY_ATTRIBUTES
: //not found in dbc
7586 case SKILL_CATEGORY_GENERIC
: //only GENERIC(DND)
7587 return SKILL_RANGE_NONE
;
7591 void ObjectMgr::LoadGameTele()
7593 m_GameTeleMap
.clear(); // for reload case
7596 QueryResult
*result
= WorldDatabase
.Query("SELECT id, position_x, position_y, position_z, orientation, map, name FROM game_tele");
7605 sLog
.outErrorDb(">> Loaded `game_tele`, table is empty!");
7609 barGoLink
bar( result
->GetRowCount() );
7615 Field
*fields
= result
->Fetch();
7617 uint32 id
= fields
[0].GetUInt32();
7621 gt
.position_x
= fields
[1].GetFloat();
7622 gt
.position_y
= fields
[2].GetFloat();
7623 gt
.position_z
= fields
[3].GetFloat();
7624 gt
.orientation
= fields
[4].GetFloat();
7625 gt
.mapId
= fields
[5].GetUInt32();
7626 gt
.name
= fields
[6].GetCppString();
7628 if(!MapManager::IsValidMapCoord(gt
.mapId
,gt
.position_x
,gt
.position_y
,gt
.position_z
,gt
.orientation
))
7630 sLog
.outErrorDb("Wrong position for id %u (name: %s) in `game_tele` table, ignoring.",id
,gt
.name
.c_str());
7634 if(!Utf8toWStr(gt
.name
,gt
.wnameLow
))
7636 sLog
.outErrorDb("Wrong UTF8 name for id %u in `game_tele` table, ignoring.",id
);
7640 wstrToLower( gt
.wnameLow
);
7642 m_GameTeleMap
[id
] = gt
;
7646 while (result
->NextRow());
7650 sLog
.outString( ">> Loaded %u GameTeleports", count
);
7653 GameTele
const* ObjectMgr::GetGameTele(const std::string
& name
) const
7655 // explicit name case
7657 if(!Utf8toWStr(name
,wname
))
7660 // converting string that we try to find to lower case
7661 wstrToLower( wname
);
7663 // Alternative first GameTele what contains wnameLow as substring in case no GameTele location found
7664 const GameTele
* alt
= NULL
;
7665 for(GameTeleMap::const_iterator itr
= m_GameTeleMap
.begin(); itr
!= m_GameTeleMap
.end(); ++itr
)
7666 if(itr
->second
.wnameLow
== wname
)
7667 return &itr
->second
;
7668 else if (alt
== NULL
&& itr
->second
.wnameLow
.find(wname
) != std::wstring::npos
)
7674 bool ObjectMgr::AddGameTele(GameTele
& tele
)
7678 for(GameTeleMap::const_iterator itr
= m_GameTeleMap
.begin(); itr
!= m_GameTeleMap
.end(); ++itr
)
7679 if(itr
->first
> new_id
)
7680 new_id
= itr
->first
;
7685 if(!Utf8toWStr(tele
.name
,tele
.wnameLow
))
7688 wstrToLower( tele
.wnameLow
);
7690 m_GameTeleMap
[new_id
] = tele
;
7692 return WorldDatabase
.PExecuteLog("INSERT INTO game_tele (id,position_x,position_y,position_z,orientation,map,name) VALUES (%u,%f,%f,%f,%f,%d,'%s')",
7693 new_id
,tele
.position_x
,tele
.position_y
,tele
.position_z
,tele
.orientation
,tele
.mapId
,tele
.name
.c_str());
7696 bool ObjectMgr::DeleteGameTele(const std::string
& name
)
7698 // explicit name case
7700 if(!Utf8toWStr(name
,wname
))
7703 // converting string that we try to find to lower case
7704 wstrToLower( wname
);
7706 for(GameTeleMap::iterator itr
= m_GameTeleMap
.begin(); itr
!= m_GameTeleMap
.end(); ++itr
)
7708 if(itr
->second
.wnameLow
== wname
)
7710 WorldDatabase
.PExecuteLog("DELETE FROM game_tele WHERE name = '%s'",itr
->second
.name
.c_str());
7711 m_GameTeleMap
.erase(itr
);
7719 void ObjectMgr::LoadMailLevelRewards()
7721 m_mailLevelRewardMap
.clear(); // for reload case
7724 QueryResult
*result
= WorldDatabase
.Query("SELECT level, raceMask, mailTemplateId, senderEntry FROM mail_level_reward");
7733 sLog
.outErrorDb(">> Loaded `mail_level_reward`, table is empty!");
7737 barGoLink
bar( result
->GetRowCount() );
7743 Field
*fields
= result
->Fetch();
7745 uint8 level
= fields
[0].GetUInt8();
7746 uint32 raceMask
= fields
[1].GetUInt32();
7747 uint32 mailTemplateId
= fields
[2].GetUInt32();
7748 uint32 senderEntry
= fields
[3].GetUInt32();
7750 if(level
> MAX_LEVEL
)
7752 sLog
.outErrorDb("Table `mail_level_reward` have data for level %u that more supported by client (%u), ignoring.",level
,MAX_LEVEL
);
7756 if(!(raceMask
& RACEMASK_ALL_PLAYABLE
))
7758 sLog
.outErrorDb("Table `mail_level_reward` have raceMask (%u) for level %u that not include any player races, ignoring.",raceMask
,level
);
7762 if(!sMailTemplateStore
.LookupEntry(mailTemplateId
))
7764 sLog
.outErrorDb("Table `mail_level_reward` have invalid mailTemplateId (%u) for level %u that invalid not include any player races, ignoring.",mailTemplateId
,level
);
7768 if(!GetCreatureTemplateStore(senderEntry
))
7770 sLog
.outErrorDb("Table `mail_level_reward` have not existed sender creature entry (%u) for level %u that invalid not include any player races, ignoring.",senderEntry
,level
);
7774 m_mailLevelRewardMap
[level
].push_back(MailLevelReward(raceMask
,mailTemplateId
,senderEntry
));
7778 while (result
->NextRow());
7782 sLog
.outString( ">> Loaded %u level dependent mail rewards,", count
);
7785 void ObjectMgr::LoadTrainerSpell()
7788 for (CacheTrainerSpellMap::iterator itr
= m_mCacheTrainerSpellMap
.begin(); itr
!= m_mCacheTrainerSpellMap
.end(); ++itr
)
7789 itr
->second
.Clear();
7790 m_mCacheTrainerSpellMap
.clear();
7792 std::set
<uint32
> skip_trainers
;
7794 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer");
7803 sLog
.outErrorDb(">> Loaded `npc_trainer`, table is empty!");
7807 barGoLink
bar( result
->GetRowCount() );
7809 std::set
<uint32
> talentIds
;
7816 Field
* fields
= result
->Fetch();
7818 uint32 entry
= fields
[0].GetUInt32();
7819 uint32 spell
= fields
[1].GetUInt32();
7821 CreatureInfo
const* cInfo
= GetCreatureTemplate(entry
);
7825 sLog
.outErrorDb("Table `npc_trainer` have entry for not existed creature template (Entry: %u), ignore", entry
);
7829 if(!(cInfo
->npcflag
& UNIT_NPC_FLAG_TRAINER
))
7831 if(skip_trainers
.count(entry
) == 0)
7833 sLog
.outErrorDb("Table `npc_trainer` have data for not creature template (Entry: %u) without trainer flag, ignore", entry
);
7834 skip_trainers
.insert(entry
);
7839 SpellEntry
const *spellinfo
= sSpellStore
.LookupEntry(spell
);
7842 sLog
.outErrorDb("Table `npc_trainer` for Trainer (Entry: %u ) has non existing spell %u, ignore", entry
,spell
);
7846 if(!SpellMgr::IsSpellValid(spellinfo
))
7848 sLog
.outErrorDb("Table `npc_trainer` for Trainer (Entry: %u) has broken learning spell %u, ignore", entry
, spell
);
7852 if(GetTalentSpellCost(spell
))
7854 if(talentIds
.count(spell
)==0)
7856 sLog
.outErrorDb("Table `npc_trainer` has talent as learning spell %u, ignore", spell
);
7857 talentIds
.insert(spell
);
7862 TrainerSpellData
& data
= m_mCacheTrainerSpellMap
[entry
];
7864 TrainerSpell
& trainerSpell
= data
.spellList
[spell
];
7865 trainerSpell
.spell
= spell
;
7866 trainerSpell
.spellCost
= fields
[2].GetUInt32();
7867 trainerSpell
.reqSkill
= fields
[3].GetUInt32();
7868 trainerSpell
.reqSkillValue
= fields
[4].GetUInt32();
7869 trainerSpell
.reqLevel
= fields
[5].GetUInt32();
7871 if(!trainerSpell
.reqLevel
)
7872 trainerSpell
.reqLevel
= spellinfo
->spellLevel
;
7874 // calculate learned spell for profession case when stored cast-spell
7875 trainerSpell
.learnedSpell
= spell
;
7876 for(int i
= 0; i
<3; ++i
)
7878 if(spellinfo
->Effect
[i
] != SPELL_EFFECT_LEARN_SPELL
)
7880 if(SpellMgr::IsProfessionOrRidingSpell(spellinfo
->EffectTriggerSpell
[i
]))
7882 trainerSpell
.learnedSpell
= spellinfo
->EffectTriggerSpell
[i
];
7887 if(SpellMgr::IsProfessionSpell(trainerSpell
.learnedSpell
))
7888 data
.trainerType
= 2;
7892 } while (result
->NextRow());
7896 sLog
.outString( ">> Loaded %d Trainers", count
);
7899 void ObjectMgr::LoadVendors()
7902 for (CacheVendorItemMap::iterator itr
= m_mCacheVendorItemMap
.begin(); itr
!= m_mCacheVendorItemMap
.end(); ++itr
)
7903 itr
->second
.Clear();
7904 m_mCacheVendorItemMap
.clear();
7906 std::set
<uint32
> skip_vendors
;
7908 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, item, maxcount, incrtime, ExtendedCost FROM npc_vendor");
7916 sLog
.outErrorDb(">> Loaded `npc_vendor`, table is empty!");
7920 barGoLink
bar( result
->GetRowCount() );
7926 Field
* fields
= result
->Fetch();
7928 uint32 entry
= fields
[0].GetUInt32();
7929 uint32 item_id
= fields
[1].GetUInt32();
7930 uint32 maxcount
= fields
[2].GetUInt32();
7931 uint32 incrtime
= fields
[3].GetUInt32();
7932 uint32 ExtendedCost
= fields
[4].GetUInt32();
7934 if(!IsVendorItemValid(entry
,item_id
,maxcount
,incrtime
,ExtendedCost
,NULL
,&skip_vendors
))
7937 VendorItemData
& vList
= m_mCacheVendorItemMap
[entry
];
7939 vList
.AddItem(item_id
,maxcount
,incrtime
,ExtendedCost
);
7942 } while (result
->NextRow());
7946 sLog
.outString( ">> Loaded %d Vendors ", count
);
7949 void ObjectMgr::LoadNpcTextId()
7952 m_mCacheNpcTextIdMap
.clear();
7954 QueryResult
* result
= WorldDatabase
.Query("SELECT npc_guid, textid FROM npc_gossip");
7962 sLog
.outErrorDb(">> Loaded `npc_gossip`, table is empty!");
7966 barGoLink
bar( result
->GetRowCount() );
7974 Field
* fields
= result
->Fetch();
7976 guid
= fields
[0].GetUInt32();
7977 textid
= fields
[1].GetUInt32();
7979 if (!GetCreatureData(guid
))
7981 sLog
.outErrorDb("Table `npc_gossip` have not existed creature (GUID: %u) entry, ignore. ",guid
);
7984 if (!GetGossipText(textid
))
7986 sLog
.outErrorDb("Table `npc_gossip` for creature (GUID: %u) have wrong Textid (%u), ignore. ", guid
, textid
);
7990 m_mCacheNpcTextIdMap
[guid
] = textid
;
7993 } while (result
->NextRow());
7997 sLog
.outString( ">> Loaded %d NpcTextId ", count
);
8000 void ObjectMgr::LoadGossipMenu()
8002 m_mGossipMenusMap
.clear();
8004 QueryResult
* result
= WorldDatabase
.Query("SELECT entry, text_id, "
8005 "cond_1, cond_1_val_1, cond_1_val_2, cond_2, cond_2_val_1, cond_2_val_2 FROM gossip_menu");
8014 sLog
.outErrorDb(">> Loaded gossip_menu, table is empty!");
8018 barGoLink
bar( result
->GetRowCount() );
8026 Field
* fields
= result
->Fetch();
8030 gMenu
.entry
= fields
[0].GetUInt32();
8031 gMenu
.text_id
= fields
[1].GetUInt32();
8033 ConditionType cond_1
= (ConditionType
)fields
[2].GetUInt32();
8034 uint32 cond_1_val_1
= fields
[3].GetUInt32();
8035 uint32 cond_1_val_2
= fields
[4].GetUInt32();
8036 ConditionType cond_2
= (ConditionType
)fields
[5].GetUInt32();
8037 uint32 cond_2_val_1
= fields
[6].GetUInt32();
8038 uint32 cond_2_val_2
= fields
[7].GetUInt32();
8040 if (!GetGossipText(gMenu
.text_id
))
8042 sLog
.outErrorDb("Table gossip_menu entry %u are using non-existing text_id %u", gMenu
.entry
, gMenu
.text_id
);
8046 if (!PlayerCondition::IsValid(cond_1
, cond_1_val_1
, cond_1_val_2
))
8048 sLog
.outErrorDb("Table gossip_menu entry %u, invalid condition 1 for id %u", gMenu
.entry
, gMenu
.text_id
);
8052 if (!PlayerCondition::IsValid(cond_2
, cond_2_val_1
, cond_2_val_2
))
8054 sLog
.outErrorDb("Table gossip_menu entry %u, invalid condition 2 for id %u", gMenu
.entry
, gMenu
.text_id
);
8058 gMenu
.cond_1
= GetConditionId(cond_1
, cond_1_val_1
, cond_1_val_2
);
8059 gMenu
.cond_2
= GetConditionId(cond_2
, cond_2_val_1
, cond_2_val_2
);
8061 m_mGossipMenusMap
.insert(GossipMenusMap::value_type(gMenu
.entry
, gMenu
));
8065 while(result
->NextRow());
8070 sLog
.outString( ">> Loaded %u gossip_menu entries", count
);
8073 void ObjectMgr::LoadGossipMenuItems()
8075 m_mGossipMenuItemsMap
.clear();
8077 QueryResult
*result
= WorldDatabase
.Query(
8078 "SELECT menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, "
8079 "action_menu_id, action_poi_id, action_script_id, box_coded, box_money, box_text, "
8080 "cond_1, cond_1_val_1, cond_1_val_2, "
8081 "cond_2, cond_2_val_1, cond_2_val_2, "
8082 "cond_3, cond_3_val_1, cond_3_val_2 "
8083 "FROM gossip_menu_option");
8092 sLog
.outErrorDb(">> Loaded gossip_menu_option, table is empty!");
8096 barGoLink
bar(result
->GetRowCount());
8100 std::set
<uint32
> gossipScriptSet
;
8102 for(ScriptMapMap::const_iterator itr
= sGossipScripts
.begin(); itr
!= sGossipScripts
.end(); ++itr
)
8103 gossipScriptSet
.insert(itr
->first
);
8109 Field
* fields
= result
->Fetch();
8111 GossipMenuItems gMenuItem
;
8113 gMenuItem
.menu_id
= fields
[0].GetUInt32();
8114 gMenuItem
.id
= fields
[1].GetUInt32();
8115 gMenuItem
.option_icon
= fields
[2].GetUInt8();
8116 gMenuItem
.option_text
= fields
[3].GetCppString();
8117 gMenuItem
.option_id
= fields
[4].GetUInt32();
8118 gMenuItem
.npc_option_npcflag
= fields
[5].GetUInt32();
8119 gMenuItem
.action_menu_id
= fields
[6].GetUInt32();
8120 gMenuItem
.action_poi_id
= fields
[7].GetUInt32();
8121 gMenuItem
.action_script_id
= fields
[8].GetUInt32();
8122 gMenuItem
.box_coded
= fields
[9].GetUInt8() != 0;
8123 gMenuItem
.box_money
= fields
[10].GetUInt32();
8124 gMenuItem
.box_text
= fields
[11].GetCppString();
8126 ConditionType cond_1
= (ConditionType
)fields
[12].GetUInt32();
8127 uint32 cond_1_val_1
= fields
[13].GetUInt32();
8128 uint32 cond_1_val_2
= fields
[14].GetUInt32();
8129 ConditionType cond_2
= (ConditionType
)fields
[15].GetUInt32();
8130 uint32 cond_2_val_1
= fields
[16].GetUInt32();
8131 uint32 cond_2_val_2
= fields
[17].GetUInt32();
8132 ConditionType cond_3
= (ConditionType
)fields
[18].GetUInt32();
8133 uint32 cond_3_val_1
= fields
[19].GetUInt32();
8134 uint32 cond_3_val_2
= fields
[20].GetUInt32();
8136 if (!PlayerCondition::IsValid(cond_1
, cond_1_val_1
, cond_1_val_2
))
8138 sLog
.outErrorDb("Table gossip_menu_option menu %u, invalid condition 1 for id %u", gMenuItem
.menu_id
, gMenuItem
.id
);
8141 if (!PlayerCondition::IsValid(cond_2
, cond_2_val_1
, cond_2_val_2
))
8143 sLog
.outErrorDb("Table gossip_menu_option menu %u, invalid condition 2 for id %u", gMenuItem
.menu_id
, gMenuItem
.id
);
8146 if (!PlayerCondition::IsValid(cond_3
, cond_3_val_1
, cond_3_val_2
))
8148 sLog
.outErrorDb("Table gossip_menu_option menu %u, invalid condition 3 for id %u", gMenuItem
.menu_id
, gMenuItem
.id
);
8152 if (gMenuItem
.option_icon
>= GOSSIP_ICON_MAX
)
8154 sLog
.outErrorDb("Table gossip_menu_option for menu %u, id %u has unknown icon id %u. Replacing with GOSSIP_ICON_CHAT", gMenuItem
.menu_id
, gMenuItem
.id
, gMenuItem
.option_icon
);
8155 gMenuItem
.option_icon
= GOSSIP_ICON_CHAT
;
8158 if (gMenuItem
.option_id
== GOSSIP_OPTION_NONE
)
8159 sLog
.outErrorDb("Table gossip_menu_option for menu %u, id %u use option id GOSSIP_OPTION_NONE. Option will never be used", gMenuItem
.menu_id
, gMenuItem
.id
);
8161 if (gMenuItem
.option_id
>= GOSSIP_OPTION_MAX
)
8162 sLog
.outErrorDb("Table gossip_menu_option for menu %u, id %u has unknown option id %u. Option will not be used", gMenuItem
.menu_id
, gMenuItem
.id
, gMenuItem
.option_id
);
8164 if (gMenuItem
.action_poi_id
&& !GetPointOfInterest(gMenuItem
.action_poi_id
))
8166 sLog
.outErrorDb("Table gossip_menu_option for menu %u, id %u use non-existing action_poi_id %u, ignoring", gMenuItem
.menu_id
, gMenuItem
.id
, gMenuItem
.action_poi_id
);
8167 gMenuItem
.action_poi_id
= 0;
8170 if (gMenuItem
.action_script_id
)
8172 if (gMenuItem
.option_id
!= GOSSIP_OPTION_GOSSIP
)
8174 sLog
.outErrorDb("Table gossip_menu_option for menu %u, id %u have action_script_id %u but option_id is not GOSSIP_OPTION_GOSSIP, ignoring", gMenuItem
.menu_id
, gMenuItem
.id
, gMenuItem
.action_script_id
);
8178 if (sGossipScripts
.find(gMenuItem
.action_script_id
) == sGossipScripts
.end())
8180 sLog
.outErrorDb("Table gossip_menu_option for menu %u, id %u have action_script_id %u that does not exist in `gossip_scripts`, ignoring", gMenuItem
.menu_id
, gMenuItem
.id
, gMenuItem
.action_script_id
);
8184 gossipScriptSet
.erase(gMenuItem
.action_script_id
);
8187 gMenuItem
.cond_1
= GetConditionId(cond_1
, cond_1_val_1
, cond_1_val_2
);
8188 gMenuItem
.cond_2
= GetConditionId(cond_2
, cond_2_val_1
, cond_2_val_2
);
8189 gMenuItem
.cond_3
= GetConditionId(cond_3
, cond_3_val_1
, cond_3_val_2
);
8191 m_mGossipMenuItemsMap
.insert(GossipMenuItemsMap::value_type(gMenuItem
.menu_id
, gMenuItem
));
8196 while(result
->NextRow());
8200 if (!gossipScriptSet
.empty())
8202 for(std::set
<uint32
>::const_iterator itr
= gossipScriptSet
.begin(); itr
!= gossipScriptSet
.end(); ++itr
)
8203 sLog
.outErrorDb("Table `gossip_scripts` contain unused script, id %u.", *itr
);
8207 sLog
.outString(">> Loaded %u gossip_menu_option entries", count
);
8210 void ObjectMgr::AddVendorItem( uint32 entry
,uint32 item
, uint32 maxcount
, uint32 incrtime
, uint32 extendedcost
)
8212 VendorItemData
& vList
= m_mCacheVendorItemMap
[entry
];
8213 vList
.AddItem(item
,maxcount
,incrtime
,extendedcost
);
8215 WorldDatabase
.PExecuteLog("INSERT INTO npc_vendor (entry,item,maxcount,incrtime,extendedcost) VALUES('%u','%u','%u','%u','%u')",entry
, item
, maxcount
,incrtime
,extendedcost
);
8218 bool ObjectMgr::RemoveVendorItem( uint32 entry
,uint32 item
)
8220 CacheVendorItemMap::iterator iter
= m_mCacheVendorItemMap
.find(entry
);
8221 if(iter
== m_mCacheVendorItemMap
.end())
8224 if(!iter
->second
.FindItem(item
))
8227 iter
->second
.RemoveItem(item
);
8228 WorldDatabase
.PExecuteLog("DELETE FROM npc_vendor WHERE entry='%u' AND item='%u'",entry
, item
);
8232 bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry
, uint32 item_id
, uint32 maxcount
, uint32 incrtime
, uint32 ExtendedCost
, Player
* pl
, std::set
<uint32
>* skip_vendors
) const
8234 CreatureInfo
const* cInfo
= GetCreatureTemplate(vendor_entry
);
8238 ChatHandler(pl
).SendSysMessage(LANG_COMMAND_VENDORSELECTION
);
8240 sLog
.outErrorDb("Table `npc_vendor` have data for not existed creature template (Entry: %u), ignore", vendor_entry
);
8244 if(!(cInfo
->npcflag
& UNIT_NPC_FLAG_VENDOR
))
8246 if(!skip_vendors
|| skip_vendors
->count(vendor_entry
)==0)
8249 ChatHandler(pl
).SendSysMessage(LANG_COMMAND_VENDORSELECTION
);
8251 sLog
.outErrorDb("Table `npc_vendor` have data for not creature template (Entry: %u) without vendor flag, ignore", vendor_entry
);
8254 skip_vendors
->insert(vendor_entry
);
8259 if(!GetItemPrototype(item_id
))
8262 ChatHandler(pl
).PSendSysMessage(LANG_ITEM_NOT_FOUND
, item_id
);
8264 sLog
.outErrorDb("Table `npc_vendor` for Vendor (Entry: %u) have in item list non-existed item (%u), ignore",vendor_entry
,item_id
);
8268 if(ExtendedCost
&& !sItemExtendedCostStore
.LookupEntry(ExtendedCost
))
8271 ChatHandler(pl
).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST
,ExtendedCost
);
8273 sLog
.outErrorDb("Table `npc_vendor` have Item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignore",item_id
,ExtendedCost
,vendor_entry
);
8277 if(maxcount
> 0 && incrtime
== 0)
8280 ChatHandler(pl
).PSendSysMessage("MaxCount!=0 (%u) but IncrTime==0", maxcount
);
8282 sLog
.outErrorDb( "Table `npc_vendor` has `maxcount` (%u) for item %u of vendor (Entry: %u) but `incrtime`=0, ignore", maxcount
, item_id
, vendor_entry
);
8285 else if(maxcount
==0 && incrtime
> 0)
8288 ChatHandler(pl
).PSendSysMessage("MaxCount==0 but IncrTime<>=0");
8290 sLog
.outErrorDb( "Table `npc_vendor` has `maxcount`=0 for item %u of vendor (Entry: %u) but `incrtime`<>0, ignore", item_id
, vendor_entry
);
8294 VendorItemData
const* vItems
= GetNpcVendorItemList(vendor_entry
);
8296 return true; // later checks for non-empty lists
8298 if(vItems
->FindItem(item_id
))
8301 ChatHandler(pl
).PSendSysMessage(LANG_ITEM_ALREADY_IN_LIST
,item_id
);
8303 sLog
.outErrorDb( "Table `npc_vendor` has duplicate items %u for vendor (Entry: %u), ignore", item_id
, vendor_entry
);
8307 if(vItems
->GetItemCount() >= MAX_VENDOR_ITEMS
)
8310 ChatHandler(pl
).SendSysMessage(LANG_COMMAND_ADDVENDORITEMITEMS
);
8312 sLog
.outErrorDb( "Table `npc_vendor` has too many items (%u >= %i) for vendor (Entry: %u), ignore", vItems
->GetItemCount(), MAX_VENDOR_ITEMS
, vendor_entry
);
8319 void ObjectMgr::LoadScriptNames()
8321 m_scriptNames
.push_back("");
8322 QueryResult
*result
= WorldDatabase
.Query(
8323 "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' "
8325 "SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' "
8327 "SELECT DISTINCT(ScriptName) FROM item_template WHERE ScriptName <> '' "
8329 "SELECT DISTINCT(ScriptName) FROM areatrigger_scripts WHERE ScriptName <> '' "
8331 "SELECT DISTINCT(script) FROM instance_template WHERE script <> ''");
8338 sLog
.outErrorDb(">> Loaded empty set of Script Names!");
8342 barGoLink
bar( result
->GetRowCount() );
8348 m_scriptNames
.push_back((*result
)[0].GetString());
8350 } while (result
->NextRow());
8353 std::sort(m_scriptNames
.begin(), m_scriptNames
.end());
8355 sLog
.outString( ">> Loaded %d Script Names", count
);
8358 uint32
ObjectMgr::GetScriptId(const char *name
)
8360 // use binary search to find the script name in the sorted vector
8361 // assume "" is the first element
8363 ScriptNameMap::const_iterator itr
=
8364 std::lower_bound(m_scriptNames
.begin(), m_scriptNames
.end(), name
);
8365 if(itr
== m_scriptNames
.end() || *itr
!= name
) return 0;
8366 return itr
- m_scriptNames
.begin();
8369 void ObjectMgr::CheckScripts(ScriptMapMap
const& scripts
,std::set
<int32
>& ids
)
8371 for(ScriptMapMap::const_iterator itrMM
= scripts
.begin(); itrMM
!= scripts
.end(); ++itrMM
)
8373 for(ScriptMap::const_iterator itrM
= itrMM
->second
.begin(); itrM
!= itrMM
->second
.end(); ++itrM
)
8375 switch(itrM
->second
.command
)
8377 case SCRIPT_COMMAND_TALK
:
8379 if(!GetMangosStringLocale (itrM
->second
.dataint
))
8380 sLog
.outErrorDb( "Table `db_script_string` is missing string id %u, used in database script id %u.", itrM
->second
.dataint
, itrMM
->first
);
8382 if(ids
.count(itrM
->second
.dataint
))
8383 ids
.erase(itrM
->second
.dataint
);
8390 void ObjectMgr::LoadDbScriptStrings()
8392 LoadMangosStrings(WorldDatabase
,"db_script_string",MIN_DB_SCRIPT_STRING_ID
,MAX_DB_SCRIPT_STRING_ID
);
8394 std::set
<int32
> ids
;
8396 for(int32 i
= MIN_DB_SCRIPT_STRING_ID
; i
< MAX_DB_SCRIPT_STRING_ID
; ++i
)
8397 if(GetMangosStringLocale(i
))
8400 CheckScripts(sQuestEndScripts
,ids
);
8401 CheckScripts(sQuestStartScripts
,ids
);
8402 CheckScripts(sSpellScripts
,ids
);
8403 CheckScripts(sGameObjectScripts
,ids
);
8404 CheckScripts(sEventScripts
,ids
);
8405 CheckScripts(sGossipScripts
,ids
);
8407 sWaypointMgr
.CheckTextsExistance(ids
);
8409 for(std::set
<int32
>::const_iterator itr
= ids
.begin(); itr
!= ids
.end(); ++itr
)
8410 sLog
.outErrorDb( "Table `db_script_string` has unused string id %u", *itr
);
8413 // Functions for scripting access
8414 uint32
GetAreaTriggerScriptId(uint32 trigger_id
)
8416 return sObjectMgr
.GetAreaTriggerScriptId(trigger_id
);
8419 bool LoadMangosStrings(DatabaseType
& db
, char const* table
,int32 start_value
, int32 end_value
)
8421 // MAX_DB_SCRIPT_STRING_ID is max allowed negative value for scripts (scrpts can use only more deep negative values
8422 // start/end reversed for negative values
8423 if (start_value
> MAX_DB_SCRIPT_STRING_ID
|| end_value
>= start_value
)
8425 sLog
.outErrorDb("Table '%s' attempt loaded with reserved by mangos range (%d - %d), strings not loaded.",table
,start_value
,end_value
+1);
8429 return sObjectMgr
.LoadMangosStrings(db
,table
,start_value
,end_value
);
8432 uint32 MANGOS_DLL_SPEC
GetScriptId(const char *name
)
8434 return sObjectMgr
.GetScriptId(name
);
8437 ObjectMgr::ScriptNameMap
& GetScriptNames()
8439 return sObjectMgr
.GetScriptNames();
8442 CreatureInfo
const* GetCreatureTemplateStore(uint32 entry
)
8444 return sCreatureStorage
.LookupEntry
<CreatureInfo
>(entry
);
8447 Quest
const* GetQuestTemplateStore(uint32 entry
)
8449 return sObjectMgr
.GetQuestTemplate(entry
);