2 * Copyright (C) 2005-2009 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"
29 #include "UpdateMask.h"
33 #include "ArenaTeam.h"
34 #include "Transports.h"
35 #include "ProgressBar.h"
37 #include "GameEventMgr.h"
40 #include "AccountMgr.h"
41 #include "InstanceSaveMgr.h"
42 #include "SpellAuras.h"
44 #include "WaypointManager.h"
46 INSTANTIATE_SINGLETON_1(ObjectMgr
);
48 ScriptMapMap sQuestEndScripts
;
49 ScriptMapMap sQuestStartScripts
;
50 ScriptMapMap sSpellScripts
;
51 ScriptMapMap sGameObjectScripts
;
52 ScriptMapMap sEventScripts
;
54 bool normalizePlayerName(std::string
& name
)
59 wchar_t wstr_buf
[MAX_INTERNAL_PLAYER_NAME
+1];
60 size_t wstr_len
= MAX_INTERNAL_PLAYER_NAME
;
62 if(!Utf8toWStr(name
,&wstr_buf
[0],wstr_len
))
65 wstr_buf
[0] = wcharToUpper(wstr_buf
[0]);
66 for(size_t i
= 1; i
< wstr_len
; ++i
)
67 wstr_buf
[i
] = wcharToLower(wstr_buf
[i
]);
69 if(!WStrToUtf8(wstr_buf
,wstr_len
,name
))
75 LanguageDesc lang_description
[LANGUAGES_COUNT
] =
78 { LANG_UNIVERSAL
, 0, 0 },
79 { LANG_ORCISH
, 669, SKILL_LANG_ORCISH
},
80 { LANG_DARNASSIAN
, 671, SKILL_LANG_DARNASSIAN
},
81 { LANG_TAURAHE
, 670, SKILL_LANG_TAURAHE
},
82 { LANG_DWARVISH
, 672, SKILL_LANG_DWARVEN
},
83 { LANG_COMMON
, 668, SKILL_LANG_COMMON
},
84 { LANG_DEMONIC
, 815, SKILL_LANG_DEMON_TONGUE
},
85 { LANG_TITAN
, 816, SKILL_LANG_TITAN
},
86 { LANG_THALASSIAN
, 813, SKILL_LANG_THALASSIAN
},
87 { LANG_DRACONIC
, 814, SKILL_LANG_DRACONIC
},
88 { LANG_KALIMAG
, 817, SKILL_LANG_OLD_TONGUE
},
89 { LANG_GNOMISH
, 7340, SKILL_LANG_GNOMISH
},
90 { LANG_TROLL
, 7341, SKILL_LANG_TROLL
},
91 { LANG_GUTTERSPEAK
, 17737, SKILL_LANG_GUTTERSPEAK
},
92 { LANG_DRAENEI
, 29932, SKILL_LANG_DRAENEI
},
93 { LANG_ZOMBIE
, 0, 0 },
94 { LANG_GNOMISH_BINARY
, 0, 0 },
95 { LANG_GOBLIN_BINARY
, 0, 0 }
98 LanguageDesc
const* GetLanguageDescByID(uint32 lang
)
100 for(int i
= 0; i
< LANGUAGES_COUNT
; ++i
)
102 if(uint32(lang_description
[i
].lang_id
) == lang
)
103 return &lang_description
[i
];
109 ObjectMgr::ObjectMgr()
112 m_hiCreatureGuid
= 1;
126 // Only zero condition left, others will be added while loading DB tables
127 mConditions
.resize(1);
130 ObjectMgr::~ObjectMgr()
132 for( QuestMap::iterator i
= mQuestTemplates
.begin( ); i
!= mQuestTemplates
.end( ); ++i
)
135 for(PetLevelInfoMap::iterator i
= petInfo
.begin( ); i
!= petInfo
.end( ); ++i
)
138 // free only if loaded
139 for (int class_
= 0; class_
< MAX_CLASSES
; ++class_
)
140 delete[] playerClassInfo
[class_
].levelInfo
;
142 for (int race
= 0; race
< MAX_RACES
; ++race
)
143 for (int class_
= 0; class_
< MAX_CLASSES
; ++class_
)
144 delete[] playerInfo
[race
][class_
].levelInfo
;
146 // free group and guild objects
147 for (GroupSet::iterator itr
= mGroupSet
.begin(); itr
!= mGroupSet
.end(); ++itr
)
150 for (GuildMap::iterator itr
= mGuildMap
.begin(); itr
!= mGuildMap
.end(); ++itr
)
153 for (CacheVendorItemMap::iterator itr
= m_mCacheVendorItemMap
.begin(); itr
!= m_mCacheVendorItemMap
.end(); ++itr
)
156 for (CacheTrainerSpellMap::iterator itr
= m_mCacheTrainerSpellMap
.begin(); itr
!= m_mCacheTrainerSpellMap
.end(); ++itr
)
160 Group
* ObjectMgr::GetGroupByLeader(const uint64
&guid
) const
162 for(GroupSet::const_iterator itr
= mGroupSet
.begin(); itr
!= mGroupSet
.end(); ++itr
)
163 if ((*itr
)->GetLeaderGUID() == guid
)
169 Guild
* ObjectMgr::GetGuildById(uint32 GuildId
) const
171 GuildMap::const_iterator itr
= mGuildMap
.find(GuildId
);
172 if (itr
!= mGuildMap
.end())
178 Guild
* ObjectMgr::GetGuildByName(const std::string
& guildname
) const
180 for(GuildMap::const_iterator itr
= mGuildMap
.begin(); itr
!= mGuildMap
.end(); ++itr
)
181 if (itr
->second
->GetName() == guildname
)
187 std::string
ObjectMgr::GetGuildNameById(uint32 GuildId
) const
189 GuildMap::const_iterator itr
= mGuildMap
.find(GuildId
);
190 if (itr
!= mGuildMap
.end())
191 return itr
->second
->GetName();
196 Guild
* ObjectMgr::GetGuildByLeader(const uint64
&guid
) const
198 for(GuildMap::const_iterator itr
= mGuildMap
.begin(); itr
!= mGuildMap
.end(); ++itr
)
199 if (itr
->second
->GetLeader() == guid
)
205 void ObjectMgr::AddGuild(Guild
* guild
)
207 mGuildMap
[guild
->GetId()] = guild
;
210 void ObjectMgr::RemoveGuild(uint32 Id
)
215 ArenaTeam
* ObjectMgr::GetArenaTeamById(uint32 arenateamid
) const
217 ArenaTeamMap::const_iterator itr
= mArenaTeamMap
.find(arenateamid
);
218 if (itr
!= mArenaTeamMap
.end())
224 ArenaTeam
* ObjectMgr::GetArenaTeamByName(const std::string
& arenateamname
) const
226 for(ArenaTeamMap::const_iterator itr
= mArenaTeamMap
.begin(); itr
!= mArenaTeamMap
.end(); ++itr
)
227 if (itr
->second
->GetName() == arenateamname
)
233 ArenaTeam
* ObjectMgr::GetArenaTeamByCaptain(uint64
const& guid
) const
235 for(ArenaTeamMap::const_iterator itr
= mArenaTeamMap
.begin(); itr
!= mArenaTeamMap
.end(); ++itr
)
236 if (itr
->second
->GetCaptain() == guid
)
242 void ObjectMgr::AddArenaTeam(ArenaTeam
* arenaTeam
)
244 mArenaTeamMap
[arenaTeam
->GetId()] = arenaTeam
;
247 void ObjectMgr::RemoveArenaTeam(uint32 Id
)
249 mArenaTeamMap
.erase(Id
);
252 CreatureInfo
const* ObjectMgr::GetCreatureTemplate(uint32 id
)
254 return sCreatureStorage
.LookupEntry
<CreatureInfo
>(id
);
257 void ObjectMgr::LoadCreatureLocales()
259 mCreatureLocaleMap
.clear(); // need for reload case
261 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");
270 sLog
.outString(">> Loaded 0 creature locale strings. DB table `locales_creature` is empty.");
274 barGoLink
bar(result
->GetRowCount());
278 Field
*fields
= result
->Fetch();
281 uint32 entry
= fields
[0].GetUInt32();
283 CreatureLocale
& data
= mCreatureLocaleMap
[entry
];
285 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
287 std::string str
= fields
[1+2*(i
-1)].GetCppString();
290 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
293 if(data
.Name
.size() <= idx
)
294 data
.Name
.resize(idx
+1);
296 data
.Name
[idx
] = str
;
299 str
= fields
[1+2*(i
-1)+1].GetCppString();
302 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
305 if(data
.SubName
.size() <= idx
)
306 data
.SubName
.resize(idx
+1);
308 data
.SubName
[idx
] = str
;
312 } while (result
->NextRow());
317 sLog
.outString( ">> Loaded %lu creature locale strings", (unsigned long)mCreatureLocaleMap
.size() );
320 void ObjectMgr::LoadNpcOptionLocales()
322 mNpcOptionLocaleMap
.clear(); // need for reload case
324 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,"
325 "option_text_loc1,box_text_loc1,option_text_loc2,box_text_loc2,"
326 "option_text_loc3,box_text_loc3,option_text_loc4,box_text_loc4,"
327 "option_text_loc5,box_text_loc5,option_text_loc6,box_text_loc6,"
328 "option_text_loc7,box_text_loc7,option_text_loc8,box_text_loc8 "
329 "FROM locales_npc_option");
338 sLog
.outString(">> Loaded 0 npc_option locale strings. DB table `locales_npc_option` is empty.");
342 barGoLink
bar(result
->GetRowCount());
346 Field
*fields
= result
->Fetch();
349 uint32 entry
= fields
[0].GetUInt32();
351 NpcOptionLocale
& data
= mNpcOptionLocaleMap
[entry
];
353 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
355 std::string str
= fields
[1+2*(i
-1)].GetCppString();
358 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
361 if(data
.OptionText
.size() <= idx
)
362 data
.OptionText
.resize(idx
+1);
364 data
.OptionText
[idx
] = str
;
367 str
= fields
[1+2*(i
-1)+1].GetCppString();
370 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
373 if(data
.BoxText
.size() <= idx
)
374 data
.BoxText
.resize(idx
+1);
376 data
.BoxText
[idx
] = str
;
380 } while (result
->NextRow());
385 sLog
.outString( ">> Loaded %lu npc_option locale strings", (unsigned long)mNpcOptionLocaleMap
.size() );
388 void ObjectMgr::LoadPointOfInterestLocales()
390 mPointOfInterestLocaleMap
.clear(); // need for reload case
392 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");
401 sLog
.outString(">> Loaded 0 points_of_interest locale strings. DB table `locales_points_of_interest` is empty.");
405 barGoLink
bar(result
->GetRowCount());
409 Field
*fields
= result
->Fetch();
412 uint32 entry
= fields
[0].GetUInt32();
414 PointOfInterestLocale
& data
= mPointOfInterestLocaleMap
[entry
];
416 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
418 std::string str
= fields
[i
].GetCppString();
422 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
425 if(data
.IconName
.size() <= idx
)
426 data
.IconName
.resize(idx
+1);
428 data
.IconName
[idx
] = str
;
431 } while (result
->NextRow());
436 sLog
.outString( ">> Loaded %lu points_of_interest locale strings", (unsigned long)mPointOfInterestLocaleMap
.size() );
439 struct SQLCreatureLoader
: public SQLStorageLoaderBase
<SQLCreatureLoader
>
442 void convert_from_str(uint32
/*field_pos*/, char *src
, D
&dst
)
444 dst
= D(objmgr
.GetScriptId(src
));
448 void ObjectMgr::LoadCreatureTemplates()
450 SQLCreatureLoader loader
;
451 loader
.Load(sCreatureStorage
);
453 sLog
.outString( ">> Loaded %u creature definitions", sCreatureStorage
.RecordCount
);
456 std::set
<uint32
> heroicEntries
; // already loaded heroic value in creatures
457 std::set
<uint32
> hasHeroicEntries
; // already loaded creatures with heroic entry values
459 // check data correctness
460 for(uint32 i
= 1; i
< sCreatureStorage
.MaxEntry
; ++i
)
462 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
>(i
);
466 if(cInfo
->HeroicEntry
)
468 CreatureInfo
const* heroicInfo
= GetCreatureTemplate(cInfo
->HeroicEntry
);
471 sLog
.outErrorDb("Creature (Entry: %u) have `heroic_entry`=%u but creature entry %u not exist.",cInfo
->HeroicEntry
,cInfo
->HeroicEntry
);
475 if(heroicEntries
.find(i
)!=heroicEntries
.end())
477 sLog
.outErrorDb("Creature (Entry: %u) listed as heroic but have value in `heroic_entry`.",i
);
481 if(heroicEntries
.find(cInfo
->HeroicEntry
)!=heroicEntries
.end())
483 sLog
.outErrorDb("Creature (Entry: %u) already listed as heroic for another entry.",cInfo
->HeroicEntry
);
487 if(hasHeroicEntries
.find(cInfo
->HeroicEntry
)!=hasHeroicEntries
.end())
489 sLog
.outErrorDb("Creature (Entry: %u) have `heroic_entry`=%u but creature entry %u have heroic entry also.",i
,cInfo
->HeroicEntry
,cInfo
->HeroicEntry
);
493 if(cInfo
->unit_class
!= heroicInfo
->unit_class
)
495 sLog
.outErrorDb("Creature (Entry: %u, class %u) has different `unit_class` in heroic mode (Entry: %u, class %u).",i
, cInfo
->unit_class
, cInfo
->HeroicEntry
, heroicInfo
->unit_class
);
499 if(cInfo
->npcflag
!= heroicInfo
->npcflag
)
501 sLog
.outErrorDb("Creature (Entry: %u) has different `npcflag` in heroic mode (Entry: %u).",i
,cInfo
->HeroicEntry
);
505 if(cInfo
->trainer_class
!= heroicInfo
->trainer_class
)
507 sLog
.outErrorDb("Creature (Entry: %u) has different `trainer_class` in heroic mode (Entry: %u).",i
,cInfo
->HeroicEntry
);
511 if(cInfo
->trainer_race
!= heroicInfo
->trainer_race
)
513 sLog
.outErrorDb("Creature (Entry: %u) has different `trainer_race` in heroic mode (Entry: %u).",i
,cInfo
->HeroicEntry
);
517 if(cInfo
->trainer_type
!= heroicInfo
->trainer_type
)
519 sLog
.outErrorDb("Creature (Entry: %u) has different `trainer_type` in heroic mode (Entry: %u).",i
,cInfo
->HeroicEntry
);
523 if(cInfo
->trainer_spell
!= heroicInfo
->trainer_spell
)
525 sLog
.outErrorDb("Creature (Entry: %u) has different `trainer_spell` in heroic mode (Entry: %u).",i
,cInfo
->HeroicEntry
);
529 if(heroicInfo
->AIName
&& *heroicInfo
->AIName
)
531 sLog
.outErrorDb("Heroic mode creature (Entry: %u) has `AIName`, but in any case will used normal mode creature (Entry: %u) AIName.",cInfo
->HeroicEntry
,i
);
535 if(heroicInfo
->ScriptID
)
537 sLog
.outErrorDb("Heroic mode creature (Entry: %u) has `ScriptName`, but in any case will used normal mode creature (Entry: %u) ScriptName.",cInfo
->HeroicEntry
,i
);
541 hasHeroicEntries
.insert(i
);
542 heroicEntries
.insert(cInfo
->HeroicEntry
);
545 FactionTemplateEntry
const* factionTemplate
= sFactionTemplateStore
.LookupEntry(cInfo
->faction_A
);
547 sLog
.outErrorDb("Creature (Entry: %u) has non-existing faction_A template (%u)", cInfo
->Entry
, cInfo
->faction_A
);
549 factionTemplate
= sFactionTemplateStore
.LookupEntry(cInfo
->faction_H
);
551 sLog
.outErrorDb("Creature (Entry: %u) has non-existing faction_H template (%u)", cInfo
->Entry
, cInfo
->faction_H
);
553 CreatureModelInfo
const* minfo
= sCreatureModelStorage
.LookupEntry
<CreatureModelInfo
>(cInfo
->DisplayID_A
);
555 sLog
.outErrorDb("Creature (Entry: %u) has non-existing modelId_A (%u)", cInfo
->Entry
, cInfo
->DisplayID_A
);
556 minfo
= sCreatureModelStorage
.LookupEntry
<CreatureModelInfo
>(cInfo
->DisplayID_H
);
558 sLog
.outErrorDb("Creature (Entry: %u) has non-existing modelId_H (%u)", cInfo
->Entry
, cInfo
->DisplayID_H
);
560 if (cInfo
->unit_class
&& ((1 << (cInfo
->unit_class
-1)) & CLASSMASK_ALL_CREATURES
) == 0)
561 sLog
.outErrorDb("Creature (Entry: %u) has invalid unit_class(%u) for creature_template", cInfo
->Entry
, cInfo
->unit_class
);
563 if(cInfo
->dmgschool
>= MAX_SPELL_SCHOOL
)
565 sLog
.outErrorDb("Creature (Entry: %u) has invalid spell school value (%u) in `dmgschool`",cInfo
->Entry
,cInfo
->dmgschool
);
566 const_cast<CreatureInfo
*>(cInfo
)->dmgschool
= SPELL_SCHOOL_NORMAL
;
569 if(cInfo
->baseattacktime
== 0)
570 const_cast<CreatureInfo
*>(cInfo
)->baseattacktime
= BASE_ATTACK_TIME
;
572 if(cInfo
->rangeattacktime
== 0)
573 const_cast<CreatureInfo
*>(cInfo
)->rangeattacktime
= BASE_ATTACK_TIME
;
575 if((cInfo
->npcflag
& UNIT_NPC_FLAG_TRAINER
) && cInfo
->trainer_type
>= MAX_TRAINER_TYPE
)
576 sLog
.outErrorDb("Creature (Entry: %u) has wrong trainer type %u",cInfo
->Entry
,cInfo
->trainer_type
);
578 if(cInfo
->type
&& !sCreatureTypeStore
.LookupEntry(cInfo
->type
))
580 sLog
.outErrorDb("Creature (Entry: %u) has invalid creature type (%u) in `type`",cInfo
->Entry
,cInfo
->type
);
581 const_cast<CreatureInfo
*>(cInfo
)->type
= CREATURE_TYPE_HUMANOID
;
584 // must exist or used hidden but used in data horse case
585 if(cInfo
->family
&& !sCreatureFamilyStore
.LookupEntry(cInfo
->family
) && cInfo
->family
!= CREATURE_FAMILY_HORSE_CUSTOM
)
587 sLog
.outErrorDb("Creature (Entry: %u) has invalid creature family (%u) in `family`",cInfo
->Entry
,cInfo
->family
);
588 const_cast<CreatureInfo
*>(cInfo
)->family
= 0;
591 if(cInfo
->InhabitType
<= 0 || cInfo
->InhabitType
> INHABIT_ANYWHERE
)
593 sLog
.outErrorDb("Creature (Entry: %u) has wrong value (%u) in `InhabitType`, creature will not correctly walk/swim/fly",cInfo
->Entry
,cInfo
->InhabitType
);
594 const_cast<CreatureInfo
*>(cInfo
)->InhabitType
= INHABIT_ANYWHERE
;
597 if(cInfo
->PetSpellDataId
)
599 CreatureSpellDataEntry
const* spellDataId
= sCreatureSpellDataStore
.LookupEntry(cInfo
->PetSpellDataId
);
601 sLog
.outErrorDb("Creature (Entry: %u) has non-existing PetSpellDataId (%u)", cInfo
->Entry
, cInfo
->PetSpellDataId
);
604 for(int j
= 0; j
< CREATURE_MAX_SPELLS
; ++j
)
606 if(cInfo
->spells
[j
] && !sSpellStore
.LookupEntry(cInfo
->spells
[j
]))
608 sLog
.outErrorDb("Creature (Entry: %u) has non-existing Spell%d (%u), set to 0", cInfo
->Entry
, j
+1,cInfo
->spells
[j
]);
609 const_cast<CreatureInfo
*>(cInfo
)->spells
[j
] = 0;
613 if(cInfo
->MovementType
>= MAX_DB_MOTION_TYPE
)
615 sLog
.outErrorDb("Creature (Entry: %u) has wrong movement generator type (%u), ignore and set to IDLE.",cInfo
->Entry
,cInfo
->MovementType
);
616 const_cast<CreatureInfo
*>(cInfo
)->MovementType
= IDLE_MOTION_TYPE
;
619 if(cInfo
->equipmentId
> 0) // 0 no equipment
621 if(!GetEquipmentInfo(cInfo
->equipmentId
))
623 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
);
624 const_cast<CreatureInfo
*>(cInfo
)->equipmentId
= 0;
628 /// if not set custom creature scale then load scale from CreatureDisplayInfo.dbc
629 if(cInfo
->scale
<= 0.0f
)
631 CreatureDisplayInfoEntry
const* ScaleEntry
= sCreatureDisplayInfoStore
.LookupEntry(cInfo
->DisplayID_A
);
632 const_cast<CreatureInfo
*>(cInfo
)->scale
= ScaleEntry
? ScaleEntry
->scale
: 1.0f
;
637 void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon
* addon
, char const* table
, char const* guidEntryStr
)
639 // Now add the auras, format "spellid effectindex spellid effectindex..."
641 std::vector
<int> val
;
642 s
=p
=(char*)reinterpret_cast<char const*>(addon
->auras
);
650 val
.push_back(atoi(s
));
655 val
.push_back(atoi(s
));
657 // free char* loaded memory
658 delete[] (char*)reinterpret_cast<char const*>(addon
->auras
);
664 sLog
.outErrorDb("Creature (%s: %u) has wrong `auras` data in `%s`.",guidEntryStr
,addon
->guidOrEntry
,table
);
676 // replace by new structures array
677 const_cast<CreatureDataAddonAura
*&>(addon
->auras
) = new CreatureDataAddonAura
[val
.size()/2+1];
680 for(int j
=0;j
<val
.size()/2;++j
)
682 CreatureDataAddonAura
& cAura
= const_cast<CreatureDataAddonAura
&>(addon
->auras
[i
]);
683 cAura
.spell_id
= (uint32
)val
[2*j
+0];
684 cAura
.effect_idx
= (uint32
)val
[2*j
+1];
685 if ( cAura
.effect_idx
> 2 )
687 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
);
690 SpellEntry
const *AdditionalSpellInfo
= sSpellStore
.LookupEntry(cAura
.spell_id
);
691 if (!AdditionalSpellInfo
)
693 sLog
.outErrorDb("Creature (%s: %u) has wrong spell %u defined in `auras` field in `%s`.",guidEntryStr
,addon
->guidOrEntry
,cAura
.spell_id
,table
);
697 if (!AdditionalSpellInfo
->Effect
[cAura
.effect_idx
] || !AdditionalSpellInfo
->EffectApplyAuraName
[cAura
.effect_idx
])
699 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
);
706 // fill terminator element (after last added)
707 CreatureDataAddonAura
& endAura
= const_cast<CreatureDataAddonAura
&>(addon
->auras
[i
]);
708 endAura
.spell_id
= 0;
709 endAura
.effect_idx
= 0;
712 void ObjectMgr::LoadCreatureAddons()
714 sCreatureInfoAddonStorage
.Load();
716 sLog
.outString( ">> Loaded %u creature template addons", sCreatureInfoAddonStorage
.RecordCount
);
719 // check data correctness and convert 'auras'
720 for(uint32 i
= 1; i
< sCreatureInfoAddonStorage
.MaxEntry
; ++i
)
722 CreatureDataAddon
const* addon
= sCreatureInfoAddonStorage
.LookupEntry
<CreatureDataAddon
>(i
);
728 if (!sCreatureDisplayInfoStore
.LookupEntry(addon
->mount
))
729 sLog
.outErrorDb("Creature (Entry %u) have invalid displayInfoId for mount (%u) defined in `creature_template_addon`.",addon
->guidOrEntry
, addon
->mount
);
732 if (!sEmotesStore
.LookupEntry(addon
->emote
))
733 sLog
.outErrorDb("Creature (Entry %u) have invalid emote (%u) defined in `creature_template_addon`.",addon
->guidOrEntry
, addon
->emote
);
735 ConvertCreatureAddonAuras(const_cast<CreatureDataAddon
*>(addon
), "creature_template_addon", "Entry");
737 if(!sCreatureStorage
.LookupEntry
<CreatureInfo
>(addon
->guidOrEntry
))
738 sLog
.outErrorDb("Creature (Entry: %u) does not exist but has a record in `creature_template_addon`",addon
->guidOrEntry
);
741 sCreatureDataAddonStorage
.Load();
743 sLog
.outString( ">> Loaded %u creature addons", sCreatureDataAddonStorage
.RecordCount
);
746 // check data correctness and convert 'auras'
747 for(uint32 i
= 1; i
< sCreatureDataAddonStorage
.MaxEntry
; ++i
)
749 CreatureDataAddon
const* addon
= sCreatureDataAddonStorage
.LookupEntry
<CreatureDataAddon
>(i
);
755 if (!sCreatureDisplayInfoStore
.LookupEntry(addon
->mount
))
756 sLog
.outErrorDb("Creature (GUID %u) have invalid displayInfoId for mount (%u) defined in `creature_addon`.",addon
->guidOrEntry
, addon
->mount
);
759 if (!sEmotesStore
.LookupEntry(addon
->emote
))
760 sLog
.outErrorDb("Creature (GUID %u) have invalid emote (%u) defined in `creature_addon`.",addon
->guidOrEntry
, addon
->emote
);
762 ConvertCreatureAddonAuras(const_cast<CreatureDataAddon
*>(addon
), "creature_addon", "GUIDLow");
764 if(mCreatureDataMap
.find(addon
->guidOrEntry
)==mCreatureDataMap
.end())
765 sLog
.outErrorDb("Creature (GUID: %u) does not exist but has a record in `creature_addon`",addon
->guidOrEntry
);
769 EquipmentInfo
const* ObjectMgr::GetEquipmentInfo(uint32 entry
)
771 return sEquipmentStorage
.LookupEntry
<EquipmentInfo
>(entry
);
774 void ObjectMgr::LoadEquipmentTemplates()
776 sEquipmentStorage
.Load();
778 for(uint32 i
=0; i
< sEquipmentStorage
.MaxEntry
; ++i
)
780 EquipmentInfo
const* eqInfo
= sEquipmentStorage
.LookupEntry
<EquipmentInfo
>(i
);
785 for(uint8 j
=0; j
<3; j
++)
787 if(!eqInfo
->equipentry
[j
])
790 ItemEntry
const *dbcitem
= sItemStore
.LookupEntry(eqInfo
->equipentry
[j
]);
794 sLog
.outErrorDb("Unknown item (entry=%u) in creature_equip_template.equipentry%u for entry = %u, forced to 0.", eqInfo
->equipentry
[j
], j
+1, i
);
795 const_cast<EquipmentInfo
*>(eqInfo
)->equipentry
[j
] = 0;
799 if(dbcitem
->InventoryType
!= INVTYPE_WEAPON
&&
800 dbcitem
->InventoryType
!= INVTYPE_SHIELD
&&
801 dbcitem
->InventoryType
!= INVTYPE_RANGED
&&
802 dbcitem
->InventoryType
!= INVTYPE_2HWEAPON
&&
803 dbcitem
->InventoryType
!= INVTYPE_WEAPONMAINHAND
&&
804 dbcitem
->InventoryType
!= INVTYPE_WEAPONOFFHAND
&&
805 dbcitem
->InventoryType
!= INVTYPE_HOLDABLE
&&
806 dbcitem
->InventoryType
!= INVTYPE_THROWN
&&
807 dbcitem
->InventoryType
!= INVTYPE_RANGEDRIGHT
)
809 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
);
810 const_cast<EquipmentInfo
*>(eqInfo
)->equipentry
[j
] = 0;
814 sLog
.outString( ">> Loaded %u equipment template", sEquipmentStorage
.RecordCount
);
818 CreatureModelInfo
const* ObjectMgr::GetCreatureModelInfo(uint32 modelid
)
820 return sCreatureModelStorage
.LookupEntry
<CreatureModelInfo
>(modelid
);
823 uint32
ObjectMgr::ChooseDisplayId(uint32 team
, const CreatureInfo
*cinfo
, const CreatureData
*data
)
825 // Load creature model (display id)
827 if (!data
|| data
->displayid
== 0) // use defaults from the template
829 // DisplayID_A is used if no team is given
831 display_id
= (cinfo
->DisplayID_H2
!= 0 && urand(0,1) == 0) ? cinfo
->DisplayID_H2
: cinfo
->DisplayID_H
;
833 display_id
= (cinfo
->DisplayID_A2
!= 0 && urand(0,1) == 0) ? cinfo
->DisplayID_A2
: cinfo
->DisplayID_A
;
835 else // overridden in creature data
836 display_id
= data
->displayid
;
841 CreatureModelInfo
const* ObjectMgr::GetCreatureModelRandomGender(uint32 display_id
)
843 CreatureModelInfo
const *minfo
= GetCreatureModelInfo(display_id
);
847 // If a model for another gender exists, 50% chance to use it
848 if(minfo
->modelid_other_gender
!= 0 && urand(0,1) == 0)
850 CreatureModelInfo
const *minfo_tmp
= GetCreatureModelInfo(minfo
->modelid_other_gender
);
853 sLog
.outErrorDb("Model (Entry: %u) has modelid_other_gender %u not found in table `creature_model_info`. ", minfo
->modelid
, minfo
->modelid_other_gender
);
854 return minfo
; // not fatal, just use the previous one
863 void ObjectMgr::LoadCreatureModelInfo()
865 sCreatureModelStorage
.Load();
867 sLog
.outString( ">> Loaded %u creature model based info", sCreatureModelStorage
.RecordCount
);
871 void ObjectMgr::LoadCreatures()
875 QueryResult
*result
= WorldDatabase
.Query("SELECT creature.guid, id, map, modelid,"
877 "equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint,"
878 // 12 13 14 15 16 17 18 19
879 "curhealth, curmana, DeathState, MovementType, spawnMask, phaseMask, event, pool_entry "
880 "FROM creature LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid "
881 "LEFT OUTER JOIN pool_creature ON creature.guid = pool_creature.guid");
890 sLog
.outErrorDb(">> Loaded 0 creature. DB table `creature` is empty.");
894 // build single time for check creature data
895 std::set
<uint32
> heroicCreatures
;
896 for(uint32 i
= 0; i
< sCreatureStorage
.MaxEntry
; ++i
)
897 if(CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
>(i
))
898 if(cInfo
->HeroicEntry
)
899 heroicCreatures
.insert(cInfo
->HeroicEntry
);
901 barGoLink
bar(result
->GetRowCount());
905 Field
*fields
= result
->Fetch();
908 uint32 guid
= fields
[ 0].GetUInt32();
909 uint32 entry
= fields
[ 1].GetUInt32();
911 CreatureInfo
const* cInfo
= GetCreatureTemplate(entry
);
914 sLog
.outErrorDb("Table `creature` has creature (GUID: %u) with non existing creature entry %u, skipped.", guid
, entry
);
918 CreatureData
& data
= mCreatureDataMap
[guid
];
921 data
.mapid
= fields
[ 2].GetUInt32();
922 data
.displayid
= fields
[ 3].GetUInt32();
923 data
.equipmentId
= fields
[ 4].GetUInt32();
924 data
.posX
= fields
[ 5].GetFloat();
925 data
.posY
= fields
[ 6].GetFloat();
926 data
.posZ
= fields
[ 7].GetFloat();
927 data
.orientation
= fields
[ 8].GetFloat();
928 data
.spawntimesecs
= fields
[ 9].GetUInt32();
929 data
.spawndist
= fields
[10].GetFloat();
930 data
.currentwaypoint
= fields
[11].GetUInt32();
931 data
.curhealth
= fields
[12].GetUInt32();
932 data
.curmana
= fields
[13].GetUInt32();
933 data
.is_dead
= fields
[14].GetBool();
934 data
.movementType
= fields
[15].GetUInt8();
935 data
.spawnMask
= fields
[16].GetUInt8();
936 data
.phaseMask
= fields
[17].GetUInt16();
937 int16 gameEvent
= fields
[18].GetInt16();
938 int16 PoolId
= fields
[19].GetInt16();
940 if(heroicCreatures
.find(data
.id
)!=heroicCreatures
.end())
942 sLog
.outErrorDb("Table `creature` have creature (GUID: %u) that listed as heroic template in `creature_template`, skipped.",guid
,data
.id
);
946 if(data
.equipmentId
> 0) // -1 no equipment, 0 use default
948 if(!GetEquipmentInfo(data
.equipmentId
))
950 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
);
951 data
.equipmentId
= -1;
955 if(cInfo
->RegenHealth
&& data
.curhealth
< cInfo
->minhealth
)
957 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
);
958 data
.curhealth
= cInfo
->minhealth
;
961 if(cInfo
->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
963 MapEntry
const* map
= sMapStore
.LookupEntry(data
.mapid
);
964 if(!map
|| !map
->IsDungeon())
965 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
);
968 if(data
.curmana
< cInfo
->minmana
)
970 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
);
971 data
.curmana
= cInfo
->minmana
;
974 if(data
.spawndist
< 0.0f
)
976 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `spawndist`< 0, set to 0.",guid
,data
.id
);
977 data
.spawndist
= 0.0f
;
979 else if(data
.movementType
== RANDOM_MOTION_TYPE
)
981 if(data
.spawndist
== 0.0f
)
983 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
);
984 data
.movementType
= IDLE_MOTION_TYPE
;
987 else if(data
.movementType
== IDLE_MOTION_TYPE
)
989 if(data
.spawndist
!= 0.0f
)
991 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `MovementType`=0 (idle) have `spawndist`<>0, set to 0.",guid
,data
.id
);
992 data
.spawndist
= 0.0f
;
996 if(data
.phaseMask
==0)
998 sLog
.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `phaseMask`=0 (not visible for anyone), set to 1.",guid
,data
.id
);
1002 if (gameEvent
==0 && PoolId
==0) // if not this is to be managed by GameEvent System or Pool system
1003 AddCreatureToGrid(guid
, &data
);
1007 } while (result
->NextRow());
1012 sLog
.outString( ">> Loaded %lu creatures", (unsigned long)mCreatureDataMap
.size() );
1015 void ObjectMgr::AddCreatureToGrid(uint32 guid
, CreatureData
const* data
)
1017 uint8 mask
= data
->spawnMask
;
1018 for(uint8 i
= 0; mask
!= 0; i
++, mask
>>= 1)
1022 CellPair cell_pair
= MaNGOS::ComputeCellPair(data
->posX
, data
->posY
);
1023 uint32 cell_id
= (cell_pair
.y_coord
*TOTAL_NUMBER_OF_CELLS_PER_MAP
) + cell_pair
.x_coord
;
1025 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(data
->mapid
,i
)][cell_id
];
1026 cell_guids
.creatures
.insert(guid
);
1031 void ObjectMgr::RemoveCreatureFromGrid(uint32 guid
, CreatureData
const* data
)
1033 uint8 mask
= data
->spawnMask
;
1034 for(uint8 i
= 0; mask
!= 0; i
++, mask
>>= 1)
1038 CellPair cell_pair
= MaNGOS::ComputeCellPair(data
->posX
, data
->posY
);
1039 uint32 cell_id
= (cell_pair
.y_coord
*TOTAL_NUMBER_OF_CELLS_PER_MAP
) + cell_pair
.x_coord
;
1041 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(data
->mapid
,i
)][cell_id
];
1042 cell_guids
.creatures
.erase(guid
);
1047 void ObjectMgr::LoadGameobjects()
1052 QueryResult
*result
= WorldDatabase
.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
1053 // 7 8 9 10 11 12 13 14 15 16 17
1054 "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, event, pool_entry "
1055 "FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid "
1056 "LEFT OUTER JOIN pool_gameobject ON gameobject.guid = pool_gameobject.guid");
1065 sLog
.outErrorDb(">> Loaded 0 gameobjects. DB table `gameobject` is empty.");
1069 barGoLink
bar(result
->GetRowCount());
1073 Field
*fields
= result
->Fetch();
1076 uint32 guid
= fields
[ 0].GetUInt32();
1077 uint32 entry
= fields
[ 1].GetUInt32();
1079 GameObjectInfo
const* gInfo
= GetGameObjectInfo(entry
);
1082 sLog
.outErrorDb("Table `gameobject` has gameobject (GUID: %u) with non existing gameobject entry %u, skipped.", guid
, entry
);
1086 GameObjectData
& data
= mGameObjectDataMap
[guid
];
1089 data
.mapid
= fields
[ 2].GetUInt32();
1090 data
.posX
= fields
[ 3].GetFloat();
1091 data
.posY
= fields
[ 4].GetFloat();
1092 data
.posZ
= fields
[ 5].GetFloat();
1093 data
.orientation
= fields
[ 6].GetFloat();
1094 data
.rotation0
= fields
[ 7].GetFloat();
1095 data
.rotation1
= fields
[ 8].GetFloat();
1096 data
.rotation2
= fields
[ 9].GetFloat();
1097 data
.rotation3
= fields
[10].GetFloat();
1098 data
.spawntimesecs
= fields
[11].GetInt32();
1099 data
.animprogress
= fields
[12].GetUInt32();
1101 uint32 go_state
= fields
[13].GetUInt32();
1102 if (go_state
>= MAX_GO_STATE
)
1104 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid `state` (%u) value, skip",guid
,data
.id
,go_state
);
1107 data
.go_state
= GOState(go_state
);
1109 data
.spawnMask
= fields
[14].GetUInt8();
1110 data
.phaseMask
= fields
[15].GetUInt16();
1111 int16 gameEvent
= fields
[16].GetInt16();
1112 int16 PoolId
= fields
[17].GetInt16();
1114 if(data
.rotation2
< -1.0f
|| data
.rotation2
> 1.0f
)
1116 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation2 (%f) value, skip",guid
,data
.id
,data
.rotation2
);
1120 if(data
.rotation3
< -1.0f
|| data
.rotation3
> 1.0f
)
1122 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation3 (%f) value, skip",guid
,data
.id
,data
.rotation3
);
1126 if(!MapManager::IsValidMapCoord(data
.mapid
,data
.posX
,data
.posY
,data
.posZ
,data
.orientation
))
1128 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid coordinates, skip",guid
,data
.id
);
1132 if(data
.phaseMask
==0)
1134 sLog
.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with `phaseMask`=0 (not visible for anyone), set to 1.",guid
,data
.id
);
1138 if (gameEvent
==0 && PoolId
==0) // if not this is to be managed by GameEvent System or Pool system
1139 AddGameobjectToGrid(guid
, &data
);
1142 } while (result
->NextRow());
1147 sLog
.outString( ">> Loaded %lu gameobjects", (unsigned long)mGameObjectDataMap
.size());
1150 void ObjectMgr::AddGameobjectToGrid(uint32 guid
, GameObjectData
const* data
)
1152 uint8 mask
= data
->spawnMask
;
1153 for(uint8 i
= 0; mask
!= 0; i
++, mask
>>= 1)
1157 CellPair cell_pair
= MaNGOS::ComputeCellPair(data
->posX
, data
->posY
);
1158 uint32 cell_id
= (cell_pair
.y_coord
*TOTAL_NUMBER_OF_CELLS_PER_MAP
) + cell_pair
.x_coord
;
1160 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(data
->mapid
,i
)][cell_id
];
1161 cell_guids
.gameobjects
.insert(guid
);
1166 void ObjectMgr::RemoveGameobjectFromGrid(uint32 guid
, GameObjectData
const* data
)
1168 uint8 mask
= data
->spawnMask
;
1169 for(uint8 i
= 0; mask
!= 0; i
++, mask
>>= 1)
1173 CellPair cell_pair
= MaNGOS::ComputeCellPair(data
->posX
, data
->posY
);
1174 uint32 cell_id
= (cell_pair
.y_coord
*TOTAL_NUMBER_OF_CELLS_PER_MAP
) + cell_pair
.x_coord
;
1176 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(data
->mapid
,i
)][cell_id
];
1177 cell_guids
.gameobjects
.erase(guid
);
1182 void ObjectMgr::LoadCreatureRespawnTimes()
1184 // remove outdated data
1185 WorldDatabase
.DirectExecute("DELETE FROM creature_respawn WHERE respawntime <= UNIX_TIMESTAMP(NOW())");
1189 QueryResult
*result
= WorldDatabase
.Query("SELECT guid,respawntime,instance FROM creature_respawn");
1198 sLog
.outString(">> Loaded 0 creature respawn time.");
1202 barGoLink
bar(result
->GetRowCount());
1206 Field
*fields
= result
->Fetch();
1209 uint32 loguid
= fields
[0].GetUInt32();
1210 uint64 respawn_time
= fields
[1].GetUInt64();
1211 uint32 instance
= fields
[2].GetUInt32();
1213 mCreatureRespawnTimes
[MAKE_PAIR64(loguid
,instance
)] = time_t(respawn_time
);
1216 } while (result
->NextRow());
1220 sLog
.outString( ">> Loaded %lu creature respawn times", (unsigned long)mCreatureRespawnTimes
.size() );
1224 void ObjectMgr::LoadGameobjectRespawnTimes()
1226 // remove outdated data
1227 WorldDatabase
.DirectExecute("DELETE FROM gameobject_respawn WHERE respawntime <= UNIX_TIMESTAMP(NOW())");
1231 QueryResult
*result
= WorldDatabase
.Query("SELECT guid,respawntime,instance FROM gameobject_respawn");
1240 sLog
.outString(">> Loaded 0 gameobject respawn time.");
1244 barGoLink
bar(result
->GetRowCount());
1248 Field
*fields
= result
->Fetch();
1251 uint32 loguid
= fields
[0].GetUInt32();
1252 uint64 respawn_time
= fields
[1].GetUInt64();
1253 uint32 instance
= fields
[2].GetUInt32();
1255 mGORespawnTimes
[MAKE_PAIR64(loguid
,instance
)] = time_t(respawn_time
);
1258 } while (result
->NextRow());
1262 sLog
.outString( ">> Loaded %lu gameobject respawn times", (unsigned long)mGORespawnTimes
.size() );
1266 // name must be checked to correctness (if received) before call this function
1267 uint64
ObjectMgr::GetPlayerGUIDByName(std::string name
) const
1271 CharacterDatabase
.escape_string(name
);
1273 // Player name safe to sending to DB (checked at login) and this function using
1274 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT guid FROM characters WHERE name = '%s'", name
.c_str());
1277 guid
= MAKE_NEW_GUID((*result
)[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
1285 bool ObjectMgr::GetPlayerNameByGUID(const uint64
&guid
, std::string
&name
) const
1287 // prevent DB access for online player
1288 if(Player
* player
= GetPlayer(guid
))
1290 name
= player
->GetName();
1294 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT name FROM characters WHERE guid = '%u'", GUID_LOPART(guid
));
1298 name
= (*result
)[0].GetCppString();
1306 uint32
ObjectMgr::GetPlayerTeamByGUID(const uint64
&guid
) const
1308 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT race FROM characters WHERE guid = '%u'", GUID_LOPART(guid
));
1312 uint8 race
= (*result
)[0].GetUInt8();
1314 return Player::TeamForRace(race
);
1320 uint32
ObjectMgr::GetPlayerAccountIdByGUID(const uint64
&guid
) const
1322 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE guid = '%u'", GUID_LOPART(guid
));
1325 uint32 acc
= (*result
)[0].GetUInt32();
1333 uint32
ObjectMgr::GetPlayerAccountIdByPlayerName(const std::string
& name
) const
1335 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name = '%s'", name
.c_str());
1338 uint32 acc
= (*result
)[0].GetUInt32();
1346 void ObjectMgr::LoadItemLocales()
1348 mItemLocaleMap
.clear(); // need for reload case
1350 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");
1359 sLog
.outString(">> Loaded 0 Item locale strings. DB table `locales_item` is empty.");
1363 barGoLink
bar(result
->GetRowCount());
1367 Field
*fields
= result
->Fetch();
1370 uint32 entry
= fields
[0].GetUInt32();
1372 ItemLocale
& data
= mItemLocaleMap
[entry
];
1374 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
1376 std::string str
= fields
[1+2*(i
-1)].GetCppString();
1379 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
1382 if(data
.Name
.size() <= idx
)
1383 data
.Name
.resize(idx
+1);
1385 data
.Name
[idx
] = str
;
1389 str
= fields
[1+2*(i
-1)+1].GetCppString();
1392 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
1395 if(data
.Description
.size() <= idx
)
1396 data
.Description
.resize(idx
+1);
1398 data
.Description
[idx
] = str
;
1402 } while (result
->NextRow());
1407 sLog
.outString( ">> Loaded %lu Item locale strings", (unsigned long)mItemLocaleMap
.size() );
1410 struct SQLItemLoader
: public SQLStorageLoaderBase
<SQLItemLoader
>
1413 void convert_from_str(uint32
/*field_pos*/, char *src
, D
&dst
)
1415 dst
= D(objmgr
.GetScriptId(src
));
1419 void ObjectMgr::LoadItemPrototypes()
1421 SQLItemLoader loader
;
1422 loader
.Load(sItemStorage
);
1423 sLog
.outString( ">> Loaded %u item prototypes", sItemStorage
.RecordCount
);
1426 // check data correctness
1427 for(uint32 i
= 1; i
< sItemStorage
.MaxEntry
; ++i
)
1429 ItemPrototype
const* proto
= sItemStorage
.LookupEntry
<ItemPrototype
>(i
);
1430 ItemEntry
const *dbcitem
= sItemStore
.LookupEntry(i
);
1433 /* to many errors, and possible not all items really used in game
1435 sLog.outErrorDb("Item (Entry: %u) doesn't exists in DB, but must exist.",i);
1442 if(proto
->Class
!= dbcitem
->Class
)
1444 sLog
.outErrorDb("Item (Entry: %u) not correct class %u, must be %u (still using DB value).",i
,proto
->Class
,dbcitem
->Class
);
1445 // It safe let use Class from DB
1447 /* disabled: have some strange wrong cases for Subclass values.
1448 for enable also uncomment Subclass field in ItemEntry structure and in Itemfmt[]
1449 if(proto->SubClass != dbcitem->SubClass)
1451 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);
1452 // It safe let use Subclass from DB
1456 if(proto
->Unk0
!= dbcitem
->Unk0
)
1458 sLog
.outErrorDb("Item (Entry: %u) not correct %i Unk0, must be %i (still using DB value).",i
,proto
->Unk0
,dbcitem
->Unk0
);
1459 // It safe let use Unk0 from DB
1462 if(proto
->Material
!= dbcitem
->Material
)
1464 sLog
.outErrorDb("Item (Entry: %u) not correct %i material, must be %i (still using DB value).",i
,proto
->Material
,dbcitem
->Material
);
1465 // It safe let use Material from DB
1468 if(proto
->InventoryType
!= dbcitem
->InventoryType
)
1470 sLog
.outErrorDb("Item (Entry: %u) not correct %u inventory type, must be %u (still using DB value).",i
,proto
->InventoryType
,dbcitem
->InventoryType
);
1471 // It safe let use InventoryType from DB
1474 if(proto
->DisplayInfoID
!= dbcitem
->DisplayId
)
1476 sLog
.outErrorDb("Item (Entry: %u) not correct %u display id, must be %u (using it).",i
,proto
->DisplayInfoID
,dbcitem
->DisplayId
);
1477 const_cast<ItemPrototype
*>(proto
)->DisplayInfoID
= dbcitem
->DisplayId
;
1479 if(proto
->Sheath
!= dbcitem
->Sheath
)
1481 sLog
.outErrorDb("Item (Entry: %u) not correct %u sheath, must be %u (using it).",i
,proto
->Sheath
,dbcitem
->Sheath
);
1482 const_cast<ItemPrototype
*>(proto
)->Sheath
= dbcitem
->Sheath
;
1487 sLog
.outErrorDb("Item (Entry: %u) not correct (not listed in list of existed items).",i
);
1490 if(proto
->Class
>= MAX_ITEM_CLASS
)
1492 sLog
.outErrorDb("Item (Entry: %u) has wrong Class value (%u)",i
,proto
->Class
);
1493 const_cast<ItemPrototype
*>(proto
)->Class
= ITEM_CLASS_MISC
;
1496 if(proto
->SubClass
>= MaxItemSubclassValues
[proto
->Class
])
1498 sLog
.outErrorDb("Item (Entry: %u) has wrong Subclass value (%u) for class %u",i
,proto
->SubClass
,proto
->Class
);
1499 const_cast<ItemPrototype
*>(proto
)->SubClass
= 0;// exist for all item classes
1502 if(proto
->Quality
>= MAX_ITEM_QUALITY
)
1504 sLog
.outErrorDb("Item (Entry: %u) has wrong Quality value (%u)",i
,proto
->Quality
);
1505 const_cast<ItemPrototype
*>(proto
)->Quality
= ITEM_QUALITY_NORMAL
;
1508 if(proto
->BuyCount
<= 0)
1510 sLog
.outErrorDb("Item (Entry: %u) has wrong BuyCount value (%u), set to default(1).",i
,proto
->BuyCount
);
1511 const_cast<ItemPrototype
*>(proto
)->BuyCount
= 1;
1514 if(proto
->InventoryType
>= MAX_INVTYPE
)
1516 sLog
.outErrorDb("Item (Entry: %u) has wrong InventoryType value (%u)",i
,proto
->InventoryType
);
1517 const_cast<ItemPrototype
*>(proto
)->InventoryType
= INVTYPE_NON_EQUIP
;
1520 if(proto
->RequiredSkill
>= MAX_SKILL_TYPE
)
1522 sLog
.outErrorDb("Item (Entry: %u) has wrong RequiredSkill value (%u)",i
,proto
->RequiredSkill
);
1523 const_cast<ItemPrototype
*>(proto
)->RequiredSkill
= 0;
1528 // can be used in equip slot, as page read use in inventory, or spell casting at use
1529 bool req
= proto
->InventoryType
!=INVTYPE_NON_EQUIP
|| proto
->PageText
;
1532 for (int j
= 0; j
< MAX_ITEM_PROTO_SPELLS
; ++j
)
1534 if(proto
->Spells
[j
].SpellId
)
1544 if(!(proto
->AllowableClass
& CLASSMASK_ALL_PLAYABLE
))
1545 sLog
.outErrorDb("Item (Entry: %u) not have in `AllowableClass` any playable classes (%u) and can't be equipped or use.",i
,proto
->AllowableClass
);
1547 if(!(proto
->AllowableRace
& RACEMASK_ALL_PLAYABLE
))
1548 sLog
.outErrorDb("Item (Entry: %u) not have in `AllowableRace` any playable races (%u) and can't be equipped or use.",i
,proto
->AllowableRace
);
1552 if(proto
->RequiredSpell
&& !sSpellStore
.LookupEntry(proto
->RequiredSpell
))
1554 sLog
.outErrorDb("Item (Entry: %u) have wrong (non-existed) spell in RequiredSpell (%u)",i
,proto
->RequiredSpell
);
1555 const_cast<ItemPrototype
*>(proto
)->RequiredSpell
= 0;
1558 if(proto
->RequiredReputationRank
>= MAX_REPUTATION_RANK
)
1559 sLog
.outErrorDb("Item (Entry: %u) has wrong reputation rank in RequiredReputationRank (%u), item can't be used.",i
,proto
->RequiredReputationRank
);
1561 if(proto
->RequiredReputationFaction
)
1563 if(!sFactionStore
.LookupEntry(proto
->RequiredReputationFaction
))
1565 sLog
.outErrorDb("Item (Entry: %u) has wrong (not existing) faction in RequiredReputationFaction (%u)",i
,proto
->RequiredReputationFaction
);
1566 const_cast<ItemPrototype
*>(proto
)->RequiredReputationFaction
= 0;
1569 if(proto
->RequiredReputationRank
== MIN_REPUTATION_RANK
)
1570 sLog
.outErrorDb("Item (Entry: %u) has min. reputation rank in RequiredReputationRank (0) but RequiredReputationFaction > 0, faction setting is useless.",i
);
1572 else if(proto
->RequiredReputationRank
> MIN_REPUTATION_RANK
)
1573 sLog
.outErrorDb("Item (Entry: %u) has RequiredReputationFaction ==0 but RequiredReputationRank > 0, rank setting is useless.",i
);
1575 if(proto
->MaxCount
< -1)
1577 sLog
.outErrorDb("Item (Entry: %u) has too large negative in maxcount (%i), replace by value (-1) no storing limits.",i
,proto
->MaxCount
);
1578 const_cast<ItemPrototype
*>(proto
)->MaxCount
= -1;
1581 if(proto
->Stackable
==0)
1583 sLog
.outErrorDb("Item (Entry: %u) has wrong value in stackable (%i), replace by default 1.",i
,proto
->Stackable
);
1584 const_cast<ItemPrototype
*>(proto
)->Stackable
= 1;
1586 else if(proto
->Stackable
< -1)
1588 sLog
.outErrorDb("Item (Entry: %u) has too large negative in stackable (%i), replace by value (-1) no stacking limits.",i
,proto
->Stackable
);
1589 const_cast<ItemPrototype
*>(proto
)->Stackable
= -1;
1591 else if(proto
->Stackable
> 255)
1593 sLog
.outErrorDb("Item (Entry: %u) has too large value in stackable (%u), replace by hardcoded upper limit (255).",i
,proto
->Stackable
);
1594 const_cast<ItemPrototype
*>(proto
)->Stackable
= 255;
1597 if(proto
->StatsCount
> MAX_ITEM_PROTO_STATS
)
1599 sLog
.outErrorDb("Item (Entry: %u) has too large value in statscount (%u), replace by hardcoded limit (%u).",i
,proto
->StatsCount
,MAX_ITEM_PROTO_STATS
);
1600 const_cast<ItemPrototype
*>(proto
)->StatsCount
= MAX_ITEM_PROTO_STATS
;
1603 for (int j
= 0; j
< MAX_ITEM_PROTO_STATS
; ++j
)
1605 // for ItemStatValue != 0
1606 if(proto
->ItemStat
[j
].ItemStatValue
&& proto
->ItemStat
[j
].ItemStatType
>= MAX_ITEM_MOD
)
1608 sLog
.outErrorDb("Item (Entry: %u) has wrong stat_type%d (%u)",i
,j
+1,proto
->ItemStat
[j
].ItemStatType
);
1609 const_cast<ItemPrototype
*>(proto
)->ItemStat
[j
].ItemStatType
= 0;
1613 for (int j
= 0; j
< MAX_ITEM_PROTO_DAMAGES
; ++j
)
1615 if(proto
->Damage
[j
].DamageType
>= MAX_SPELL_SCHOOL
)
1617 sLog
.outErrorDb("Item (Entry: %u) has wrong dmg_type%d (%u)",i
,j
+1,proto
->Damage
[j
].DamageType
);
1618 const_cast<ItemPrototype
*>(proto
)->Damage
[j
].DamageType
= 0;
1623 if((proto
->Spells
[0].SpellId
== SPELL_ID_GENERIC_LEARN
) || (proto
->Spells
[0].SpellId
== SPELL_ID_GENERIC_LEARN_PET
))
1626 if(proto
->Spells
[0].SpellTrigger
!= ITEM_SPELLTRIGGER_ON_USE
)
1628 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
);
1629 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1630 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1631 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellId
= 0;
1632 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1635 // spell_2 have learning spell
1636 if(proto
->Spells
[1].SpellTrigger
!= ITEM_SPELLTRIGGER_LEARN_SPELL_ID
)
1638 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
);
1639 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1640 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellId
= 0;
1641 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1643 else if(!proto
->Spells
[1].SpellId
)
1645 sLog
.outErrorDb("Item (Entry: %u) not has expected spell in spellid_%d in special learning format.",i
,1+1);
1646 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1647 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1651 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(proto
->Spells
[1].SpellId
);
1654 sLog
.outErrorDb("Item (Entry: %u) has wrong (not existing) spell in spellid_%d (%u)",i
,1+1,proto
->Spells
[1].SpellId
);
1655 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1656 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellId
= 0;
1657 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1659 // allowed only in special format
1660 else if((proto
->Spells
[1].SpellId
==SPELL_ID_GENERIC_LEARN
) || (proto
->Spells
[1].SpellId
==SPELL_ID_GENERIC_LEARN_PET
))
1662 sLog
.outErrorDb("Item (Entry: %u) has broken spell in spellid_%d (%u)",i
,1+1,proto
->Spells
[1].SpellId
);
1663 const_cast<ItemPrototype
*>(proto
)->Spells
[0].SpellId
= 0;
1664 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellId
= 0;
1665 const_cast<ItemPrototype
*>(proto
)->Spells
[1].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1669 // spell_3*,spell_4*,spell_5* is empty
1670 for (int j
= 2; j
< MAX_ITEM_PROTO_SPELLS
; ++j
)
1672 if(proto
->Spells
[j
].SpellTrigger
!= ITEM_SPELLTRIGGER_ON_USE
)
1674 sLog
.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u)",i
,j
+1,proto
->Spells
[j
].SpellTrigger
);
1675 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1676 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1678 else if(proto
->Spells
[j
].SpellId
!= 0)
1680 sLog
.outErrorDb("Item (Entry: %u) has wrong spell in spellid_%d (%u) for learning special format",i
,j
+1,proto
->Spells
[j
].SpellId
);
1681 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1685 // normal spell list
1688 for (int j
= 0; j
< MAX_ITEM_PROTO_SPELLS
; ++j
)
1690 if(proto
->Spells
[j
].SpellTrigger
>= MAX_ITEM_SPELLTRIGGER
|| proto
->Spells
[j
].SpellTrigger
== ITEM_SPELLTRIGGER_LEARN_SPELL_ID
)
1692 sLog
.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u)",i
,j
+1,proto
->Spells
[j
].SpellTrigger
);
1693 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1694 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellTrigger
= ITEM_SPELLTRIGGER_ON_USE
;
1697 if(proto
->Spells
[j
].SpellId
)
1699 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(proto
->Spells
[j
].SpellId
);
1702 sLog
.outErrorDb("Item (Entry: %u) has wrong (not existing) spell in spellid_%d (%u)",i
,j
+1,proto
->Spells
[j
].SpellId
);
1703 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1705 // allowed only in special format
1706 else if((proto
->Spells
[j
].SpellId
==SPELL_ID_GENERIC_LEARN
) || (proto
->Spells
[j
].SpellId
==SPELL_ID_GENERIC_LEARN_PET
))
1708 sLog
.outErrorDb("Item (Entry: %u) has broken spell in spellid_%d (%u)",i
,j
+1,proto
->Spells
[j
].SpellId
);
1709 const_cast<ItemPrototype
*>(proto
)->Spells
[j
].SpellId
= 0;
1715 if(proto
->Bonding
>= MAX_BIND_TYPE
)
1716 sLog
.outErrorDb("Item (Entry: %u) has wrong Bonding value (%u)",i
,proto
->Bonding
);
1718 if(proto
->PageText
&& !sPageTextStore
.LookupEntry
<PageText
>(proto
->PageText
))
1719 sLog
.outErrorDb("Item (Entry: %u) has non existing first page (Id:%u)", i
,proto
->PageText
);
1721 if(proto
->LockID
&& !sLockStore
.LookupEntry(proto
->LockID
))
1722 sLog
.outErrorDb("Item (Entry: %u) has wrong LockID (%u)",i
,proto
->LockID
);
1724 if(proto
->Sheath
>= MAX_SHEATHETYPE
)
1726 sLog
.outErrorDb("Item (Entry: %u) has wrong Sheath (%u)",i
,proto
->Sheath
);
1727 const_cast<ItemPrototype
*>(proto
)->Sheath
= SHEATHETYPE_NONE
;
1730 if(proto
->RandomProperty
&& !sItemRandomPropertiesStore
.LookupEntry(GetItemEnchantMod(proto
->RandomProperty
)))
1732 sLog
.outErrorDb("Item (Entry: %u) has unknown (wrong or not listed in `item_enchantment_template`) RandomProperty (%u)",i
,proto
->RandomProperty
);
1733 const_cast<ItemPrototype
*>(proto
)->RandomProperty
= 0;
1736 if(proto
->RandomSuffix
&& !sItemRandomSuffixStore
.LookupEntry(GetItemEnchantMod(proto
->RandomSuffix
)))
1738 sLog
.outErrorDb("Item (Entry: %u) has wrong RandomSuffix (%u)",i
,proto
->RandomSuffix
);
1739 const_cast<ItemPrototype
*>(proto
)->RandomSuffix
= 0;
1742 if(proto
->ItemSet
&& !sItemSetStore
.LookupEntry(proto
->ItemSet
))
1744 sLog
.outErrorDb("Item (Entry: %u) have wrong ItemSet (%u)",i
,proto
->ItemSet
);
1745 const_cast<ItemPrototype
*>(proto
)->ItemSet
= 0;
1748 if(proto
->Area
&& !GetAreaEntryByAreaID(proto
->Area
))
1749 sLog
.outErrorDb("Item (Entry: %u) has wrong Area (%u)",i
,proto
->Area
);
1751 if(proto
->Map
&& !sMapStore
.LookupEntry(proto
->Map
))
1752 sLog
.outErrorDb("Item (Entry: %u) has wrong Map (%u)",i
,proto
->Map
);
1754 if(proto
->BagFamily
)
1757 for(uint32 j
= 0; j
< sizeof(proto
->BagFamily
)*8; ++j
)
1759 uint32 mask
= 1 << j
;
1760 if((proto
->BagFamily
& mask
)==0)
1763 ItemBagFamilyEntry
const* bf
= sItemBagFamilyStore
.LookupEntry(j
+1);
1766 sLog
.outErrorDb("Item (Entry: %u) has bag family bit set not listed in ItemBagFamily.dbc, remove bit",i
);
1767 const_cast<ItemPrototype
*>(proto
)->BagFamily
&= ~mask
;
1771 if(BAG_FAMILY_MASK_CURRENCY_TOKENS
& mask
)
1773 CurrencyTypesEntry
const* ctEntry
= sCurrencyTypesStore
.LookupEntry(proto
->ItemId
);
1776 sLog
.outErrorDb("Item (Entry: %u) has currency bag family bit set in BagFamily but not listed in CurrencyTypes.dbc, remove bit",i
);
1777 const_cast<ItemPrototype
*>(proto
)->BagFamily
&= ~mask
;
1783 if(proto
->TotemCategory
&& !sTotemCategoryStore
.LookupEntry(proto
->TotemCategory
))
1784 sLog
.outErrorDb("Item (Entry: %u) has wrong TotemCategory (%u)",i
,proto
->TotemCategory
);
1786 for (int j
= 0; j
< MAX_ITEM_PROTO_SOCKETS
; j
++)
1788 if(proto
->Socket
[j
].Color
&& (proto
->Socket
[j
].Color
& SOCKET_COLOR_ALL
) != proto
->Socket
[j
].Color
)
1790 sLog
.outErrorDb("Item (Entry: %u) has wrong socketColor_%d (%u)",i
,j
+1,proto
->Socket
[j
].Color
);
1791 const_cast<ItemPrototype
*>(proto
)->Socket
[j
].Color
= 0;
1795 if(proto
->GemProperties
&& !sGemPropertiesStore
.LookupEntry(proto
->GemProperties
))
1796 sLog
.outErrorDb("Item (Entry: %u) has wrong GemProperties (%u)",i
,proto
->GemProperties
);
1798 if(proto
->FoodType
>= MAX_PET_DIET
)
1800 sLog
.outErrorDb("Item (Entry: %u) has wrong FoodType value (%u)",i
,proto
->FoodType
);
1801 const_cast<ItemPrototype
*>(proto
)->FoodType
= 0;
1804 if(proto
->ItemLimitCategory
&& !sItemLimitCategoryStore
.LookupEntry(proto
->ItemLimitCategory
))
1806 sLog
.outErrorDb("Item (Entry: %u) has wrong LimitCategory value (%u)",i
,proto
->ItemLimitCategory
);
1807 const_cast<ItemPrototype
*>(proto
)->ItemLimitCategory
= 0;
1812 void ObjectMgr::LoadItemRequiredTarget()
1814 m_ItemRequiredTarget
.clear(); // needed for reload case
1818 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,type,targetEntry FROM item_required_target");
1827 sLog
.outErrorDb(">> Loaded 0 ItemRequiredTarget. DB table `item_required_target` is empty.");
1831 barGoLink
bar(result
->GetRowCount());
1835 Field
*fields
= result
->Fetch();
1838 uint32 uiItemId
= fields
[0].GetUInt32();
1839 uint32 uiType
= fields
[1].GetUInt32();
1840 uint32 uiTargetEntry
= fields
[2].GetUInt32();
1842 ItemPrototype
const* pItemProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(uiItemId
);
1846 sLog
.outErrorDb("Table `item_required_target`: Entry %u listed for TargetEntry %u does not exist in `item_template`.",uiItemId
,uiTargetEntry
);
1850 bool bIsItemSpellValid
= false;
1852 for(int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
1854 if (SpellEntry
const* pSpellInfo
= sSpellStore
.LookupEntry(pItemProto
->Spells
[i
].SpellId
))
1856 if (pItemProto
->Spells
[i
].SpellTrigger
== ITEM_SPELLTRIGGER_ON_USE
||
1857 pItemProto
->Spells
[i
].SpellTrigger
== ITEM_SPELLTRIGGER_ON_NO_DELAY_USE
)
1859 SpellScriptTarget::const_iterator lower
= spellmgr
.GetBeginSpellScriptTarget(pSpellInfo
->Id
);
1860 SpellScriptTarget::const_iterator upper
= spellmgr
.GetEndSpellScriptTarget(pSpellInfo
->Id
);
1865 if (pSpellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_DAMAGE
||
1866 pSpellInfo
->EffectImplicitTargetB
[i
] == TARGET_CHAIN_DAMAGE
||
1867 pSpellInfo
->EffectImplicitTargetA
[i
] == TARGET_DUELVSPLAYER
||
1868 pSpellInfo
->EffectImplicitTargetB
[i
] == TARGET_DUELVSPLAYER
)
1870 bIsItemSpellValid
= true;
1877 if (!bIsItemSpellValid
)
1879 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
);
1883 if (!uiType
|| uiType
> MAX_ITEM_REQ_TARGET_TYPE
)
1885 sLog
.outErrorDb("Table `item_required_target`: Type %u for TargetEntry %u is incorrect.",uiType
,uiTargetEntry
);
1891 sLog
.outErrorDb("Table `item_required_target`: TargetEntry == 0 for Type (%u).",uiType
);
1895 if (!sCreatureStorage
.LookupEntry
<CreatureInfo
>(uiTargetEntry
))
1897 sLog
.outErrorDb("Table `item_required_target`: creature template entry %u does not exist.",uiTargetEntry
);
1901 m_ItemRequiredTarget
.insert(ItemRequiredTargetMap::value_type(uiItemId
,ItemRequiredTarget(ItemRequiredTargetType(uiType
),uiTargetEntry
)));
1904 } while (result
->NextRow());
1909 sLog
.outString(">> Loaded %u Item required targets", count
);
1912 void ObjectMgr::LoadPetLevelInfo()
1914 // Loading levels data
1916 // 0 1 2 3 4 5 6 7 8 9
1917 QueryResult
*result
= WorldDatabase
.Query("SELECT creature_entry, level, hp, mana, str, agi, sta, inte, spi, armor FROM pet_levelstats");
1926 sLog
.outString( ">> Loaded %u level pet stats definitions", count
);
1927 sLog
.outErrorDb( "Error loading `pet_levelstats` table or empty table.");
1931 barGoLink
bar( result
->GetRowCount() );
1935 Field
* fields
= result
->Fetch();
1937 uint32 creature_id
= fields
[0].GetUInt32();
1938 if(!sCreatureStorage
.LookupEntry
<CreatureInfo
>(creature_id
))
1940 sLog
.outErrorDb("Wrong creature id %u in `pet_levelstats` table, ignoring.",creature_id
);
1944 uint32 current_level
= fields
[1].GetUInt32();
1945 if(current_level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
1947 if(current_level
> STRONG_MAX_LEVEL
) // hardcoded level maximum
1948 sLog
.outErrorDb("Wrong (> %u) level %u in `pet_levelstats` table, ignoring.",STRONG_MAX_LEVEL
,current_level
);
1951 sLog
.outDetail("Unused (> MaxPlayerLevel in mangosd.conf) level %u in `pet_levelstats` table, ignoring.",current_level
);
1952 ++count
; // make result loading percent "expected" correct in case disabled detail mode for example.
1956 else if(current_level
< 1)
1958 sLog
.outErrorDb("Wrong (<1) level %u in `pet_levelstats` table, ignoring.",current_level
);
1962 PetLevelInfo
*& pInfoMapEntry
= petInfo
[creature_id
];
1964 if(pInfoMapEntry
==NULL
)
1965 pInfoMapEntry
= new PetLevelInfo
[sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)];
1967 // data for level 1 stored in [0] array element, ...
1968 PetLevelInfo
* pLevelInfo
= &pInfoMapEntry
[current_level
-1];
1970 pLevelInfo
->health
= fields
[2].GetUInt16();
1971 pLevelInfo
->mana
= fields
[3].GetUInt16();
1972 pLevelInfo
->armor
= fields
[9].GetUInt16();
1974 for (int i
= 0; i
< MAX_STATS
; i
++)
1976 pLevelInfo
->stats
[i
] = fields
[i
+4].GetUInt16();
1982 while (result
->NextRow());
1987 sLog
.outString( ">> Loaded %u level pet stats definitions", count
);
1990 // Fill gaps and check integrity
1991 for (PetLevelInfoMap::iterator itr
= petInfo
.begin(); itr
!= petInfo
.end(); ++itr
)
1993 PetLevelInfo
* pInfo
= itr
->second
;
1995 // fatal error if no level 1 data
1996 if(!pInfo
|| pInfo
[0].health
== 0 )
1998 sLog
.outErrorDb("Creature %u does not have pet stats data for Level 1!",itr
->first
);
2003 for (uint32 level
= 1; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2005 if(pInfo
[level
].health
== 0)
2007 sLog
.outErrorDb("Creature %u has no data for Level %i pet stats data, using data of Level %i.",itr
->first
,level
+1, level
);
2008 pInfo
[level
] = pInfo
[level
-1];
2014 PetLevelInfo
const* ObjectMgr::GetPetLevelInfo(uint32 creature_id
, uint32 level
) const
2016 if(level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2017 level
= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
);
2019 PetLevelInfoMap::const_iterator itr
= petInfo
.find(creature_id
);
2020 if(itr
== petInfo
.end())
2023 return &itr
->second
[level
-1]; // data for level 1 stored in [0] array element, ...
2026 void ObjectMgr::LoadPlayerInfo()
2028 // Load playercreate
2031 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, map, zone, position_x, position_y, position_z FROM playercreateinfo");
2040 sLog
.outString( ">> Loaded %u player create definitions", count
);
2041 sLog
.outErrorDb( "Error loading `playercreateinfo` table or empty table.");
2045 barGoLink
bar( result
->GetRowCount() );
2049 Field
* fields
= result
->Fetch();
2051 uint32 current_race
= fields
[0].GetUInt32();
2052 uint32 current_class
= fields
[1].GetUInt32();
2053 uint32 mapId
= fields
[2].GetUInt32();
2054 uint32 zoneId
= fields
[3].GetUInt32();
2055 float positionX
= fields
[4].GetFloat();
2056 float positionY
= fields
[5].GetFloat();
2057 float positionZ
= fields
[6].GetFloat();
2059 if(current_race
>= MAX_RACES
)
2061 sLog
.outErrorDb("Wrong race %u in `playercreateinfo` table, ignoring.",current_race
);
2065 ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(current_race
);
2068 sLog
.outErrorDb("Wrong race %u in `playercreateinfo` table, ignoring.",current_race
);
2072 if(current_class
>= MAX_CLASSES
)
2074 sLog
.outErrorDb("Wrong class %u in `playercreateinfo` table, ignoring.",current_class
);
2078 if(!sChrClassesStore
.LookupEntry(current_class
))
2080 sLog
.outErrorDb("Wrong class %u in `playercreateinfo` table, ignoring.",current_class
);
2084 // accept DB data only for valid position (and non instanceable)
2085 if( !MapManager::IsValidMapCoord(mapId
,positionX
,positionY
,positionZ
) )
2087 sLog
.outErrorDb("Wrong home position for class %u race %u pair in `playercreateinfo` table, ignoring.",current_class
,current_race
);
2091 if( sMapStore
.LookupEntry(mapId
)->Instanceable() )
2093 sLog
.outErrorDb("Home position in instanceable map for class %u race %u pair in `playercreateinfo` table, ignoring.",current_class
,current_race
);
2097 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2099 pInfo
->mapId
= mapId
;
2100 pInfo
->zoneId
= zoneId
;
2101 pInfo
->positionX
= positionX
;
2102 pInfo
->positionY
= positionY
;
2103 pInfo
->positionZ
= positionZ
;
2105 pInfo
->displayId_m
= rEntry
->model_m
;
2106 pInfo
->displayId_f
= rEntry
->model_f
;
2111 while (result
->NextRow());
2116 sLog
.outString( ">> Loaded %u player create definitions", count
);
2119 // Load playercreate items
2122 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, itemid, amount FROM playercreateinfo_item");
2133 sLog
.outString( ">> Loaded %u custom player create items", count
);
2137 barGoLink
bar( result
->GetRowCount() );
2141 Field
* fields
= result
->Fetch();
2143 uint32 current_race
= fields
[0].GetUInt32();
2144 if(current_race
>= MAX_RACES
)
2146 sLog
.outErrorDb("Wrong race %u in `playercreateinfo_item` table, ignoring.",current_race
);
2150 uint32 current_class
= fields
[1].GetUInt32();
2151 if(current_class
>= MAX_CLASSES
)
2153 sLog
.outErrorDb("Wrong class %u in `playercreateinfo_item` table, ignoring.",current_class
);
2157 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2159 uint32 item_id
= fields
[2].GetUInt32();
2161 if(!GetItemPrototype(item_id
))
2163 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
);
2167 uint32 amount
= fields
[3].GetUInt32();
2171 sLog
.outErrorDb("Item id %u (class %u race %u) have amount==0 in `playercreateinfo_item` table, ignoring.",item_id
,current_race
,current_class
);
2175 pInfo
->item
.push_back(PlayerCreateInfoItem( item_id
, amount
));
2180 while(result
->NextRow());
2185 sLog
.outString( ">> Loaded %u custom player create items", count
);
2189 // Load playercreate spells
2192 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, Spell FROM playercreateinfo_spell");
2201 sLog
.outString( ">> Loaded %u player create spells", count
);
2202 sLog
.outErrorDb( "Error loading `playercreateinfo_spell` table or empty table.");
2206 barGoLink
bar( result
->GetRowCount() );
2210 Field
* fields
= result
->Fetch();
2212 uint32 current_race
= fields
[0].GetUInt32();
2213 if(current_race
>= MAX_RACES
)
2215 sLog
.outErrorDb("Wrong race %u in `playercreateinfo_spell` table, ignoring.",current_race
);
2219 uint32 current_class
= fields
[1].GetUInt32();
2220 if(current_class
>= MAX_CLASSES
)
2222 sLog
.outErrorDb("Wrong class %u in `playercreateinfo_spell` table, ignoring.",current_class
);
2226 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2227 pInfo
->spell
.push_back(fields
[2].GetUInt32());
2232 while( result
->NextRow() );
2237 sLog
.outString( ">> Loaded %u player create spells", count
);
2241 // Load playercreate actions
2244 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, button, action, type, misc FROM playercreateinfo_action");
2253 sLog
.outString( ">> Loaded %u player create actions", count
);
2254 sLog
.outErrorDb( "Error loading `playercreateinfo_action` table or empty table.");
2258 barGoLink
bar( result
->GetRowCount() );
2262 Field
* fields
= result
->Fetch();
2264 uint32 current_race
= fields
[0].GetUInt32();
2265 if(current_race
>= MAX_RACES
)
2267 sLog
.outErrorDb("Wrong race %u in `playercreateinfo_action` table, ignoring.",current_race
);
2271 uint32 current_class
= fields
[1].GetUInt32();
2272 if(current_class
>= MAX_CLASSES
)
2274 sLog
.outErrorDb("Wrong class %u in `playercreateinfo_action` table, ignoring.",current_class
);
2278 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2279 pInfo
->action
[0].push_back(fields
[2].GetUInt16());
2280 pInfo
->action
[1].push_back(fields
[3].GetUInt16());
2281 pInfo
->action
[2].push_back(fields
[4].GetUInt16());
2282 pInfo
->action
[3].push_back(fields
[5].GetUInt16());
2287 while( result
->NextRow() );
2292 sLog
.outString( ">> Loaded %u player create actions", count
);
2296 // Loading levels data (class only dependent)
2299 QueryResult
*result
= WorldDatabase
.Query("SELECT class, level, basehp, basemana FROM player_classlevelstats");
2308 sLog
.outString( ">> Loaded %u level health/mana definitions", count
);
2309 sLog
.outErrorDb( "Error loading `player_classlevelstats` table or empty table.");
2313 barGoLink
bar( result
->GetRowCount() );
2317 Field
* fields
= result
->Fetch();
2319 uint32 current_class
= fields
[0].GetUInt32();
2320 if(current_class
>= MAX_CLASSES
)
2322 sLog
.outErrorDb("Wrong class %u in `player_classlevelstats` table, ignoring.",current_class
);
2326 uint32 current_level
= fields
[1].GetUInt32();
2327 if(current_level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2329 if(current_level
> STRONG_MAX_LEVEL
) // hardcoded level maximum
2330 sLog
.outErrorDb("Wrong (> %u) level %u in `player_classlevelstats` table, ignoring.",STRONG_MAX_LEVEL
,current_level
);
2333 sLog
.outDetail("Unused (> MaxPlayerLevel in mangosd.conf) level %u in `player_classlevelstats` table, ignoring.",current_level
);
2334 ++count
; // make result loading percent "expected" correct in case disabled detail mode for example.
2339 PlayerClassInfo
* pClassInfo
= &playerClassInfo
[current_class
];
2341 if(!pClassInfo
->levelInfo
)
2342 pClassInfo
->levelInfo
= new PlayerClassLevelInfo
[sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)];
2344 PlayerClassLevelInfo
* pClassLevelInfo
= &pClassInfo
->levelInfo
[current_level
-1];
2346 pClassLevelInfo
->basehealth
= fields
[2].GetUInt16();
2347 pClassLevelInfo
->basemana
= fields
[3].GetUInt16();
2352 while (result
->NextRow());
2357 sLog
.outString( ">> Loaded %u level health/mana definitions", count
);
2360 // Fill gaps and check integrity
2361 for (int class_
= 0; class_
< MAX_CLASSES
; ++class_
)
2363 // skip non existed classes
2364 if(!sChrClassesStore
.LookupEntry(class_
))
2367 PlayerClassInfo
* pClassInfo
= &playerClassInfo
[class_
];
2369 // fatal error if no level 1 data
2370 if(!pClassInfo
->levelInfo
|| pClassInfo
->levelInfo
[0].basehealth
== 0 )
2372 sLog
.outErrorDb("Class %i Level 1 does not have health/mana data!",class_
);
2377 for (uint32 level
= 1; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2379 if(pClassInfo
->levelInfo
[level
].basehealth
== 0)
2381 sLog
.outErrorDb("Class %i Level %i does not have health/mana data. Using stats data of level %i.",class_
,level
+1, level
);
2382 pClassInfo
->levelInfo
[level
] = pClassInfo
->levelInfo
[level
-1];
2387 // Loading levels data (class/race dependent)
2390 QueryResult
*result
= WorldDatabase
.Query("SELECT race, class, level, str, agi, sta, inte, spi FROM player_levelstats");
2399 sLog
.outString( ">> Loaded %u level stats definitions", count
);
2400 sLog
.outErrorDb( "Error loading `player_levelstats` table or empty table.");
2404 barGoLink
bar( result
->GetRowCount() );
2408 Field
* fields
= result
->Fetch();
2410 uint32 current_race
= fields
[0].GetUInt32();
2411 if(current_race
>= MAX_RACES
)
2413 sLog
.outErrorDb("Wrong race %u in `player_levelstats` table, ignoring.",current_race
);
2417 uint32 current_class
= fields
[1].GetUInt32();
2418 if(current_class
>= MAX_CLASSES
)
2420 sLog
.outErrorDb("Wrong class %u in `player_levelstats` table, ignoring.",current_class
);
2424 uint32 current_level
= fields
[2].GetUInt32();
2425 if(current_level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2427 if(current_level
> STRONG_MAX_LEVEL
) // hardcoded level maximum
2428 sLog
.outErrorDb("Wrong (> %u) level %u in `player_levelstats` table, ignoring.",STRONG_MAX_LEVEL
,current_level
);
2431 sLog
.outDetail("Unused (> MaxPlayerLevel in mangosd.conf) level %u in `player_levelstats` table, ignoring.",current_level
);
2432 ++count
; // make result loading percent "expected" correct in case disabled detail mode for example.
2437 PlayerInfo
* pInfo
= &playerInfo
[current_race
][current_class
];
2439 if(!pInfo
->levelInfo
)
2440 pInfo
->levelInfo
= new PlayerLevelInfo
[sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)];
2442 PlayerLevelInfo
* pLevelInfo
= &pInfo
->levelInfo
[current_level
-1];
2444 for (int i
= 0; i
< MAX_STATS
; i
++)
2446 pLevelInfo
->stats
[i
] = fields
[i
+3].GetUInt8();
2452 while (result
->NextRow());
2457 sLog
.outString( ">> Loaded %u level stats definitions", count
);
2460 // Fill gaps and check integrity
2461 for (int race
= 0; race
< MAX_RACES
; ++race
)
2463 // skip non existed races
2464 if(!sChrRacesStore
.LookupEntry(race
))
2467 for (int class_
= 0; class_
< MAX_CLASSES
; ++class_
)
2469 // skip non existed classes
2470 if(!sChrClassesStore
.LookupEntry(class_
))
2473 PlayerInfo
* pInfo
= &playerInfo
[race
][class_
];
2475 // skip non loaded combinations
2476 if(!pInfo
->displayId_m
|| !pInfo
->displayId_f
)
2479 // skip expansion races if not playing with expansion
2480 if (sWorld
.getConfig(CONFIG_EXPANSION
) < 1 && (race
== RACE_BLOODELF
|| race
== RACE_DRAENEI
))
2483 // skip expansion classes if not playing with expansion
2484 if (sWorld
.getConfig(CONFIG_EXPANSION
) < 2 && class_
== CLASS_DEATH_KNIGHT
)
2487 // fatal error if no level 1 data
2488 if(!pInfo
->levelInfo
|| pInfo
->levelInfo
[0].stats
[0] == 0 )
2490 sLog
.outErrorDb("Race %i Class %i Level 1 does not have stats data!",race
,class_
);
2495 for (uint32 level
= 1; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2497 if(pInfo
->levelInfo
[level
].stats
[0] == 0)
2499 sLog
.outErrorDb("Race %i Class %i Level %i does not have stats data. Using stats data of level %i.",race
,class_
,level
+1, level
);
2500 pInfo
->levelInfo
[level
] = pInfo
->levelInfo
[level
-1];
2506 // Loading xp per level data
2508 mPlayerXPperLevel
.resize(sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
));
2509 for (uint32 level
= 0; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2510 mPlayerXPperLevel
[level
] = 0;
2513 QueryResult
*result
= WorldDatabase
.Query("SELECT lvl, xp_for_next_level FROM player_xp_for_level");
2522 sLog
.outString( ">> Loaded %u xp for level definitions", count
);
2523 sLog
.outErrorDb( "Error loading `player_xp_for_level` table or empty table.");
2527 barGoLink
bar( result
->GetRowCount() );
2531 Field
* fields
= result
->Fetch();
2533 uint32 current_level
= fields
[0].GetUInt32();
2534 uint32 current_xp
= fields
[1].GetUInt32();
2536 if(current_level
>= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2538 if(current_level
> STRONG_MAX_LEVEL
) // hardcoded level maximum
2539 sLog
.outErrorDb("Wrong (> %u) level %u in `player_xp_for_level` table, ignoring.", STRONG_MAX_LEVEL
,current_level
);
2542 sLog
.outDetail("Unused (> MaxPlayerLevel in mangosd.conf) level %u in `player_xp_for_levels` table, ignoring.",current_level
);
2543 ++count
; // make result loading percent "expected" correct in case disabled detail mode for example.
2548 mPlayerXPperLevel
[current_level
] = current_xp
;
2552 while (result
->NextRow());
2557 sLog
.outString( ">> Loaded %u xp for level definitions", count
);
2561 for (uint32 level
= 1; level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
); ++level
)
2563 if( mPlayerXPperLevel
[level
] == 0)
2565 sLog
.outErrorDb("Level %i does not have XP for level data. Using data of level [%i] + 100.",level
+1, level
);
2566 mPlayerXPperLevel
[level
] = mPlayerXPperLevel
[level
-1]+100;
2571 void ObjectMgr::GetPlayerClassLevelInfo(uint32 class_
, uint32 level
, PlayerClassLevelInfo
* info
) const
2573 if(level
< 1 || class_
>= MAX_CLASSES
)
2576 PlayerClassInfo
const* pInfo
= &playerClassInfo
[class_
];
2578 if(level
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2579 level
= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
);
2581 *info
= pInfo
->levelInfo
[level
-1];
2584 void ObjectMgr::GetPlayerLevelInfo(uint32 race
, uint32 class_
, uint32 level
, PlayerLevelInfo
* info
) const
2586 if(level
< 1 || race
>= MAX_RACES
|| class_
>= MAX_CLASSES
)
2589 PlayerInfo
const* pInfo
= &playerInfo
[race
][class_
];
2590 if(pInfo
->displayId_m
==0 || pInfo
->displayId_f
==0)
2593 if(level
<= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2594 *info
= pInfo
->levelInfo
[level
-1];
2596 BuildPlayerLevelInfo(race
,class_
,level
,info
);
2599 void ObjectMgr::BuildPlayerLevelInfo(uint8 race
, uint8 _class
, uint8 level
, PlayerLevelInfo
* info
) const
2601 // base data (last known level)
2602 *info
= playerInfo
[race
][_class
].levelInfo
[sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)-1];
2604 for(int lvl
= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
)-1; lvl
< level
; ++lvl
)
2609 info
->stats
[STAT_STRENGTH
] += (lvl
> 23 ? 2: (lvl
> 1 ? 1: 0));
2610 info
->stats
[STAT_STAMINA
] += (lvl
> 23 ? 2: (lvl
> 1 ? 1: 0));
2611 info
->stats
[STAT_AGILITY
] += (lvl
> 36 ? 1: (lvl
> 6 && (lvl
%2) ? 1: 0));
2612 info
->stats
[STAT_INTELLECT
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2613 info
->stats
[STAT_SPIRIT
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2616 info
->stats
[STAT_STRENGTH
] += (lvl
> 3 ? 1: 0);
2617 info
->stats
[STAT_STAMINA
] += (lvl
> 33 ? 2: (lvl
> 1 ? 1: 0));
2618 info
->stats
[STAT_AGILITY
] += (lvl
> 38 ? 1: (lvl
> 7 && !(lvl
%2) ? 1: 0));
2619 info
->stats
[STAT_INTELLECT
] += (lvl
> 6 && (lvl
%2) ? 1: 0);
2620 info
->stats
[STAT_SPIRIT
] += (lvl
> 7 ? 1: 0);
2623 info
->stats
[STAT_STRENGTH
] += (lvl
> 4 ? 1: 0);
2624 info
->stats
[STAT_STAMINA
] += (lvl
> 4 ? 1: 0);
2625 info
->stats
[STAT_AGILITY
] += (lvl
> 33 ? 2: (lvl
> 1 ? 1: 0));
2626 info
->stats
[STAT_INTELLECT
] += (lvl
> 8 && (lvl
%2) ? 1: 0);
2627 info
->stats
[STAT_SPIRIT
] += (lvl
> 38 ? 1: (lvl
> 9 && !(lvl
%2) ? 1: 0));
2630 info
->stats
[STAT_STRENGTH
] += (lvl
> 5 ? 1: 0);
2631 info
->stats
[STAT_STAMINA
] += (lvl
> 4 ? 1: 0);
2632 info
->stats
[STAT_AGILITY
] += (lvl
> 16 ? 2: (lvl
> 1 ? 1: 0));
2633 info
->stats
[STAT_INTELLECT
] += (lvl
> 8 && !(lvl
%2) ? 1: 0);
2634 info
->stats
[STAT_SPIRIT
] += (lvl
> 38 ? 1: (lvl
> 9 && !(lvl
%2) ? 1: 0));
2637 info
->stats
[STAT_STRENGTH
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2638 info
->stats
[STAT_STAMINA
] += (lvl
> 5 ? 1: 0);
2639 info
->stats
[STAT_AGILITY
] += (lvl
> 38 ? 1: (lvl
> 8 && (lvl
%2) ? 1: 0));
2640 info
->stats
[STAT_INTELLECT
] += (lvl
> 22 ? 2: (lvl
> 1 ? 1: 0));
2641 info
->stats
[STAT_SPIRIT
] += (lvl
> 3 ? 1: 0);
2644 info
->stats
[STAT_STRENGTH
] += (lvl
> 34 ? 1: (lvl
> 6 && (lvl
%2) ? 1: 0));
2645 info
->stats
[STAT_STAMINA
] += (lvl
> 4 ? 1: 0);
2646 info
->stats
[STAT_AGILITY
] += (lvl
> 7 && !(lvl
%2) ? 1: 0);
2647 info
->stats
[STAT_INTELLECT
] += (lvl
> 5 ? 1: 0);
2648 info
->stats
[STAT_SPIRIT
] += (lvl
> 4 ? 1: 0);
2651 info
->stats
[STAT_STRENGTH
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2652 info
->stats
[STAT_STAMINA
] += (lvl
> 5 ? 1: 0);
2653 info
->stats
[STAT_AGILITY
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2654 info
->stats
[STAT_INTELLECT
] += (lvl
> 24 ? 2: (lvl
> 1 ? 1: 0));
2655 info
->stats
[STAT_SPIRIT
] += (lvl
> 33 ? 2: (lvl
> 2 ? 1: 0));
2658 info
->stats
[STAT_STRENGTH
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2659 info
->stats
[STAT_STAMINA
] += (lvl
> 38 ? 2: (lvl
> 3 ? 1: 0));
2660 info
->stats
[STAT_AGILITY
] += (lvl
> 9 && !(lvl
%2) ? 1: 0);
2661 info
->stats
[STAT_INTELLECT
] += (lvl
> 33 ? 2: (lvl
> 2 ? 1: 0));
2662 info
->stats
[STAT_SPIRIT
] += (lvl
> 38 ? 2: (lvl
> 3 ? 1: 0));
2665 info
->stats
[STAT_STRENGTH
] += (lvl
> 38 ? 2: (lvl
> 6 && (lvl
%2) ? 1: 0));
2666 info
->stats
[STAT_STAMINA
] += (lvl
> 32 ? 2: (lvl
> 4 ? 1: 0));
2667 info
->stats
[STAT_AGILITY
] += (lvl
> 38 ? 2: (lvl
> 8 && (lvl
%2) ? 1: 0));
2668 info
->stats
[STAT_INTELLECT
] += (lvl
> 38 ? 3: (lvl
> 4 ? 1: 0));
2669 info
->stats
[STAT_SPIRIT
] += (lvl
> 38 ? 3: (lvl
> 5 ? 1: 0));
2674 void ObjectMgr::LoadGuilds()
2679 QueryResult
*result
= CharacterDatabase
.Query( "SELECT guildid FROM guild" );
2689 sLog
.outString( ">> Loaded %u guild definitions", count
);
2693 barGoLink
bar( result
->GetRowCount() );
2697 Field
*fields
= result
->Fetch();
2702 newguild
= new Guild
;
2703 if(!newguild
->LoadGuildFromDB(fields
[0].GetUInt32()))
2705 newguild
->Disband();
2711 }while( result
->NextRow() );
2716 sLog
.outString( ">> Loaded %u guild definitions", count
);
2719 void ObjectMgr::LoadArenaTeams()
2723 QueryResult
*result
= CharacterDatabase
.Query( "SELECT arenateamid FROM arena_team" );
2733 sLog
.outString( ">> Loaded %u arenateam definitions", count
);
2737 barGoLink
bar( result
->GetRowCount() );
2741 Field
*fields
= result
->Fetch();
2746 ArenaTeam
*newarenateam
= new ArenaTeam
;
2747 if(!newarenateam
->LoadArenaTeamFromDB(fields
[0].GetUInt32()))
2749 delete newarenateam
;
2752 AddArenaTeam(newarenateam
);
2753 }while( result
->NextRow() );
2758 sLog
.outString( ">> Loaded %u arenateam definitions", count
);
2761 void ObjectMgr::LoadGroups()
2763 // -- loading groups --
2764 Group
*group
= NULL
;
2765 uint64 leaderGuid
= 0;
2767 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
2768 QueryResult
*result
= CharacterDatabase
.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, leaderGuid FROM groups");
2777 sLog
.outString( ">> Loaded %u group definitions", count
);
2781 barGoLink
bar( result
->GetRowCount() );
2786 Field
*fields
= result
->Fetch();
2788 leaderGuid
= MAKE_NEW_GUID(fields
[15].GetUInt32(),0,HIGHGUID_PLAYER
);
2791 if(!group
->LoadGroupFromDB(leaderGuid
, result
, false))
2798 }while( result
->NextRow() );
2803 sLog
.outString( ">> Loaded %u group definitions", count
);
2805 // -- loading members --
2810 result
= CharacterDatabase
.Query("SELECT memberGuid, assistant, subgroup, leaderGuid FROM group_member ORDER BY leaderGuid");
2813 barGoLink
bar2( 1 );
2818 barGoLink
bar2( result
->GetRowCount() );
2822 Field
*fields
= result
->Fetch();
2824 leaderGuid
= MAKE_NEW_GUID(fields
[3].GetUInt32(), 0, HIGHGUID_PLAYER
);
2825 if(!group
|| group
->GetLeaderGUID() != leaderGuid
)
2827 group
= GetGroupByLeader(leaderGuid
);
2830 sLog
.outErrorDb("Incorrect entry in group_member table : no group with leader %d for member %d!", fields
[3].GetUInt32(), fields
[0].GetUInt32());
2831 CharacterDatabase
.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", fields
[0].GetUInt32());
2836 if(!group
->LoadMemberFromDB(fields
[0].GetUInt32(), fields
[2].GetUInt8(), fields
[1].GetBool()))
2838 sLog
.outErrorDb("Incorrect entry in group_member table : member %d cannot be added to player %d's group!", fields
[0].GetUInt32(), fields
[3].GetUInt32());
2839 CharacterDatabase
.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", fields
[0].GetUInt32());
2841 }while( result
->NextRow() );
2846 // TODO: maybe delete from the DB before loading in this case
2847 for(GroupSet::iterator itr
= mGroupSet
.begin(); itr
!= mGroupSet
.end();)
2849 if((*itr
)->GetMembersCount() < 2)
2853 mGroupSet
.erase(itr
++);
2859 // -- loading instances --
2863 result
= CharacterDatabase
.Query(
2865 "SELECT leaderGuid, map, instance, permanent, difficulty, resettime, "
2867 "(SELECT COUNT(*) FROM character_instance WHERE guid = leaderGuid AND instance = group_instance.instance AND permanent = 1 LIMIT 1) "
2868 "FROM group_instance LEFT JOIN instance ON instance = id ORDER BY leaderGuid"
2873 barGoLink
bar2( 1 );
2878 barGoLink
bar2( result
->GetRowCount() );
2882 Field
*fields
= result
->Fetch();
2884 leaderGuid
= MAKE_NEW_GUID(fields
[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
2885 if(!group
|| group
->GetLeaderGUID() != leaderGuid
)
2887 group
= GetGroupByLeader(leaderGuid
);
2890 sLog
.outErrorDb("Incorrect entry in group_instance table : no group with leader %d", fields
[0].GetUInt32());
2895 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(fields
[1].GetUInt32());
2896 if(!mapEntry
|| !mapEntry
->IsDungeon())
2898 sLog
.outErrorDb("Incorrect entry in group_instance table : no dungeon map %d", fields
[1].GetUInt32());
2902 InstanceSave
*save
= sInstanceSaveManager
.AddInstanceSave(mapEntry
->MapID
, fields
[2].GetUInt32(), fields
[4].GetUInt8(), (time_t)fields
[5].GetUInt64(), (fields
[6].GetUInt32() == 0), true);
2903 group
->BindToInstance(save
, fields
[3].GetBool(), true);
2904 }while( result
->NextRow() );
2909 sLog
.outString( ">> Loaded %u group-instance binds total", count
);
2912 sLog
.outString( ">> Loaded %u group members total", count
);
2915 void ObjectMgr::LoadQuests()
2918 for(QuestMap::const_iterator itr
=mQuestTemplates
.begin(); itr
!= mQuestTemplates
.end(); ++itr
)
2920 mQuestTemplates
.clear();
2922 mExclusiveQuestGroups
.clear();
2924 // 0 1 2 3 4 5 6 7 8
2925 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, Method, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue,"
2926 // 9 10 11 12 13 14 15 16
2927 "RepObjectiveFaction, RepObjectiveValue, RequiredMinRepFaction, RequiredMinRepValue, RequiredMaxRepFaction, RequiredMaxRepValue, SuggestedPlayers, LimitTime,"
2928 // 17 18 19 20 21 22 23 24 25 26 27 28
2929 "QuestFlags, SpecialFlags, CharTitleId, PlayersSlain, BonusTalents, PrevQuestId, NextQuestId, ExclusiveGroup, NextQuestInChain, SrcItemId, SrcItemCount, SrcSpell,"
2930 // 29 30 31 32 33 34 35 36 37 38
2931 "Title, Details, Objectives, OfferRewardText, RequestItemsText, EndText, ObjectiveText1, ObjectiveText2, ObjectiveText3, ObjectiveText4,"
2932 // 39 40 41 42 43 44 45 46
2933 "ReqItemId1, ReqItemId2, ReqItemId3, ReqItemId4, ReqItemCount1, ReqItemCount2, ReqItemCount3, ReqItemCount4,"
2934 // 47 48 49 50 51 52 53 54
2935 "ReqSourceId1, ReqSourceId2, ReqSourceId3, ReqSourceId4, ReqSourceCount1, ReqSourceCount2, ReqSourceCount3, ReqSourceCount4,"
2936 // 55 56 57 58 59 60 61 62
2937 "ReqCreatureOrGOId1, ReqCreatureOrGOId2, ReqCreatureOrGOId3, ReqCreatureOrGOId4, ReqCreatureOrGOCount1, ReqCreatureOrGOCount2, ReqCreatureOrGOCount3, ReqCreatureOrGOCount4,"
2939 "ReqSpellCast1, ReqSpellCast2, ReqSpellCast3, ReqSpellCast4,"
2940 // 67 68 69 70 71 72
2941 "RewChoiceItemId1, RewChoiceItemId2, RewChoiceItemId3, RewChoiceItemId4, RewChoiceItemId5, RewChoiceItemId6,"
2942 // 73 74 75 76 77 78
2943 "RewChoiceItemCount1, RewChoiceItemCount2, RewChoiceItemCount3, RewChoiceItemCount4, RewChoiceItemCount5, RewChoiceItemCount6,"
2944 // 79 80 81 82 83 84 85 86
2945 "RewItemId1, RewItemId2, RewItemId3, RewItemId4, RewItemCount1, RewItemCount2, RewItemCount3, RewItemCount4,"
2946 // 87 88 89 90 91 92 93 94 95 96
2947 "RewRepFaction1, RewRepFaction2, RewRepFaction3, RewRepFaction4, RewRepFaction5, RewRepValue1, RewRepValue2, RewRepValue3, RewRepValue4, RewRepValue5,"
2948 // 97 98 99 100 101 102 103 104 105 106 107
2949 "RewHonorableKills, RewOrReqMoney, RewMoneyMaxLevel, RewSpell, RewSpellCast, RewMailTemplateId, RewMailDelaySecs, PointMapId, PointX, PointY, PointOpt,"
2950 // 108 109 110 111 112 113 114 115
2951 "DetailsEmote1, DetailsEmote2, DetailsEmote3, DetailsEmote4, DetailsEmoteDelay1, DetailsEmoteDelay2, DetailsEmoteDelay3, DetailsEmoteDelay4,"
2952 // 116 117 118 119 120 121
2953 "IncompleteEmote, CompleteEmote, OfferRewardEmote1, OfferRewardEmote2, OfferRewardEmote3, OfferRewardEmote4,"
2955 "OfferRewardEmoteDelay1, OfferRewardEmoteDelay2, OfferRewardEmoteDelay3, OfferRewardEmoteDelay4,"
2957 "StartScript, CompleteScript"
2958 " FROM quest_template");
2965 sLog
.outString( ">> Loaded 0 quests definitions" );
2966 sLog
.outErrorDb("`quest_template` table is empty!");
2970 // create multimap previous quest for each existed quest
2971 // some quests can have many previous maps set by NextQuestId in previous quest
2972 // for example set of race quests can lead to single not race specific quest
2973 barGoLink
bar( result
->GetRowCount() );
2977 Field
*fields
= result
->Fetch();
2979 Quest
* newQuest
= new Quest(fields
);
2980 mQuestTemplates
[newQuest
->GetQuestId()] = newQuest
;
2981 } while( result
->NextRow() );
2986 for (QuestMap::iterator iter
= mQuestTemplates
.begin(); iter
!= mQuestTemplates
.end(); ++iter
)
2988 Quest
* qinfo
= iter
->second
;
2990 // additional quest integrity checks (GO, creature_template and item_template must be loaded already)
2992 if( qinfo
->GetQuestMethod() >= 3 )
2994 sLog
.outErrorDb("Quest %u has `Method` = %u, expected values are 0, 1 or 2.",qinfo
->GetQuestId(),qinfo
->GetQuestMethod());
2997 if (qinfo
->QuestFlags
& ~QUEST_MANGOS_FLAGS_DB_ALLOWED
)
2999 sLog
.outErrorDb("Quest %u has `SpecialFlags` = %u > max allowed value. Correct `SpecialFlags` to value <= %u",
3000 qinfo
->GetQuestId(),qinfo
->QuestFlags
,QUEST_MANGOS_FLAGS_DB_ALLOWED
>> 16);
3001 qinfo
->QuestFlags
&= QUEST_MANGOS_FLAGS_DB_ALLOWED
;
3004 if(qinfo
->QuestFlags
& QUEST_FLAGS_DAILY
)
3006 if(!(qinfo
->QuestFlags
& QUEST_MANGOS_FLAGS_REPEATABLE
))
3008 sLog
.outErrorDb("Daily Quest %u not marked as repeatable in `SpecialFlags`, added.",qinfo
->GetQuestId());
3009 qinfo
->QuestFlags
|= QUEST_MANGOS_FLAGS_REPEATABLE
;
3013 if(qinfo
->QuestFlags
& QUEST_FLAGS_AUTO_REWARDED
)
3015 // at auto-reward can be rewarded only RewChoiceItemId[0]
3016 for(int j
= 1; j
< QUEST_REWARD_CHOICES_COUNT
; ++j
)
3018 if(uint32 id
= qinfo
->RewChoiceItemId
[j
])
3020 sLog
.outErrorDb("Quest %u has `RewChoiceItemId%d` = %u but item from `RewChoiceItemId%d` can't be rewarded with quest flag QUEST_FLAGS_AUTO_REWARDED.",
3021 qinfo
->GetQuestId(),j
+1,id
,j
+1);
3022 // no changes, quest ignore this data
3027 // client quest log visual (area case)
3028 if( qinfo
->ZoneOrSort
> 0 )
3030 if(!GetAreaEntryByAreaID(qinfo
->ZoneOrSort
))
3032 sLog
.outErrorDb("Quest %u has `ZoneOrSort` = %u (zone case) but zone with this id does not exist.",
3033 qinfo
->GetQuestId(),qinfo
->ZoneOrSort
);
3034 // no changes, quest not dependent from this value but can have problems at client
3037 // client quest log visual (sort case)
3038 if( qinfo
->ZoneOrSort
< 0 )
3040 QuestSortEntry
const* qSort
= sQuestSortStore
.LookupEntry(-int32(qinfo
->ZoneOrSort
));
3043 sLog
.outErrorDb("Quest %u has `ZoneOrSort` = %i (sort case) but quest sort with this id does not exist.",
3044 qinfo
->GetQuestId(),qinfo
->ZoneOrSort
);
3045 // 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)
3047 //check SkillOrClass value (class case).
3048 if( ClassByQuestSort(-int32(qinfo
->ZoneOrSort
)) )
3050 // SkillOrClass should not have class case when class case already set in ZoneOrSort.
3051 if(qinfo
->SkillOrClass
< 0)
3053 sLog
.outErrorDb("Quest %u has `ZoneOrSort` = %i (class sort case) and `SkillOrClass` = %i (class case), redundant.",
3054 qinfo
->GetQuestId(),qinfo
->ZoneOrSort
,qinfo
->SkillOrClass
);
3057 //check for proper SkillOrClass value (skill case)
3058 if(int32 skill_id
= SkillByQuestSort(-int32(qinfo
->ZoneOrSort
)))
3060 // skill is positive value in SkillOrClass
3061 if(qinfo
->SkillOrClass
!= skill_id
)
3063 sLog
.outErrorDb("Quest %u has `ZoneOrSort` = %i (skill sort case) but `SkillOrClass` does not have a corresponding value (%i).",
3064 qinfo
->GetQuestId(),qinfo
->ZoneOrSort
,skill_id
);
3065 //override, and force proper value here?
3070 // SkillOrClass (class case)
3071 if( qinfo
->SkillOrClass
< 0 )
3073 if( !sChrClassesStore
.LookupEntry(-int32(qinfo
->SkillOrClass
)) )
3075 sLog
.outErrorDb("Quest %u has `SkillOrClass` = %i (class case) but class (%i) does not exist",
3076 qinfo
->GetQuestId(),qinfo
->SkillOrClass
,-qinfo
->SkillOrClass
);
3079 // SkillOrClass (skill case)
3080 if( qinfo
->SkillOrClass
> 0 )
3082 if( !sSkillLineStore
.LookupEntry(qinfo
->SkillOrClass
) )
3084 sLog
.outErrorDb("Quest %u has `SkillOrClass` = %u (skill case) but skill (%i) does not exist",
3085 qinfo
->GetQuestId(),qinfo
->SkillOrClass
,qinfo
->SkillOrClass
);
3089 if( qinfo
->RequiredSkillValue
)
3091 if( qinfo
->RequiredSkillValue
> sWorld
.GetConfigMaxSkillValue() )
3093 sLog
.outErrorDb("Quest %u has `RequiredSkillValue` = %u but max possible skill is %u, quest can't be done.",
3094 qinfo
->GetQuestId(),qinfo
->RequiredSkillValue
,sWorld
.GetConfigMaxSkillValue());
3095 // no changes, quest can't be done for this requirement
3098 if( qinfo
->SkillOrClass
<= 0 )
3100 sLog
.outErrorDb("Quest %u has `RequiredSkillValue` = %u but `SkillOrClass` = %i (class case), value ignored.",
3101 qinfo
->GetQuestId(),qinfo
->RequiredSkillValue
,qinfo
->SkillOrClass
);
3102 // no changes, quest can't be done for this requirement (fail at wrong skill id)
3105 // else Skill quests can have 0 skill level, this is ok
3107 if(qinfo
->RepObjectiveFaction
&& !sFactionStore
.LookupEntry(qinfo
->RepObjectiveFaction
))
3109 sLog
.outErrorDb("Quest %u has `RepObjectiveFaction` = %u but faction template %u does not exist, quest can't be done.",
3110 qinfo
->GetQuestId(),qinfo
->RepObjectiveFaction
,qinfo
->RepObjectiveFaction
);
3111 // no changes, quest can't be done for this requirement
3114 if(qinfo
->RequiredMinRepFaction
&& !sFactionStore
.LookupEntry(qinfo
->RequiredMinRepFaction
))
3116 sLog
.outErrorDb("Quest %u has `RequiredMinRepFaction` = %u but faction template %u does not exist, quest can't be done.",
3117 qinfo
->GetQuestId(),qinfo
->RequiredMinRepFaction
,qinfo
->RequiredMinRepFaction
);
3118 // no changes, quest can't be done for this requirement
3121 if(qinfo
->RequiredMaxRepFaction
&& !sFactionStore
.LookupEntry(qinfo
->RequiredMaxRepFaction
))
3123 sLog
.outErrorDb("Quest %u has `RequiredMaxRepFaction` = %u but faction template %u does not exist, quest can't be done.",
3124 qinfo
->GetQuestId(),qinfo
->RequiredMaxRepFaction
,qinfo
->RequiredMaxRepFaction
);
3125 // no changes, quest can't be done for this requirement
3128 if(qinfo
->RequiredMinRepValue
&& qinfo
->RequiredMinRepValue
> ReputationMgr::Reputation_Cap
)
3130 sLog
.outErrorDb("Quest %u has `RequiredMinRepValue` = %d but max reputation is %u, quest can't be done.",
3131 qinfo
->GetQuestId(),qinfo
->RequiredMinRepValue
,ReputationMgr::Reputation_Cap
);
3132 // no changes, quest can't be done for this requirement
3135 if(qinfo
->RequiredMinRepValue
&& qinfo
->RequiredMaxRepValue
&& qinfo
->RequiredMaxRepValue
<= qinfo
->RequiredMinRepValue
)
3137 sLog
.outErrorDb("Quest %u has `RequiredMaxRepValue` = %d and `RequiredMinRepValue` = %d, quest can't be done.",
3138 qinfo
->GetQuestId(),qinfo
->RequiredMaxRepValue
,qinfo
->RequiredMinRepValue
);
3139 // no changes, quest can't be done for this requirement
3142 if(!qinfo
->RepObjectiveFaction
&& qinfo
->RepObjectiveValue
> 0 )
3144 sLog
.outErrorDb("Quest %u has `RepObjectiveValue` = %d but `RepObjectiveFaction` is 0, value has no effect",
3145 qinfo
->GetQuestId(),qinfo
->RepObjectiveValue
);
3149 if(!qinfo
->RequiredMinRepFaction
&& qinfo
->RequiredMinRepValue
> 0 )
3151 sLog
.outErrorDb("Quest %u has `RequiredMinRepValue` = %d but `RequiredMinRepFaction` is 0, value has no effect",
3152 qinfo
->GetQuestId(),qinfo
->RequiredMinRepValue
);
3156 if(!qinfo
->RequiredMaxRepFaction
&& qinfo
->RequiredMaxRepValue
> 0 )
3158 sLog
.outErrorDb("Quest %u has `RequiredMaxRepValue` = %d but `RequiredMaxRepFaction` is 0, value has no effect",
3159 qinfo
->GetQuestId(),qinfo
->RequiredMaxRepValue
);
3163 if(qinfo
->CharTitleId
&& !sCharTitlesStore
.LookupEntry(qinfo
->CharTitleId
))
3165 sLog
.outErrorDb("Quest %u has `CharTitleId` = %u but CharTitle Id %u does not exist, quest can't be rewarded with title.",
3166 qinfo
->GetQuestId(),qinfo
->GetCharTitleId(),qinfo
->GetCharTitleId());
3167 qinfo
->CharTitleId
= 0;
3168 // quest can't reward this title
3171 if(qinfo
->SrcItemId
)
3173 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(qinfo
->SrcItemId
))
3175 sLog
.outErrorDb("Quest %u has `SrcItemId` = %u but item with entry %u does not exist, quest can't be done.",
3176 qinfo
->GetQuestId(),qinfo
->SrcItemId
,qinfo
->SrcItemId
);
3177 qinfo
->SrcItemId
= 0; // quest can't be done for this requirement
3179 else if(qinfo
->SrcItemCount
==0)
3181 sLog
.outErrorDb("Quest %u has `SrcItemId` = %u but `SrcItemCount` = 0, set to 1 but need fix in DB.",
3182 qinfo
->GetQuestId(),qinfo
->SrcItemId
);
3183 qinfo
->SrcItemCount
= 1; // update to 1 for allow quest work for backward compatibility with DB
3186 else if(qinfo
->SrcItemCount
>0)
3188 sLog
.outErrorDb("Quest %u has `SrcItemId` = 0 but `SrcItemCount` = %u, useless value.",
3189 qinfo
->GetQuestId(),qinfo
->SrcItemCount
);
3190 qinfo
->SrcItemCount
=0; // no quest work changes in fact
3195 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(qinfo
->SrcSpell
);
3198 sLog
.outErrorDb("Quest %u has `SrcSpell` = %u but spell %u doesn't exist, quest can't be done.",
3199 qinfo
->GetQuestId(),qinfo
->SrcSpell
,qinfo
->SrcSpell
);
3200 qinfo
->SrcSpell
= 0; // quest can't be done for this requirement
3202 else if(!SpellMgr::IsSpellValid(spellInfo
))
3204 sLog
.outErrorDb("Quest %u has `SrcSpell` = %u but spell %u is broken, quest can't be done.",
3205 qinfo
->GetQuestId(),qinfo
->SrcSpell
,qinfo
->SrcSpell
);
3206 qinfo
->SrcSpell
= 0; // quest can't be done for this requirement
3210 for(int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; ++j
)
3212 uint32 id
= qinfo
->ReqItemId
[j
];
3215 if(qinfo
->ReqItemCount
[j
]==0)
3217 sLog
.outErrorDb("Quest %u has `ReqItemId%d` = %u but `ReqItemCount%d` = 0, quest can't be done.",
3218 qinfo
->GetQuestId(),j
+1,id
,j
+1);
3219 // no changes, quest can't be done for this requirement
3222 qinfo
->SetFlag(QUEST_MANGOS_FLAGS_DELIVER
);
3224 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(id
))
3226 sLog
.outErrorDb("Quest %u has `ReqItemId%d` = %u but item with entry %u does not exist, quest can't be done.",
3227 qinfo
->GetQuestId(),j
+1,id
,id
);
3228 qinfo
->ReqItemCount
[j
] = 0; // prevent incorrect work of quest
3231 else if(qinfo
->ReqItemCount
[j
]>0)
3233 sLog
.outErrorDb("Quest %u has `ReqItemId%d` = 0 but `ReqItemCount%d` = %u, quest can't be done.",
3234 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->ReqItemCount
[j
]);
3235 qinfo
->ReqItemCount
[j
] = 0; // prevent incorrect work of quest
3239 for(int j
= 0; j
< QUEST_SOURCE_ITEM_IDS_COUNT
; ++j
)
3241 uint32 id
= qinfo
->ReqSourceId
[j
];
3244 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(id
))
3246 sLog
.outErrorDb("Quest %u has `ReqSourceId%d` = %u but item with entry %u does not exist, quest can't be done.",
3247 qinfo
->GetQuestId(),j
+1,id
,id
);
3248 // no changes, quest can't be done for this requirement
3253 if(qinfo
->ReqSourceCount
[j
]>0)
3255 sLog
.outErrorDb("Quest %u has `ReqSourceId%d` = 0 but `ReqSourceCount%d` = %u.",
3256 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->ReqSourceCount
[j
]);
3257 // no changes, quest ignore this data
3262 for(int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; ++j
)
3264 uint32 id
= qinfo
->ReqSpell
[j
];
3267 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(id
);
3270 sLog
.outErrorDb("Quest %u has `ReqSpellCast%d` = %u but spell %u does not exist, quest can't be done.",
3271 qinfo
->GetQuestId(),j
+1,id
,id
);
3275 if(!qinfo
->ReqCreatureOrGOId
[j
])
3278 for(int k
= 0; k
< 3; ++k
)
3280 if( spellInfo
->Effect
[k
]==SPELL_EFFECT_QUEST_COMPLETE
&& uint32(spellInfo
->EffectMiscValue
[k
])==qinfo
->QuestId
||
3281 spellInfo
->Effect
[k
]==SPELL_EFFECT_SEND_EVENT
)
3290 if(!qinfo
->HasFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
))
3292 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);
3294 // this will prevent quest completing without objective
3295 const_cast<Quest
*>(qinfo
)->SetFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
);
3300 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.",
3301 qinfo
->GetQuestId(),j
+1,id
,j
+1,id
);
3302 // no changes, quest can't be done for this requirement
3308 for(int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; ++j
)
3310 int32 id
= qinfo
->ReqCreatureOrGOId
[j
];
3311 if(id
< 0 && !sGOStorage
.LookupEntry
<GameObjectInfo
>(-id
))
3313 sLog
.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = %i but gameobject %u does not exist, quest can't be done.",
3314 qinfo
->GetQuestId(),j
+1,id
,uint32(-id
));
3315 qinfo
->ReqCreatureOrGOId
[j
] = 0; // quest can't be done for this requirement
3318 if(id
> 0 && !sCreatureStorage
.LookupEntry
<CreatureInfo
>(id
))
3320 sLog
.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = %i but creature with entry %u does not exist, quest can't be done.",
3321 qinfo
->GetQuestId(),j
+1,id
,uint32(id
));
3322 qinfo
->ReqCreatureOrGOId
[j
] = 0; // quest can't be done for this requirement
3327 // In fact SpeakTo and Kill are quite same: either you can speak to mob:SpeakTo or you can't:Kill/Cast
3329 qinfo
->SetFlag(QUEST_MANGOS_FLAGS_KILL_OR_CAST
| QUEST_MANGOS_FLAGS_SPEAKTO
);
3331 if(!qinfo
->ReqCreatureOrGOCount
[j
])
3333 sLog
.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = %u but `ReqCreatureOrGOCount%d` = 0, quest can't be done.",
3334 qinfo
->GetQuestId(),j
+1,id
,j
+1);
3335 // no changes, quest can be incorrectly done, but we already report this
3338 else if(qinfo
->ReqCreatureOrGOCount
[j
]>0)
3340 sLog
.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = 0 but `ReqCreatureOrGOCount%d` = %u.",
3341 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->ReqCreatureOrGOCount
[j
]);
3342 // no changes, quest ignore this data
3346 for(int j
= 0; j
< QUEST_REWARD_CHOICES_COUNT
; ++j
)
3348 uint32 id
= qinfo
->RewChoiceItemId
[j
];
3351 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(id
))
3353 sLog
.outErrorDb("Quest %u has `RewChoiceItemId%d` = %u but item with entry %u does not exist, quest will not reward this item.",
3354 qinfo
->GetQuestId(),j
+1,id
,id
);
3355 qinfo
->RewChoiceItemId
[j
] = 0; // no changes, quest will not reward this
3358 if(!qinfo
->RewChoiceItemCount
[j
])
3360 sLog
.outErrorDb("Quest %u has `RewChoiceItemId%d` = %u but `RewChoiceItemCount%d` = 0, quest can't be done.",
3361 qinfo
->GetQuestId(),j
+1,id
,j
+1);
3362 // no changes, quest can't be done
3365 else if(qinfo
->RewChoiceItemCount
[j
]>0)
3367 sLog
.outErrorDb("Quest %u has `RewChoiceItemId%d` = 0 but `RewChoiceItemCount%d` = %u.",
3368 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->RewChoiceItemCount
[j
]);
3369 // no changes, quest ignore this data
3373 for(int j
= 0; j
< QUEST_REWARDS_COUNT
; ++j
)
3375 uint32 id
= qinfo
->RewItemId
[j
];
3378 if(!sItemStorage
.LookupEntry
<ItemPrototype
>(id
))
3380 sLog
.outErrorDb("Quest %u has `RewItemId%d` = %u but item with entry %u does not exist, quest will not reward this item.",
3381 qinfo
->GetQuestId(),j
+1,id
,id
);
3382 qinfo
->RewItemId
[j
] = 0; // no changes, quest will not reward this item
3385 if(!qinfo
->RewItemCount
[j
])
3387 sLog
.outErrorDb("Quest %u has `RewItemId%d` = %u but `RewItemCount%d` = 0, quest will not reward this item.",
3388 qinfo
->GetQuestId(),j
+1,id
,j
+1);
3392 else if(qinfo
->RewItemCount
[j
]>0)
3394 sLog
.outErrorDb("Quest %u has `RewItemId%d` = 0 but `RewItemCount%d` = %u.",
3395 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->RewItemCount
[j
]);
3396 // no changes, quest ignore this data
3400 for(int j
= 0; j
< QUEST_REPUTATIONS_COUNT
; ++j
)
3402 if(qinfo
->RewRepFaction
[j
])
3404 if(!qinfo
->RewRepValue
[j
])
3406 sLog
.outErrorDb("Quest %u has `RewRepFaction%d` = %u but `RewRepValue%d` = 0, quest will not reward this reputation.",
3407 qinfo
->GetQuestId(),j
+1,qinfo
->RewRepValue
[j
],j
+1);
3411 if(!sFactionStore
.LookupEntry(qinfo
->RewRepFaction
[j
]))
3413 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.",
3414 qinfo
->GetQuestId(),j
+1,qinfo
->RewRepFaction
[j
] ,qinfo
->RewRepFaction
[j
] );
3415 qinfo
->RewRepFaction
[j
] = 0; // quest will not reward this
3418 else if(qinfo
->RewRepValue
[j
]!=0)
3420 sLog
.outErrorDb("Quest %u has `RewRepFaction%d` = 0 but `RewRepValue%d` = %u.",
3421 qinfo
->GetQuestId(),j
+1,j
+1,qinfo
->RewRepValue
[j
]);
3422 // no changes, quest ignore this data
3428 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(qinfo
->RewSpell
);
3432 sLog
.outErrorDb("Quest %u has `RewSpell` = %u but spell %u does not exist, spell removed as display reward.",
3433 qinfo
->GetQuestId(),qinfo
->RewSpell
,qinfo
->RewSpell
);
3434 qinfo
->RewSpell
= 0; // no spell reward will display for this quest
3437 else if(!SpellMgr::IsSpellValid(spellInfo
))
3439 sLog
.outErrorDb("Quest %u has `RewSpell` = %u but spell %u is broken, quest can't be done.",
3440 qinfo
->GetQuestId(),qinfo
->RewSpell
,qinfo
->RewSpell
);
3441 qinfo
->RewSpell
= 0; // no spell reward will display for this quest
3446 if(qinfo
->RewSpellCast
)
3448 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(qinfo
->RewSpellCast
);
3452 sLog
.outErrorDb("Quest %u has `RewSpellCast` = %u but spell %u does not exist, quest will not have a spell reward.",
3453 qinfo
->GetQuestId(),qinfo
->RewSpellCast
,qinfo
->RewSpellCast
);
3454 qinfo
->RewSpellCast
= 0; // no spell will be casted on player
3457 else if(!SpellMgr::IsSpellValid(spellInfo
))
3459 sLog
.outErrorDb("Quest %u has `RewSpellCast` = %u but spell %u is broken, quest can't be done.",
3460 qinfo
->GetQuestId(),qinfo
->RewSpellCast
,qinfo
->RewSpellCast
);
3461 qinfo
->RewSpellCast
= 0; // no spell will be casted on player
3466 if(qinfo
->RewMailTemplateId
)
3468 if(!sMailTemplateStore
.LookupEntry(qinfo
->RewMailTemplateId
))
3470 sLog
.outErrorDb("Quest %u has `RewMailTemplateId` = %u but mail template %u does not exist, quest will not have a mail reward.",
3471 qinfo
->GetQuestId(),qinfo
->RewMailTemplateId
,qinfo
->RewMailTemplateId
);
3472 qinfo
->RewMailTemplateId
= 0; // no mail will send to player
3473 qinfo
->RewMailDelaySecs
= 0; // no mail will send to player
3477 if(qinfo
->NextQuestInChain
)
3479 QuestMap::iterator qNextItr
= mQuestTemplates
.find(qinfo
->NextQuestInChain
);
3480 if(qNextItr
== mQuestTemplates
.end())
3482 sLog
.outErrorDb("Quest %u has `NextQuestInChain` = %u but quest %u does not exist, quest chain will not work.",
3483 qinfo
->GetQuestId(),qinfo
->NextQuestInChain
,qinfo
->NextQuestInChain
);
3484 qinfo
->NextQuestInChain
= 0;
3487 qNextItr
->second
->prevChainQuests
.push_back(qinfo
->GetQuestId());
3490 // fill additional data stores
3491 if(qinfo
->PrevQuestId
)
3493 if (mQuestTemplates
.find(abs(qinfo
->GetPrevQuestId())) == mQuestTemplates
.end())
3495 sLog
.outErrorDb("Quest %d has PrevQuestId %i, but no such quest", qinfo
->GetQuestId(), qinfo
->GetPrevQuestId());
3499 qinfo
->prevQuests
.push_back(qinfo
->PrevQuestId
);
3503 if(qinfo
->NextQuestId
)
3505 QuestMap::iterator qNextItr
= mQuestTemplates
.find(abs(qinfo
->GetNextQuestId()));
3506 if (qNextItr
== mQuestTemplates
.end())
3508 sLog
.outErrorDb("Quest %d has NextQuestId %i, but no such quest", qinfo
->GetQuestId(), qinfo
->GetNextQuestId());
3512 int32 signedQuestId
= qinfo
->NextQuestId
< 0 ? -int32(qinfo
->GetQuestId()) : int32(qinfo
->GetQuestId());
3513 qNextItr
->second
->prevQuests
.push_back(signedQuestId
);
3517 if(qinfo
->ExclusiveGroup
)
3518 mExclusiveQuestGroups
.insert(std::pair
<int32
, uint32
>(qinfo
->ExclusiveGroup
, qinfo
->GetQuestId()));
3519 if(qinfo
->LimitTime
)
3520 qinfo
->SetFlag(QUEST_MANGOS_FLAGS_TIMED
);
3523 // check QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT for spell with SPELL_EFFECT_QUEST_COMPLETE
3524 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); ++i
)
3526 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
3530 for(int j
= 0; j
< 3; ++j
)
3532 if(spellInfo
->Effect
[j
] != SPELL_EFFECT_QUEST_COMPLETE
)
3535 uint32 quest_id
= spellInfo
->EffectMiscValue
[j
];
3537 Quest
const* quest
= GetQuestTemplate(quest_id
);
3539 // some quest referenced in spells not exist (outdated spells)
3543 if(!quest
->HasFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
))
3545 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
);
3547 // this will prevent quest completing without objective
3548 const_cast<Quest
*>(quest
)->SetFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
);
3554 sLog
.outString( ">> Loaded %lu quests definitions", (unsigned long)mQuestTemplates
.size() );
3557 void ObjectMgr::LoadQuestLocales()
3559 mQuestLocaleMap
.clear(); // need for reload case
3561 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,"
3562 "Title_loc1,Details_loc1,Objectives_loc1,OfferRewardText_loc1,RequestItemsText_loc1,EndText_loc1,ObjectiveText1_loc1,ObjectiveText2_loc1,ObjectiveText3_loc1,ObjectiveText4_loc1,"
3563 "Title_loc2,Details_loc2,Objectives_loc2,OfferRewardText_loc2,RequestItemsText_loc2,EndText_loc2,ObjectiveText1_loc2,ObjectiveText2_loc2,ObjectiveText3_loc2,ObjectiveText4_loc2,"
3564 "Title_loc3,Details_loc3,Objectives_loc3,OfferRewardText_loc3,RequestItemsText_loc3,EndText_loc3,ObjectiveText1_loc3,ObjectiveText2_loc3,ObjectiveText3_loc3,ObjectiveText4_loc3,"
3565 "Title_loc4,Details_loc4,Objectives_loc4,OfferRewardText_loc4,RequestItemsText_loc4,EndText_loc4,ObjectiveText1_loc4,ObjectiveText2_loc4,ObjectiveText3_loc4,ObjectiveText4_loc4,"
3566 "Title_loc5,Details_loc5,Objectives_loc5,OfferRewardText_loc5,RequestItemsText_loc5,EndText_loc5,ObjectiveText1_loc5,ObjectiveText2_loc5,ObjectiveText3_loc5,ObjectiveText4_loc5,"
3567 "Title_loc6,Details_loc6,Objectives_loc6,OfferRewardText_loc6,RequestItemsText_loc6,EndText_loc6,ObjectiveText1_loc6,ObjectiveText2_loc6,ObjectiveText3_loc6,ObjectiveText4_loc6,"
3568 "Title_loc7,Details_loc7,Objectives_loc7,OfferRewardText_loc7,RequestItemsText_loc7,EndText_loc7,ObjectiveText1_loc7,ObjectiveText2_loc7,ObjectiveText3_loc7,ObjectiveText4_loc7,"
3569 "Title_loc8,Details_loc8,Objectives_loc8,OfferRewardText_loc8,RequestItemsText_loc8,EndText_loc8,ObjectiveText1_loc8,ObjectiveText2_loc8,ObjectiveText3_loc8,ObjectiveText4_loc8"
3570 " FROM locales_quest"
3580 sLog
.outString(">> Loaded 0 Quest locale strings. DB table `locales_quest` is empty.");
3584 barGoLink
bar(result
->GetRowCount());
3588 Field
*fields
= result
->Fetch();
3591 uint32 entry
= fields
[0].GetUInt32();
3593 QuestLocale
& data
= mQuestLocaleMap
[entry
];
3595 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
3597 std::string str
= fields
[1+10*(i
-1)].GetCppString();
3600 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
3603 if(data
.Title
.size() <= idx
)
3604 data
.Title
.resize(idx
+1);
3606 data
.Title
[idx
] = str
;
3609 str
= fields
[1+10*(i
-1)+1].GetCppString();
3612 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
3615 if(data
.Details
.size() <= idx
)
3616 data
.Details
.resize(idx
+1);
3618 data
.Details
[idx
] = str
;
3621 str
= fields
[1+10*(i
-1)+2].GetCppString();
3624 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
3627 if(data
.Objectives
.size() <= idx
)
3628 data
.Objectives
.resize(idx
+1);
3630 data
.Objectives
[idx
] = str
;
3633 str
= fields
[1+10*(i
-1)+3].GetCppString();
3636 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
3639 if(data
.OfferRewardText
.size() <= idx
)
3640 data
.OfferRewardText
.resize(idx
+1);
3642 data
.OfferRewardText
[idx
] = str
;
3645 str
= fields
[1+10*(i
-1)+4].GetCppString();
3648 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
3651 if(data
.RequestItemsText
.size() <= idx
)
3652 data
.RequestItemsText
.resize(idx
+1);
3654 data
.RequestItemsText
[idx
] = str
;
3657 str
= fields
[1+10*(i
-1)+5].GetCppString();
3660 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
3663 if(data
.EndText
.size() <= idx
)
3664 data
.EndText
.resize(idx
+1);
3666 data
.EndText
[idx
] = str
;
3669 for(int k
= 0; k
< 4; ++k
)
3671 str
= fields
[1+10*(i
-1)+6+k
].GetCppString();
3674 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
3677 if(data
.ObjectiveText
[k
].size() <= idx
)
3678 data
.ObjectiveText
[k
].resize(idx
+1);
3680 data
.ObjectiveText
[k
][idx
] = str
;
3685 } while (result
->NextRow());
3690 sLog
.outString( ">> Loaded %lu Quest locale strings", (unsigned long)mQuestLocaleMap
.size() );
3693 void ObjectMgr::LoadScripts(ScriptMapMap
& scripts
, char const* tablename
)
3695 if(sWorld
.IsScriptScheduled()) // function don't must be called in time scripts use.
3698 sLog
.outString( "%s :", tablename
);
3700 scripts
.clear(); // need for reload support
3702 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT id,delay,command,datalong,datalong2,dataint, x, y, z, o FROM %s", tablename
);
3712 sLog
.outString( ">> Loaded %u script definitions", count
);
3716 barGoLink
bar( result
->GetRowCount() );
3722 Field
*fields
= result
->Fetch();
3724 tmp
.id
= fields
[0].GetUInt32();
3725 tmp
.delay
= fields
[1].GetUInt32();
3726 tmp
.command
= fields
[2].GetUInt32();
3727 tmp
.datalong
= fields
[3].GetUInt32();
3728 tmp
.datalong2
= fields
[4].GetUInt32();
3729 tmp
.dataint
= fields
[5].GetInt32();
3730 tmp
.x
= fields
[6].GetFloat();
3731 tmp
.y
= fields
[7].GetFloat();
3732 tmp
.z
= fields
[8].GetFloat();
3733 tmp
.o
= fields
[9].GetFloat();
3735 // generic command args check
3738 case SCRIPT_COMMAND_TALK
:
3740 if(tmp
.datalong
> 3)
3742 sLog
.outErrorDb("Table `%s` has invalid talk type (datalong = %u) in SCRIPT_COMMAND_TALK for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
3747 sLog
.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u",tablename
,tmp
.dataint
,tmp
.id
);
3750 if(tmp
.dataint
< MIN_DB_SCRIPT_STRING_ID
|| tmp
.dataint
>= MAX_DB_SCRIPT_STRING_ID
)
3752 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
);
3756 // if(!objmgr.GetMangosStringLocale(tmp.dataint)) will checked after db_script_string loading
3760 case SCRIPT_COMMAND_EMOTE
:
3762 if(!sEmotesStore
.LookupEntry(tmp
.datalong
))
3764 sLog
.outErrorDb("Table `%s` has invalid emote id (datalong = %u) in SCRIPT_COMMAND_EMOTE for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
3770 case SCRIPT_COMMAND_TELEPORT_TO
:
3772 if(!sMapStore
.LookupEntry(tmp
.datalong
))
3774 sLog
.outErrorDb("Table `%s` has invalid map (Id: %u) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
3778 if(!MaNGOS::IsValidMapCoord(tmp
.x
,tmp
.y
,tmp
.z
,tmp
.o
))
3780 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
);
3786 case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE
:
3788 if(!MaNGOS::IsValidMapCoord(tmp
.x
,tmp
.y
,tmp
.z
,tmp
.o
))
3790 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
);
3794 if(!GetCreatureTemplate(tmp
.datalong
))
3796 sLog
.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
3802 case SCRIPT_COMMAND_RESPAWN_GAMEOBJECT
:
3804 GameObjectData
const* data
= GetGOData(tmp
.datalong
);
3807 sLog
.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",tablename
,tmp
.datalong
,tmp
.id
);
3811 GameObjectInfo
const* info
= GetGameObjectInfo(data
->id
);
3814 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
);
3818 if( info
->type
==GAMEOBJECT_TYPE_FISHINGNODE
||
3819 info
->type
==GAMEOBJECT_TYPE_FISHINGHOLE
||
3820 info
->type
==GAMEOBJECT_TYPE_DOOR
||
3821 info
->type
==GAMEOBJECT_TYPE_BUTTON
||
3822 info
->type
==GAMEOBJECT_TYPE_TRAP
)
3824 sLog
.outErrorDb("Table `%s` have gameobject type (%u) unsupported by command SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",tablename
,info
->id
,tmp
.id
);
3829 case SCRIPT_COMMAND_OPEN_DOOR
:
3830 case SCRIPT_COMMAND_CLOSE_DOOR
:
3832 GameObjectData
const* data
= GetGOData(tmp
.datalong
);
3835 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
);
3839 GameObjectInfo
const* info
= GetGameObjectInfo(data
->id
);
3842 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
);
3846 if( info
->type
!=GAMEOBJECT_TYPE_DOOR
)
3848 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
);
3854 case SCRIPT_COMMAND_QUEST_EXPLORED
:
3856 Quest
const* quest
= GetQuestTemplate(tmp
.datalong
);
3859 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
);
3863 if(!quest
->HasFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
))
3865 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
);
3867 // this will prevent quest completing without objective
3868 const_cast<Quest
*>(quest
)->SetFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
);
3870 // continue; - quest objective requirement set and command can be allowed
3873 if(float(tmp
.datalong2
) > DEFAULT_VISIBILITY_DISTANCE
)
3875 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",
3876 tablename
,tmp
.datalong2
,tmp
.id
);
3880 if(tmp
.datalong2
&& float(tmp
.datalong2
) > DEFAULT_VISIBILITY_DISTANCE
)
3882 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",
3883 tablename
,tmp
.datalong2
,tmp
.id
,DEFAULT_VISIBILITY_DISTANCE
);
3887 if(tmp
.datalong2
&& float(tmp
.datalong2
) < INTERACTION_DISTANCE
)
3889 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",
3890 tablename
,tmp
.datalong2
,tmp
.id
,INTERACTION_DISTANCE
);
3897 case SCRIPT_COMMAND_REMOVE_AURA
:
3899 if(!sSpellStore
.LookupEntry(tmp
.datalong
))
3901 sLog
.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA or SCRIPT_COMMAND_CAST_SPELL for script id %u",
3902 tablename
,tmp
.datalong
,tmp
.id
);
3905 if(tmp
.datalong2
& ~0x1) // 1 bits (0,1)
3907 sLog
.outErrorDb("Table `%s` using unknown flags in datalong2 (%u)i n SCRIPT_COMMAND_CAST_SPELL for script id %u",
3908 tablename
,tmp
.datalong2
,tmp
.id
);
3913 case SCRIPT_COMMAND_CAST_SPELL
:
3915 if(!sSpellStore
.LookupEntry(tmp
.datalong
))
3917 sLog
.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA or SCRIPT_COMMAND_CAST_SPELL for script id %u",
3918 tablename
,tmp
.datalong
,tmp
.id
);
3921 if(tmp
.datalong2
& ~0x3) // 2 bits
3923 sLog
.outErrorDb("Table `%s` using unknown flags in datalong2 (%u)i n SCRIPT_COMMAND_CAST_SPELL for script id %u",
3924 tablename
,tmp
.datalong2
,tmp
.id
);
3931 if (scripts
.find(tmp
.id
) == scripts
.end())
3934 scripts
[tmp
.id
] = emptyMap
;
3936 scripts
[tmp
.id
].insert(std::pair
<uint32
, ScriptInfo
>(tmp
.delay
, tmp
));
3939 } while( result
->NextRow() );
3944 sLog
.outString( ">> Loaded %u script definitions", count
);
3947 void ObjectMgr::LoadGameObjectScripts()
3949 LoadScripts(sGameObjectScripts
, "gameobject_scripts");
3952 for(ScriptMapMap::const_iterator itr
= sGameObjectScripts
.begin(); itr
!= sGameObjectScripts
.end(); ++itr
)
3954 if(!GetGOData(itr
->first
))
3955 sLog
.outErrorDb("Table `gameobject_scripts` has not existing gameobject (GUID: %u) as script id",itr
->first
);
3959 void ObjectMgr::LoadQuestEndScripts()
3961 LoadScripts(sQuestEndScripts
, "quest_end_scripts");
3964 for(ScriptMapMap::const_iterator itr
= sQuestEndScripts
.begin(); itr
!= sQuestEndScripts
.end(); ++itr
)
3966 if(!GetQuestTemplate(itr
->first
))
3967 sLog
.outErrorDb("Table `quest_end_scripts` has not existing quest (Id: %u) as script id",itr
->first
);
3971 void ObjectMgr::LoadQuestStartScripts()
3973 LoadScripts(sQuestStartScripts
,"quest_start_scripts");
3976 for(ScriptMapMap::const_iterator itr
= sQuestStartScripts
.begin(); itr
!= sQuestStartScripts
.end(); ++itr
)
3978 if(!GetQuestTemplate(itr
->first
))
3979 sLog
.outErrorDb("Table `quest_start_scripts` has not existing quest (Id: %u) as script id",itr
->first
);
3983 void ObjectMgr::LoadSpellScripts()
3985 LoadScripts(sSpellScripts
, "spell_scripts");
3988 for(ScriptMapMap::const_iterator itr
= sSpellScripts
.begin(); itr
!= sSpellScripts
.end(); ++itr
)
3990 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
3994 sLog
.outErrorDb("Table `spell_scripts` has not existing spell (Id: %u) as script id",itr
->first
);
3998 //check for correct spellEffect
4000 for(int i
=0; i
<3; ++i
)
4002 // skip empty effects
4003 if( !spellInfo
->Effect
[i
] )
4006 if( spellInfo
->Effect
[i
] == SPELL_EFFECT_SCRIPT_EFFECT
)
4014 sLog
.outErrorDb("Table `spell_scripts` has unsupported spell (Id: %u) without SPELL_EFFECT_SCRIPT_EFFECT (%u) spell effect",itr
->first
,SPELL_EFFECT_SCRIPT_EFFECT
);
4018 void ObjectMgr::LoadEventScripts()
4020 LoadScripts(sEventScripts
, "event_scripts");
4022 std::set
<uint32
> evt_scripts
;
4023 // Load all possible script entries from gameobjects
4024 for(uint32 i
= 1; i
< sGOStorage
.MaxEntry
; ++i
)
4026 GameObjectInfo
const * goInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(i
);
4029 switch(goInfo
->type
)
4031 case GAMEOBJECT_TYPE_GOOBER
:
4032 if (goInfo
->goober
.eventId
)
4033 evt_scripts
.insert(goInfo
->goober
.eventId
);
4035 case GAMEOBJECT_TYPE_CHEST
:
4036 if (goInfo
->chest
.eventId
)
4037 evt_scripts
.insert(goInfo
->chest
.eventId
);
4039 case GAMEOBJECT_TYPE_CAMERA
:
4040 if (goInfo
->camera
.eventID
)
4041 evt_scripts
.insert(goInfo
->camera
.eventID
);
4047 // Load all possible script entries from spells
4048 for(uint32 i
= 1; i
< sSpellStore
.GetNumRows(); ++i
)
4050 SpellEntry
const * spell
= sSpellStore
.LookupEntry(i
);
4053 for(int j
=0; j
<3; ++j
)
4055 if( spell
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
)
4057 if (spell
->EffectMiscValue
[j
])
4058 evt_scripts
.insert(spell
->EffectMiscValue
[j
]);
4063 // Then check if all scripts are in above list of possible script entries
4064 for(ScriptMapMap::const_iterator itr
= sEventScripts
.begin(); itr
!= sEventScripts
.end(); ++itr
)
4066 std::set
<uint32
>::const_iterator itr2
= evt_scripts
.find(itr
->first
);
4067 if (itr2
== evt_scripts
.end())
4068 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",
4069 itr
->first
, SPELL_EFFECT_SEND_EVENT
);
4073 void ObjectMgr::LoadItemTexts()
4075 QueryResult
*result
= CharacterDatabase
.Query("SELECT id, text FROM item_text");
4085 sLog
.outString( ">> Loaded %u item pages", count
);
4089 barGoLink
bar( result
->GetRowCount() );
4096 fields
= result
->Fetch();
4098 mItemTexts
[ fields
[0].GetUInt32() ] = fields
[1].GetCppString();
4102 } while ( result
->NextRow() );
4107 sLog
.outString( ">> Loaded %u item texts", count
);
4110 void ObjectMgr::LoadPageTexts()
4112 sPageTextStore
.Free(); // for reload case
4114 sPageTextStore
.Load();
4115 sLog
.outString( ">> Loaded %u page texts", sPageTextStore
.RecordCount
);
4118 for(uint32 i
= 1; i
< sPageTextStore
.MaxEntry
; ++i
)
4120 // check data correctness
4121 PageText
const* page
= sPageTextStore
.LookupEntry
<PageText
>(i
);
4125 if(page
->Next_Page
&& !sPageTextStore
.LookupEntry
<PageText
>(page
->Next_Page
))
4127 sLog
.outErrorDb("Page text (Id: %u) has not existing next page (Id:%u)", i
,page
->Next_Page
);
4131 // detect circular reference
4132 std::set
<uint32
> checkedPages
;
4133 for(PageText
const* pageItr
= page
; pageItr
; pageItr
= sPageTextStore
.LookupEntry
<PageText
>(pageItr
->Next_Page
))
4135 if(!pageItr
->Next_Page
)
4137 checkedPages
.insert(pageItr
->Page_ID
);
4138 if(checkedPages
.find(pageItr
->Next_Page
)!=checkedPages
.end())
4140 std::ostringstream ss
;
4141 ss
<< "The text page(s) ";
4142 for (std::set
<uint32
>::iterator itr
= checkedPages
.begin();itr
!=checkedPages
.end(); ++itr
)
4144 ss
<< "create(s) a circular reference, which can cause the server to freeze. Changing Next_Page of page "
4145 << pageItr
->Page_ID
<<" to 0";
4146 sLog
.outErrorDb(ss
.str().c_str());
4147 const_cast<PageText
*>(pageItr
)->Next_Page
= 0;
4154 void ObjectMgr::LoadPageTextLocales()
4156 mPageTextLocaleMap
.clear(); // need for reload case
4158 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");
4167 sLog
.outString(">> Loaded 0 PageText locale strings. DB table `locales_page_text` is empty.");
4171 barGoLink
bar(result
->GetRowCount());
4175 Field
*fields
= result
->Fetch();
4178 uint32 entry
= fields
[0].GetUInt32();
4180 PageTextLocale
& data
= mPageTextLocaleMap
[entry
];
4182 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
4184 std::string str
= fields
[i
].GetCppString();
4188 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4191 if(data
.Text
.size() <= idx
)
4192 data
.Text
.resize(idx
+1);
4194 data
.Text
[idx
] = str
;
4198 } while (result
->NextRow());
4203 sLog
.outString( ">> Loaded %lu PageText locale strings", (unsigned long)mPageTextLocaleMap
.size() );
4206 struct SQLInstanceLoader
: public SQLStorageLoaderBase
<SQLInstanceLoader
>
4209 void convert_from_str(uint32
/*field_pos*/, char *src
, D
&dst
)
4211 dst
= D(objmgr
.GetScriptId(src
));
4215 void ObjectMgr::LoadInstanceTemplate()
4217 SQLInstanceLoader loader
;
4218 loader
.Load(sInstanceTemplate
);
4220 for(uint32 i
= 0; i
< sInstanceTemplate
.MaxEntry
; i
++)
4222 InstanceTemplate
* temp
= (InstanceTemplate
*)GetInstanceTemplate(i
);
4224 const MapEntry
* entry
= sMapStore
.LookupEntry(temp
->map
);
4227 sLog
.outErrorDb("ObjectMgr::LoadInstanceTemplate: bad mapid %d for template!", temp
->map
);
4230 else if(!entry
->HasResetTime())
4233 //FIXME: now exist heroic instance, normal/heroic raid instances
4234 // entry->resetTimeHeroic store reset time for both heroic mode instance (raid and non-raid)
4235 // entry->resetTimeRaid store reset time for normal raid only
4236 // for current state entry->resetTimeRaid == entry->resetTimeHeroic in case raid instances with heroic mode.
4237 // but at some point wee need implement reset time dependent from raid instance mode
4238 if(temp
->reset_delay
== 0)
4240 // use defaults from the DBC
4241 if(entry
->resetTimeHeroic
) // for both raid and non raids, read above
4243 temp
->reset_delay
= entry
->resetTimeHeroic
/ DAY
;
4245 else if (entry
->resetTimeRaid
&& entry
->map_type
== MAP_RAID
)
4246 // for normal raid only
4248 temp
->reset_delay
= entry
->resetTimeRaid
/ DAY
;
4252 // the reset_delay must be at least one day
4253 temp
->reset_delay
= std::max((uint32
)1, (uint32
)(temp
->reset_delay
* sWorld
.getRate(RATE_INSTANCE_RESET_TIME
)));
4256 sLog
.outString( ">> Loaded %u Instance Template definitions", sInstanceTemplate
.RecordCount
);
4260 GossipText
const *ObjectMgr::GetGossipText(uint32 Text_ID
) const
4262 GossipTextMap::const_iterator itr
= mGossipText
.find(Text_ID
);
4263 if(itr
!= mGossipText
.end())
4264 return &itr
->second
;
4268 void ObjectMgr::LoadGossipText()
4270 QueryResult
*result
= WorldDatabase
.Query( "SELECT * FROM npc_text" );
4279 sLog
.outString( ">> Loaded %u npc texts", count
);
4285 barGoLink
bar( result
->GetRowCount() );
4292 Field
*fields
= result
->Fetch();
4296 uint32 Text_ID
= fields
[cic
++].GetUInt32();
4299 sLog
.outErrorDb("Table `npc_text` has record wit reserved id 0, ignore.");
4303 GossipText
& gText
= mGossipText
[Text_ID
];
4305 for (int i
=0; i
< 8; i
++)
4307 gText
.Options
[i
].Text_0
= fields
[cic
++].GetCppString();
4308 gText
.Options
[i
].Text_1
= fields
[cic
++].GetCppString();
4310 gText
.Options
[i
].Language
= fields
[cic
++].GetUInt32();
4311 gText
.Options
[i
].Probability
= fields
[cic
++].GetFloat();
4313 for(int j
=0; j
< 3; ++j
)
4315 gText
.Options
[i
].Emotes
[j
]._Delay
= fields
[cic
++].GetUInt32();
4316 gText
.Options
[i
].Emotes
[j
]._Emote
= fields
[cic
++].GetUInt32();
4319 } while( result
->NextRow() );
4322 sLog
.outString( ">> Loaded %u npc texts", count
);
4326 void ObjectMgr::LoadNpcTextLocales()
4328 mNpcTextLocaleMap
.clear(); // need for reload case
4330 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,"
4331 "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,"
4332 "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,"
4333 "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,"
4334 "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,"
4335 "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,"
4336 "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,"
4337 "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, "
4338 "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 "
4339 " FROM locales_npc_text");
4348 sLog
.outString(">> Loaded 0 Quest locale strings. DB table `locales_npc_text` is empty.");
4352 barGoLink
bar(result
->GetRowCount());
4356 Field
*fields
= result
->Fetch();
4359 uint32 entry
= fields
[0].GetUInt32();
4361 NpcTextLocale
& data
= mNpcTextLocaleMap
[entry
];
4363 for(int i
=1; i
<MAX_LOCALE
; ++i
)
4365 for(int j
=0; j
<8; ++j
)
4367 std::string str0
= fields
[1+8*2*(i
-1)+2*j
].GetCppString();
4370 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4373 if(data
.Text_0
[j
].size() <= idx
)
4374 data
.Text_0
[j
].resize(idx
+1);
4376 data
.Text_0
[j
][idx
] = str0
;
4379 std::string str1
= fields
[1+8*2*(i
-1)+2*j
+1].GetCppString();
4382 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
4385 if(data
.Text_1
[j
].size() <= idx
)
4386 data
.Text_1
[j
].resize(idx
+1);
4388 data
.Text_1
[j
][idx
] = str1
;
4393 } while (result
->NextRow());
4398 sLog
.outString( ">> Loaded %lu NpcText locale strings", (unsigned long)mNpcTextLocaleMap
.size() );
4401 //not very fast function but it is called only once a day, or on starting-up
4402 void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp
)
4404 time_t basetime
= time(NULL
);
4405 sLog
.outDebug("Returning mails current time: hour: %d, minute: %d, second: %d ", localtime(&basetime
)->tm_hour
, localtime(&basetime
)->tm_min
, localtime(&basetime
)->tm_sec
);
4406 //delete all old mails without item and without body immediately, if starting server
4408 CharacterDatabase
.PExecute("DELETE FROM mail WHERE expire_time < '" UI64FMTD
"' AND has_items = '0' AND itemTextId = 0", (uint64
)basetime
);
4409 // 0 1 2 3 4 5 6 7 8 9
4410 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
);
4416 sLog
.outString(">> Only expired mails (need to be return or delete) or DB table `mail` is empty.");
4417 return; // any mails need to be returned or deleted
4420 //std::ostringstream delitems, delmails; //will be here for optimization
4421 //bool deletemail = false, deleteitem = false;
4422 //delitems << "DELETE FROM item_instance WHERE guid IN ( ";
4423 //delmails << "DELETE FROM mail WHERE id IN ( "
4425 barGoLink
bar( result
->GetRowCount() );
4433 fields
= result
->Fetch();
4435 m
->messageID
= fields
[0].GetUInt32();
4436 m
->messageType
= fields
[1].GetUInt8();
4437 m
->sender
= fields
[2].GetUInt32();
4438 m
->receiver
= fields
[3].GetUInt32();
4439 m
->itemTextId
= fields
[4].GetUInt32();
4440 bool has_items
= fields
[5].GetBool();
4441 m
->expire_time
= (time_t)fields
[6].GetUInt64();
4442 m
->deliver_time
= 0;
4443 m
->COD
= fields
[7].GetUInt32();
4444 m
->checked
= fields
[8].GetUInt32();
4445 m
->mailTemplateId
= fields
[9].GetInt16();
4449 pl
= GetPlayer((uint64
)m
->receiver
);
4450 if (pl
&& pl
->m_mailsLoaded
)
4451 { //this code will run very improbably (the time is between 4 and 5 am, in game is online a player, who has old mail
4452 //his in mailbox and he has already listed his mails )
4456 //delete or return mail:
4459 QueryResult
*resultItems
= CharacterDatabase
.PQuery("SELECT item_guid,item_template FROM mail_items WHERE mail_id='%u'", m
->messageID
);
4464 Field
*fields2
= resultItems
->Fetch();
4466 uint32 item_guid_low
= fields2
[0].GetUInt32();
4467 uint32 item_template
= fields2
[1].GetUInt32();
4469 m
->AddItem(item_guid_low
, item_template
);
4471 while (resultItems
->NextRow());
4475 //if it is mail from AH, it shouldn't be returned, but deleted
4476 if (m
->messageType
!= MAIL_NORMAL
|| (m
->checked
& (MAIL_CHECK_MASK_AUCTION
| MAIL_CHECK_MASK_COD_PAYMENT
| MAIL_CHECK_MASK_RETURNED
)))
4478 // mail open and then not returned
4479 for(std::vector
<MailItemInfo
>::iterator itr2
= m
->items
.begin(); itr2
!= m
->items
.end(); ++itr2
)
4480 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", itr2
->item_guid
);
4484 //mail will be returned:
4485 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
);
4492 CharacterDatabase
.PExecute("DELETE FROM item_text WHERE id = '%u'", m
->itemTextId
);
4494 //deletemail = true;
4495 //delmails << m->messageID << ", ";
4496 CharacterDatabase
.PExecute("DELETE FROM mail WHERE id = '%u'", m
->messageID
);
4499 } while (result
->NextRow());
4503 sLog
.outString( ">> Loaded %u mails", count
);
4506 void ObjectMgr::LoadQuestAreaTriggers()
4508 mQuestAreaTriggerMap
.clear(); // need for reload case
4510 QueryResult
*result
= WorldDatabase
.Query( "SELECT id,quest FROM areatrigger_involvedrelation" );
4520 sLog
.outString( ">> Loaded %u quest trigger points", count
);
4524 barGoLink
bar( result
->GetRowCount() );
4531 Field
*fields
= result
->Fetch();
4533 uint32 trigger_ID
= fields
[0].GetUInt32();
4534 uint32 quest_ID
= fields
[1].GetUInt32();
4536 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(trigger_ID
);
4539 sLog
.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",trigger_ID
);
4543 Quest
const* quest
= GetQuestTemplate(quest_ID
);
4547 sLog
.outErrorDb("Table `areatrigger_involvedrelation` has record (id: %u) for not existing quest %u",trigger_ID
,quest_ID
);
4551 if(!quest
->HasFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
))
4553 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
);
4555 // this will prevent quest completing without objective
4556 const_cast<Quest
*>(quest
)->SetFlag(QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
);
4558 // continue; - quest modified to required objective and trigger can be allowed.
4561 mQuestAreaTriggerMap
[trigger_ID
] = quest_ID
;
4563 } while( result
->NextRow() );
4568 sLog
.outString( ">> Loaded %u quest trigger points", count
);
4571 void ObjectMgr::LoadTavernAreaTriggers()
4573 mTavernAreaTriggerSet
.clear(); // need for reload case
4575 QueryResult
*result
= WorldDatabase
.Query("SELECT id FROM areatrigger_tavern");
4585 sLog
.outString( ">> Loaded %u tavern triggers", count
);
4589 barGoLink
bar( result
->GetRowCount() );
4596 Field
*fields
= result
->Fetch();
4598 uint32 Trigger_ID
= fields
[0].GetUInt32();
4600 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(Trigger_ID
);
4603 sLog
.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID
);
4607 mTavernAreaTriggerSet
.insert(Trigger_ID
);
4608 } while( result
->NextRow() );
4613 sLog
.outString( ">> Loaded %u tavern triggers", count
);
4616 void ObjectMgr::LoadAreaTriggerScripts()
4618 mAreaTriggerScripts
.clear(); // need for reload case
4619 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, ScriptName FROM areatrigger_scripts");
4629 sLog
.outString( ">> Loaded %u areatrigger scripts", count
);
4633 barGoLink
bar( result
->GetRowCount() );
4640 Field
*fields
= result
->Fetch();
4642 uint32 Trigger_ID
= fields
[0].GetUInt32();
4643 const char *scriptName
= fields
[1].GetString();
4645 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(Trigger_ID
);
4648 sLog
.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID
);
4651 mAreaTriggerScripts
[Trigger_ID
] = GetScriptId(scriptName
);
4652 } while( result
->NextRow() );
4657 sLog
.outString( ">> Loaded %u areatrigger scripts", count
);
4660 uint32
ObjectMgr::GetNearestTaxiNode( float x
, float y
, float z
, uint32 mapid
, uint32 team
)
4666 for(uint32 i
= 1; i
< sTaxiNodesStore
.GetNumRows(); ++i
)
4668 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(i
);
4669 if(!node
|| node
->map_id
!= mapid
|| !node
->MountCreatureID
[team
== ALLIANCE
? 1 : 0])
4672 uint8 field
= (uint8
)((i
- 1) / 32);
4673 uint32 submask
= 1<<((i
-1)%32);
4675 // skip not taxi network nodes
4676 if((sTaxiNodesMask
[field
] & submask
)==0)
4679 float dist2
= (node
->x
- x
)*(node
->x
- x
)+(node
->y
- y
)*(node
->y
- y
)+(node
->z
- z
)*(node
->z
- z
);
4699 void ObjectMgr::GetTaxiPath( uint32 source
, uint32 destination
, uint32
&path
, uint32
&cost
)
4701 TaxiPathSetBySource::iterator src_i
= sTaxiPathSetBySource
.find(source
);
4702 if(src_i
==sTaxiPathSetBySource
.end())
4709 TaxiPathSetForSource
& pathSet
= src_i
->second
;
4711 TaxiPathSetForSource::iterator dest_i
= pathSet
.find(destination
);
4712 if(dest_i
==pathSet
.end())
4719 cost
= dest_i
->second
.price
;
4720 path
= dest_i
->second
.ID
;
4723 uint16
ObjectMgr::GetTaxiMount( uint32 id
, uint32 team
, bool allowed_alt_team
/* = false */)
4725 uint16 mount_entry
= 0;
4726 uint16 mount_id
= 0;
4728 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(id
);
4731 if (team
== ALLIANCE
)
4733 mount_entry
= node
->MountCreatureID
[1];
4734 if(!mount_entry
&& allowed_alt_team
)
4735 mount_entry
= node
->MountCreatureID
[0];
4737 CreatureInfo
const *ci
= GetCreatureTemplate(mount_entry
);
4739 mount_id
= ci
->DisplayID_A
;
4743 mount_entry
= node
->MountCreatureID
[0];
4745 if(!mount_entry
&& allowed_alt_team
)
4746 mount_entry
= node
->MountCreatureID
[1];
4748 CreatureInfo
const *ci
= GetCreatureTemplate(mount_entry
);
4750 mount_id
= ci
->DisplayID_H
;
4754 CreatureModelInfo
const *minfo
= GetCreatureModelInfo(mount_id
);
4757 sLog
.outErrorDb("Taxi mount (Entry: %u) for taxi node (Id: %u) for team %u has model %u not found in table `creature_model_info`, can't load. ",
4758 mount_entry
,id
,team
,mount_id
);
4762 if(minfo
->modelid_other_gender
!=0)
4763 mount_id
= urand(0,1) ? mount_id
: minfo
->modelid_other_gender
;
4768 void ObjectMgr::GetTaxiPathNodes( uint32 path
, Path
&pathnodes
, std::vector
<uint32
>& mapIds
)
4770 if(path
>= sTaxiPathNodesByPath
.size())
4773 TaxiPathNodeList
& nodeList
= sTaxiPathNodesByPath
[path
];
4775 pathnodes
.Resize(nodeList
.size());
4776 mapIds
.resize(nodeList
.size());
4778 for(size_t i
= 0; i
< nodeList
.size(); ++i
)
4780 pathnodes
[ i
].x
= nodeList
[i
].x
;
4781 pathnodes
[ i
].y
= nodeList
[i
].y
;
4782 pathnodes
[ i
].z
= nodeList
[i
].z
;
4784 mapIds
[i
] = nodeList
[i
].mapid
;
4788 void ObjectMgr::GetTransportPathNodes( uint32 path
, TransportPath
&pathnodes
)
4790 if(path
>= sTaxiPathNodesByPath
.size())
4793 TaxiPathNodeList
& nodeList
= sTaxiPathNodesByPath
[path
];
4795 pathnodes
.Resize(nodeList
.size());
4797 for(size_t i
= 0; i
< nodeList
.size(); ++i
)
4799 pathnodes
[ i
].mapid
= nodeList
[i
].mapid
;
4800 pathnodes
[ i
].x
= nodeList
[i
].x
;
4801 pathnodes
[ i
].y
= nodeList
[i
].y
;
4802 pathnodes
[ i
].z
= nodeList
[i
].z
;
4803 pathnodes
[ i
].actionFlag
= nodeList
[i
].actionFlag
;
4804 pathnodes
[ i
].delay
= nodeList
[i
].delay
;
4808 void ObjectMgr::LoadGraveyardZones()
4810 mGraveYardMap
.clear(); // need for reload case
4812 QueryResult
*result
= WorldDatabase
.Query("SELECT id,ghost_zone,faction FROM game_graveyard_zone");
4822 sLog
.outString( ">> Loaded %u graveyard-zone links", count
);
4826 barGoLink
bar( result
->GetRowCount() );
4833 Field
*fields
= result
->Fetch();
4835 uint32 safeLocId
= fields
[0].GetUInt32();
4836 uint32 zoneId
= fields
[1].GetUInt32();
4837 uint32 team
= fields
[2].GetUInt32();
4839 WorldSafeLocsEntry
const* entry
= sWorldSafeLocsStore
.LookupEntry(safeLocId
);
4842 sLog
.outErrorDb("Table `game_graveyard_zone` has record for not existing graveyard (WorldSafeLocs.dbc id) %u, skipped.",safeLocId
);
4846 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
4849 sLog
.outErrorDb("Table `game_graveyard_zone` has record for not existing zone id (%u), skipped.",zoneId
);
4853 if(areaEntry
->zone
!= 0)
4855 sLog
.outErrorDb("Table `game_graveyard_zone` has record subzone id (%u) instead of zone, skipped.",zoneId
);
4859 if(team
!=0 && team
!=HORDE
&& team
!=ALLIANCE
)
4861 sLog
.outErrorDb("Table `game_graveyard_zone` has record for non player faction (%u), skipped.",team
);
4865 if(!AddGraveYardLink(safeLocId
,zoneId
,team
,false))
4866 sLog
.outErrorDb("Table `game_graveyard_zone` has a duplicate record for Graveyard (ID: %u) and Zone (ID: %u), skipped.",safeLocId
,zoneId
);
4867 } while( result
->NextRow() );
4872 sLog
.outString( ">> Loaded %u graveyard-zone links", count
);
4875 WorldSafeLocsEntry
const *ObjectMgr::GetClosestGraveYard(float x
, float y
, float z
, uint32 MapId
, uint32 team
)
4877 // search for zone associated closest graveyard
4878 uint32 zoneId
= MapManager::Instance().GetZoneId(MapId
,x
,y
,z
);
4880 // Simulate std. algorithm:
4881 // found some graveyard associated to (ghost_zone,ghost_map)
4883 // if mapId == graveyard.mapId (ghost in plain zone or city or battleground) and search graveyard at same map
4884 // then check faction
4885 // if mapId != graveyard.mapId (ghost in instance) and search any graveyard associated
4886 // then check faction
4887 GraveYardMap::const_iterator graveLow
= mGraveYardMap
.lower_bound(zoneId
);
4888 GraveYardMap::const_iterator graveUp
= mGraveYardMap
.upper_bound(zoneId
);
4889 if(graveLow
==graveUp
)
4891 sLog
.outErrorDb("Table `game_graveyard_zone` incomplete: Zone %u Team %u does not have a linked graveyard.",zoneId
,team
);
4896 bool foundNear
= false;
4898 WorldSafeLocsEntry
const* entryNear
= NULL
;
4900 // at entrance map for corpse map
4901 bool foundEntr
= false;
4903 WorldSafeLocsEntry
const* entryEntr
= NULL
;
4906 WorldSafeLocsEntry
const* entryFar
= NULL
;
4908 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(MapId
);
4910 for(GraveYardMap::const_iterator itr
= graveLow
; itr
!= graveUp
; ++itr
)
4912 GraveYardData
const& data
= itr
->second
;
4914 WorldSafeLocsEntry
const* entry
= sWorldSafeLocsStore
.LookupEntry(data
.safeLocId
);
4917 sLog
.outErrorDb("Table `game_graveyard_zone` has record for not existing graveyard (WorldSafeLocs.dbc id) %u, skipped.",data
.safeLocId
);
4921 // skip enemy faction graveyard
4922 // team == 0 case can be at call from .neargrave
4923 if(data
.team
!= 0 && team
!= 0 && data
.team
!= team
)
4926 // find now nearest graveyard at other map
4927 if(MapId
!= entry
->map_id
)
4929 // if find graveyard at different map from where entrance placed (or no entrance data), use any first
4931 mapEntry
->entrance_map
< 0 ||
4932 mapEntry
->entrance_map
!= entry
->map_id
||
4933 (mapEntry
->entrance_x
== 0 && mapEntry
->entrance_y
== 0))
4935 // not have any corrdinates for check distance anyway
4940 // at entrance map calculate distance (2D);
4941 float dist2
= (entry
->x
- mapEntry
->entrance_x
)*(entry
->x
- mapEntry
->entrance_x
)
4942 +(entry
->y
- mapEntry
->entrance_y
)*(entry
->y
- mapEntry
->entrance_y
);
4945 if(dist2
< distEntr
)
4958 // find now nearest graveyard at same map
4961 float dist2
= (entry
->x
- x
)*(entry
->x
- x
)+(entry
->y
- y
)*(entry
->y
- y
)+(entry
->z
- z
)*(entry
->z
- z
);
4964 if(dist2
< distNear
)
4988 GraveYardData
const* ObjectMgr::FindGraveYardData(uint32 id
, uint32 zoneId
)
4990 GraveYardMap::const_iterator graveLow
= mGraveYardMap
.lower_bound(zoneId
);
4991 GraveYardMap::const_iterator graveUp
= mGraveYardMap
.upper_bound(zoneId
);
4993 for(GraveYardMap::const_iterator itr
= graveLow
; itr
!= graveUp
; ++itr
)
4995 if(itr
->second
.safeLocId
==id
)
4996 return &itr
->second
;
5002 bool ObjectMgr::AddGraveYardLink(uint32 id
, uint32 zoneId
, uint32 team
, bool inDB
)
5004 if(FindGraveYardData(id
,zoneId
))
5007 // add link to loaded data
5009 data
.safeLocId
= id
;
5012 mGraveYardMap
.insert(GraveYardMap::value_type(zoneId
,data
));
5017 WorldDatabase
.PExecuteLog("INSERT INTO game_graveyard_zone ( id,ghost_zone,faction) "
5018 "VALUES ('%u', '%u','%u')",id
,zoneId
,team
);
5024 void ObjectMgr::LoadAreaTriggerTeleports()
5026 mAreaTriggers
.clear(); // need for reload case
5030 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13
5031 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");
5040 sLog
.outString( ">> Loaded %u area trigger teleport definitions", count
);
5044 barGoLink
bar( result
->GetRowCount() );
5048 Field
*fields
= result
->Fetch();
5054 uint32 Trigger_ID
= fields
[0].GetUInt32();
5058 at
.requiredLevel
= fields
[1].GetUInt8();
5059 at
.requiredItem
= fields
[2].GetUInt32();
5060 at
.requiredItem2
= fields
[3].GetUInt32();
5061 at
.heroicKey
= fields
[4].GetUInt32();
5062 at
.heroicKey2
= fields
[5].GetUInt32();
5063 at
.requiredQuest
= fields
[6].GetUInt32();
5064 at
.requiredQuestHeroic
= fields
[7].GetUInt32();
5065 at
.requiredFailedText
= fields
[8].GetCppString();
5066 at
.target_mapId
= fields
[9].GetUInt32();
5067 at
.target_X
= fields
[10].GetFloat();
5068 at
.target_Y
= fields
[11].GetFloat();
5069 at
.target_Z
= fields
[12].GetFloat();
5070 at
.target_Orientation
= fields
[13].GetFloat();
5072 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(Trigger_ID
);
5075 sLog
.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID
);
5081 ItemPrototype
const *pProto
= GetItemPrototype(at
.requiredItem
);
5084 sLog
.outError("Key item %u does not exist for trigger %u, removing key requirement.", at
.requiredItem
, Trigger_ID
);
5085 at
.requiredItem
= 0;
5088 if(at
.requiredItem2
)
5090 ItemPrototype
const *pProto
= GetItemPrototype(at
.requiredItem2
);
5093 sLog
.outError("Second item %u not exist for trigger %u, remove key requirement.", at
.requiredItem2
, Trigger_ID
);
5094 at
.requiredItem2
= 0;
5100 ItemPrototype
const *pProto
= GetItemPrototype(at
.heroicKey
);
5103 sLog
.outError("Heroic key item %u not exist for trigger %u, remove key requirement.", at
.heroicKey
, Trigger_ID
);
5110 ItemPrototype
const *pProto
= GetItemPrototype(at
.heroicKey2
);
5113 sLog
.outError("Heroic second key item %u not exist for trigger %u, remove key requirement.", at
.heroicKey2
, Trigger_ID
);
5118 if(at
.requiredQuest
)
5120 QuestMap::iterator qReqItr
= mQuestTemplates
.find(at
.requiredQuest
);
5121 if(qReqItr
== mQuestTemplates
.end())
5123 sLog
.outErrorDb("Required Quest %u not exist for trigger %u, remove quest done requirement.",at
.requiredQuest
,Trigger_ID
);
5124 at
.requiredQuest
= 0;
5128 if(at
.requiredQuestHeroic
)
5130 QuestMap::iterator qReqItr
= mQuestTemplates
.find(at
.requiredQuestHeroic
);
5131 if(qReqItr
== mQuestTemplates
.end())
5133 sLog
.outErrorDb("Required Quest %u not exist for trigger %u, remove quest done requirement.",at
.requiredQuestHeroic
,Trigger_ID
);
5134 at
.requiredQuestHeroic
= 0;
5138 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(at
.target_mapId
);
5141 sLog
.outErrorDb("Area trigger (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Trigger_ID
,at
.target_mapId
);
5145 if(at
.target_X
==0 && at
.target_Y
==0 && at
.target_Z
==0)
5147 sLog
.outErrorDb("Area trigger (ID:%u) target coordinates not provided.",Trigger_ID
);
5151 mAreaTriggers
[Trigger_ID
] = at
;
5153 } while( result
->NextRow() );
5158 sLog
.outString( ">> Loaded %u area trigger teleport definitions", count
);
5162 * Searches for the areatrigger which teleports players out of the given map
5164 AreaTrigger
const* ObjectMgr::GetGoBackTrigger(uint32 Map
) const
5166 const MapEntry
*mapEntry
= sMapStore
.LookupEntry(Map
);
5167 if(!mapEntry
) return NULL
;
5168 for (AreaTriggerMap::const_iterator itr
= mAreaTriggers
.begin(); itr
!= mAreaTriggers
.end(); ++itr
)
5170 if(itr
->second
.target_mapId
== mapEntry
->entrance_map
)
5172 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(itr
->first
);
5173 if(atEntry
&& atEntry
->mapid
== Map
)
5174 return &itr
->second
;
5181 * Searches for the areatrigger which teleports players to the given map
5183 AreaTrigger
const* ObjectMgr::GetMapEntranceTrigger(uint32 Map
) const
5185 for (AreaTriggerMap::const_iterator itr
= mAreaTriggers
.begin(); itr
!= mAreaTriggers
.end(); ++itr
)
5187 if(itr
->second
.target_mapId
== Map
)
5189 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(itr
->first
);
5191 return &itr
->second
;
5197 void ObjectMgr::SetHighestGuids()
5199 QueryResult
*result
= CharacterDatabase
.Query( "SELECT MAX(guid) FROM characters" );
5202 m_hiCharGuid
= (*result
)[0].GetUInt32()+1;
5206 result
= WorldDatabase
.Query( "SELECT MAX(guid) FROM creature" );
5209 m_hiCreatureGuid
= (*result
)[0].GetUInt32()+1;
5213 result
= CharacterDatabase
.Query( "SELECT MAX(guid) FROM item_instance" );
5216 m_hiItemGuid
= (*result
)[0].GetUInt32()+1;
5220 // Cleanup other tables from not existed guids (>=m_hiItemGuid)
5221 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", m_hiItemGuid
);
5222 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE item_guid >= '%u'", m_hiItemGuid
);
5223 CharacterDatabase
.PExecute("DELETE FROM auctionhouse WHERE itemguid >= '%u'", m_hiItemGuid
);
5224 CharacterDatabase
.PExecute("DELETE FROM guild_bank_item WHERE item_guid >= '%u'", m_hiItemGuid
);
5226 result
= WorldDatabase
.Query("SELECT MAX(guid) FROM gameobject" );
5229 m_hiGoGuid
= (*result
)[0].GetUInt32()+1;
5233 result
= CharacterDatabase
.Query("SELECT MAX(id) FROM auctionhouse" );
5236 m_auctionid
= (*result
)[0].GetUInt32()+1;
5240 result
= CharacterDatabase
.Query( "SELECT MAX(id) FROM mail" );
5243 m_mailid
= (*result
)[0].GetUInt32()+1;
5247 result
= CharacterDatabase
.Query( "SELECT MAX(id) FROM item_text" );
5250 m_ItemTextId
= (*result
)[0].GetUInt32()+1;
5254 result
= CharacterDatabase
.Query( "SELECT MAX(guid) FROM corpse" );
5257 m_hiCorpseGuid
= (*result
)[0].GetUInt32()+1;
5261 result
= CharacterDatabase
.Query("SELECT MAX(arenateamid) FROM arena_team");
5264 m_arenaTeamId
= (*result
)[0].GetUInt32()+1;
5268 result
= CharacterDatabase
.Query( "SELECT MAX(guildid) FROM guild" );
5271 m_guildId
= (*result
)[0].GetUInt32()+1;
5276 uint32
ObjectMgr::GenerateArenaTeamId()
5278 if(m_arenaTeamId
>=0xFFFFFFFE)
5280 sLog
.outError("Arena team ids overflow!! Can't continue, shutting down server. ");
5281 World::StopNow(ERROR_EXIT_CODE
);
5283 return m_arenaTeamId
++;
5286 uint32
ObjectMgr::GenerateAuctionID()
5288 if(m_auctionid
>=0xFFFFFFFE)
5290 sLog
.outError("Auctions ids overflow!! Can't continue, shutting down server. ");
5291 World::StopNow(ERROR_EXIT_CODE
);
5293 return m_auctionid
++;
5296 uint32
ObjectMgr::GenerateGuildId()
5298 if(m_guildId
>=0xFFFFFFFE)
5300 sLog
.outError("Guild ids overflow!! Can't continue, shutting down server. ");
5301 World::StopNow(ERROR_EXIT_CODE
);
5306 uint32
ObjectMgr::GenerateMailID()
5308 if(m_mailid
>=0xFFFFFFFE)
5310 sLog
.outError("Mail ids overflow!! Can't continue, shutting down server. ");
5311 World::StopNow(ERROR_EXIT_CODE
);
5316 uint32
ObjectMgr::GenerateItemTextID()
5318 if(m_ItemTextId
>=0xFFFFFFFE)
5320 sLog
.outError("Item text ids overflow!! Can't continue, shutting down server. ");
5321 World::StopNow(ERROR_EXIT_CODE
);
5323 return m_ItemTextId
++;
5326 uint32
ObjectMgr::CreateItemText(std::string text
)
5328 uint32 newItemTextId
= GenerateItemTextID();
5329 //insert new itempage to container
5330 mItemTexts
[ newItemTextId
] = text
;
5332 CharacterDatabase
.escape_string(text
);
5333 //any Delete query needed, itemTextId is maximum of all ids
5334 std::ostringstream query
;
5335 query
<< "INSERT INTO item_text (id,text) VALUES ( '" << newItemTextId
<< "', '" << text
<< "')";
5336 CharacterDatabase
.Execute(query
.str().c_str()); //needs to be run this way, because mail body may be more than 1024 characters
5337 return newItemTextId
;
5340 uint32
ObjectMgr::GenerateLowGuid(HighGuid guidhigh
)
5345 if(m_hiItemGuid
>=0xFFFFFFFE)
5347 sLog
.outError("Item guid overflow!! Can't continue, shutting down server. ");
5348 World::StopNow(ERROR_EXIT_CODE
);
5350 return m_hiItemGuid
++;
5352 if(m_hiCreatureGuid
>=0x00FFFFFE)
5354 sLog
.outError("Creature guid overflow!! Can't continue, shutting down server. ");
5355 World::StopNow(ERROR_EXIT_CODE
);
5357 return m_hiCreatureGuid
++;
5359 if(m_hiPetGuid
>=0x00FFFFFE)
5361 sLog
.outError("Pet guid overflow!! Can't continue, shutting down server. ");
5362 World::StopNow(ERROR_EXIT_CODE
);
5364 return m_hiPetGuid
++;
5365 case HIGHGUID_VEHICLE
:
5366 if(m_hiVehicleGuid
>=0x00FFFFFF)
5368 sLog
.outError("Vehicle guid overflow!! Can't continue, shutting down server. ");
5369 World::StopNow(ERROR_EXIT_CODE
);
5371 return m_hiVehicleGuid
++;
5372 case HIGHGUID_PLAYER
:
5373 if(m_hiCharGuid
>=0xFFFFFFFE)
5375 sLog
.outError("Players guid overflow!! Can't continue, shutting down server. ");
5376 World::StopNow(ERROR_EXIT_CODE
);
5378 return m_hiCharGuid
++;
5379 case HIGHGUID_GAMEOBJECT
:
5380 if(m_hiGoGuid
>=0x00FFFFFE)
5382 sLog
.outError("Gameobject guid overflow!! Can't continue, shutting down server. ");
5383 World::StopNow(ERROR_EXIT_CODE
);
5385 return m_hiGoGuid
++;
5386 case HIGHGUID_CORPSE
:
5387 if(m_hiCorpseGuid
>=0xFFFFFFFE)
5389 sLog
.outError("Corpse guid overflow!! Can't continue, shutting down server. ");
5390 World::StopNow(ERROR_EXIT_CODE
);
5392 return m_hiCorpseGuid
++;
5393 case HIGHGUID_DYNAMICOBJECT
:
5394 if(m_hiDoGuid
>=0xFFFFFFFE)
5396 sLog
.outError("DynamicObject guid overflow!! Can't continue, shutting down server. ");
5397 World::StopNow(ERROR_EXIT_CODE
);
5399 return m_hiDoGuid
++;
5408 void ObjectMgr::LoadGameObjectLocales()
5410 mGameObjectLocaleMap
.clear(); // need for reload case
5412 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,"
5413 "name_loc1,name_loc2,name_loc3,name_loc4,name_loc5,name_loc6,name_loc7,name_loc8,"
5414 "castbarcaption_loc1,castbarcaption_loc2,castbarcaption_loc3,castbarcaption_loc4,"
5415 "castbarcaption_loc5,castbarcaption_loc6,castbarcaption_loc7,castbarcaption_loc8 FROM locales_gameobject");
5424 sLog
.outString(">> Loaded 0 gameobject locale strings. DB table `locales_gameobject` is empty.");
5428 barGoLink
bar(result
->GetRowCount());
5432 Field
*fields
= result
->Fetch();
5435 uint32 entry
= fields
[0].GetUInt32();
5437 GameObjectLocale
& data
= mGameObjectLocaleMap
[entry
];
5439 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
5441 std::string str
= fields
[i
].GetCppString();
5444 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
5447 if(data
.Name
.size() <= idx
)
5448 data
.Name
.resize(idx
+1);
5450 data
.Name
[idx
] = str
;
5455 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
5457 std::string str
= fields
[i
+(MAX_LOCALE
-1)].GetCppString();
5460 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
5463 if(data
.CastBarCaption
.size() <= idx
)
5464 data
.CastBarCaption
.resize(idx
+1);
5466 data
.CastBarCaption
[idx
] = str
;
5471 } while (result
->NextRow());
5476 sLog
.outString( ">> Loaded %lu gameobject locale strings", (unsigned long)mGameObjectLocaleMap
.size() );
5479 struct SQLGameObjectLoader
: public SQLStorageLoaderBase
<SQLGameObjectLoader
>
5482 void convert_from_str(uint32
/*field_pos*/, char *src
, D
&dst
)
5484 dst
= D(objmgr
.GetScriptId(src
));
5488 inline void CheckGOLockId(GameObjectInfo
const* goInfo
,uint32 dataN
,uint32 N
)
5490 if (sLockStore
.LookupEntry(dataN
))
5493 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but lock (Id: %u) not found.",
5494 goInfo
->id
,goInfo
->type
,N
,goInfo
->door
.lockId
,goInfo
->door
.lockId
);
5497 inline void CheckGOLinkedTrapId(GameObjectInfo
const* goInfo
,uint32 dataN
,uint32 N
)
5499 if (GameObjectInfo
const* trapInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(dataN
))
5501 if (trapInfo
->type
!=GAMEOBJECT_TYPE_TRAP
)
5502 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but GO (Entry %u) have not GAMEOBJECT_TYPE_TRAP (%u) type.",
5503 goInfo
->id
,goInfo
->type
,N
,dataN
,dataN
,GAMEOBJECT_TYPE_TRAP
);
5505 /* disable check for while (too many error reports baout not existed in trap templates
5507 sLog.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but trap GO (Entry %u) not exist in `gameobject_template`.",
5508 goInfo->id,goInfo->type,N,dataN,dataN);
5512 inline void CheckGOSpellId(GameObjectInfo
const* goInfo
,uint32 dataN
,uint32 N
)
5514 if (sSpellStore
.LookupEntry(dataN
))
5517 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but Spell (Entry %u) not exist.",
5518 goInfo
->id
,goInfo
->type
,N
,dataN
,dataN
);
5521 inline void CheckAndFixGOChairHeightId(GameObjectInfo
const* goInfo
,uint32
const& dataN
,uint32 N
)
5523 if (dataN
<= (UNIT_STAND_STATE_SIT_HIGH_CHAIR
-UNIT_STAND_STATE_SIT_LOW_CHAIR
) )
5526 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but correct chair height in range 0..%i.",
5527 goInfo
->id
,goInfo
->type
,N
,dataN
,UNIT_STAND_STATE_SIT_HIGH_CHAIR
-UNIT_STAND_STATE_SIT_LOW_CHAIR
);
5529 // prevent client and server unexpected work
5530 const_cast<uint32
&>(dataN
) = 0;
5533 inline void CheckGONoDamageImmuneId(GameObjectInfo
const* goInfo
,uint32 dataN
,uint32 N
)
5535 // 0/1 correct values
5539 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but expected boolean (0/1) noDamageImmune field value.",
5540 goInfo
->id
,goInfo
->type
,N
,dataN
);
5543 void ObjectMgr::LoadGameobjectInfo()
5545 SQLGameObjectLoader loader
;
5546 loader
.Load(sGOStorage
);
5549 for(uint32 id
= 1; id
< sGOStorage
.MaxEntry
; id
++)
5551 GameObjectInfo
const* goInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
5555 switch(goInfo
->type
)
5557 case GAMEOBJECT_TYPE_DOOR
: //0
5559 if (goInfo
->door
.lockId
)
5560 CheckGOLockId(goInfo
,goInfo
->door
.lockId
,1);
5561 CheckGONoDamageImmuneId(goInfo
,goInfo
->door
.noDamageImmune
,3);
5564 case GAMEOBJECT_TYPE_BUTTON
: //1
5566 if (goInfo
->button
.lockId
)
5567 CheckGOLockId(goInfo
,goInfo
->button
.lockId
,1);
5568 CheckGONoDamageImmuneId(goInfo
,goInfo
->button
.noDamageImmune
,4);
5571 case GAMEOBJECT_TYPE_QUESTGIVER
: //2
5573 if (goInfo
->questgiver
.lockId
)
5574 CheckGOLockId(goInfo
,goInfo
->questgiver
.lockId
,0);
5575 CheckGONoDamageImmuneId(goInfo
,goInfo
->questgiver
.noDamageImmune
,5);
5578 case GAMEOBJECT_TYPE_CHEST
: //3
5580 if (goInfo
->chest
.lockId
)
5581 CheckGOLockId(goInfo
,goInfo
->chest
.lockId
,0);
5583 if (goInfo
->chest
.linkedTrapId
) // linked trap
5584 CheckGOLinkedTrapId(goInfo
,goInfo
->chest
.linkedTrapId
,7);
5587 case GAMEOBJECT_TYPE_TRAP
: //6
5589 if (goInfo
->trap
.lockId
)
5590 CheckGOLockId(goInfo
,goInfo
->trap
.lockId
,0);
5591 /* disable check for while, too many not existed spells
5592 if (goInfo->trap.spellId) // spell
5593 CheckGOSpellId(goInfo,goInfo->trap.spellId,3);
5597 case GAMEOBJECT_TYPE_CHAIR
: //7
5598 CheckAndFixGOChairHeightId(goInfo
,goInfo
->chair
.height
,1);
5600 case GAMEOBJECT_TYPE_SPELL_FOCUS
: //8
5602 if (goInfo
->spellFocus
.focusId
)
5604 if (!sSpellFocusObjectStore
.LookupEntry(goInfo
->spellFocus
.focusId
))
5605 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data0=%u but SpellFocus (Id: %u) not exist.",
5606 id
,goInfo
->type
,goInfo
->spellFocus
.focusId
,goInfo
->spellFocus
.focusId
);
5609 if (goInfo
->spellFocus
.linkedTrapId
) // linked trap
5610 CheckGOLinkedTrapId(goInfo
,goInfo
->spellFocus
.linkedTrapId
,2);
5613 case GAMEOBJECT_TYPE_GOOBER
: //10
5615 if (goInfo
->goober
.lockId
)
5616 CheckGOLockId(goInfo
,goInfo
->goober
.lockId
,0);
5618 if (goInfo
->goober
.pageId
) // pageId
5620 if (!sPageTextStore
.LookupEntry
<PageText
>(goInfo
->goober
.pageId
))
5621 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data7=%u but PageText (Entry %u) not exist.",
5622 id
,goInfo
->type
,goInfo
->goober
.pageId
,goInfo
->goober
.pageId
);
5624 /* disable check for while, too many not existed spells
5625 if (goInfo->goober.spellId) // spell
5626 CheckGOSpellId(goInfo,goInfo->goober.spellId,10);
5628 CheckGONoDamageImmuneId(goInfo
,goInfo
->goober
.noDamageImmune
,11);
5629 if (goInfo
->goober
.linkedTrapId
) // linked trap
5630 CheckGOLinkedTrapId(goInfo
,goInfo
->goober
.linkedTrapId
,12);
5633 case GAMEOBJECT_TYPE_AREADAMAGE
: //12
5635 if (goInfo
->areadamage
.lockId
)
5636 CheckGOLockId(goInfo
,goInfo
->areadamage
.lockId
,0);
5639 case GAMEOBJECT_TYPE_CAMERA
: //13
5641 if (goInfo
->camera
.lockId
)
5642 CheckGOLockId(goInfo
,goInfo
->camera
.lockId
,0);
5645 case GAMEOBJECT_TYPE_MO_TRANSPORT
: //15
5647 if (goInfo
->moTransport
.taxiPathId
)
5649 if (goInfo
->moTransport
.taxiPathId
>= sTaxiPathNodesByPath
.size() || sTaxiPathNodesByPath
[goInfo
->moTransport
.taxiPathId
].empty())
5650 sLog
.outErrorDb("Gameobject (Entry: %u GoType: %u) have data0=%u but TaxiPath (Id: %u) not exist.",
5651 id
,goInfo
->type
,goInfo
->moTransport
.taxiPathId
,goInfo
->moTransport
.taxiPathId
);
5655 case GAMEOBJECT_TYPE_SUMMONING_RITUAL
: //18
5657 /* disable check for while, too many not existed spells
5658 // always must have spell
5659 CheckGOSpellId(goInfo,goInfo->summoningRitual.spellId,1);
5663 case GAMEOBJECT_TYPE_SPELLCASTER
: //22
5665 // always must have spell
5666 CheckGOSpellId(goInfo
,goInfo
->spellcaster
.spellId
,0);
5669 case GAMEOBJECT_TYPE_FLAGSTAND
: //24
5671 if (goInfo
->flagstand
.lockId
)
5672 CheckGOLockId(goInfo
,goInfo
->flagstand
.lockId
,0);
5673 CheckGONoDamageImmuneId(goInfo
,goInfo
->flagstand
.noDamageImmune
,5);
5676 case GAMEOBJECT_TYPE_FISHINGHOLE
: //25
5678 if (goInfo
->fishinghole
.lockId
)
5679 CheckGOLockId(goInfo
,goInfo
->fishinghole
.lockId
,4);
5682 case GAMEOBJECT_TYPE_FLAGDROP
: //26
5684 if (goInfo
->flagdrop
.lockId
)
5685 CheckGOLockId(goInfo
,goInfo
->flagdrop
.lockId
,0);
5686 CheckGONoDamageImmuneId(goInfo
,goInfo
->flagdrop
.noDamageImmune
,3);
5689 case GAMEOBJECT_TYPE_BARBER_CHAIR
: //32
5690 CheckAndFixGOChairHeightId(goInfo
,goInfo
->barberChair
.chairheight
,0);
5695 sLog
.outString( ">> Loaded %u game object templates", sGOStorage
.RecordCount
);
5699 void ObjectMgr::LoadExplorationBaseXP()
5702 QueryResult
*result
= WorldDatabase
.Query("SELECT level,basexp FROM exploration_basexp");
5711 sLog
.outString( ">> Loaded %u BaseXP definitions", count
);
5715 barGoLink
bar( result
->GetRowCount() );
5721 Field
*fields
= result
->Fetch();
5722 uint32 level
= fields
[0].GetUInt32();
5723 uint32 basexp
= fields
[1].GetUInt32();
5724 mBaseXPTable
[level
] = basexp
;
5727 while (result
->NextRow());
5732 sLog
.outString( ">> Loaded %u BaseXP definitions", count
);
5735 uint32
ObjectMgr::GetBaseXP(uint32 level
)
5737 return mBaseXPTable
[level
] ? mBaseXPTable
[level
] : 0;
5740 uint32
ObjectMgr::GetXPForLevel(uint32 level
)
5742 if (level
< mPlayerXPperLevel
.size())
5743 return mPlayerXPperLevel
[level
];
5747 void ObjectMgr::LoadPetNames()
5750 QueryResult
*result
= WorldDatabase
.Query("SELECT word,entry,half FROM pet_name_generation");
5759 sLog
.outString( ">> Loaded %u pet name parts", count
);
5763 barGoLink
bar( result
->GetRowCount() );
5769 Field
*fields
= result
->Fetch();
5770 std::string word
= fields
[0].GetString();
5771 uint32 entry
= fields
[1].GetUInt32();
5772 bool half
= fields
[2].GetBool();
5774 PetHalfName1
[entry
].push_back(word
);
5776 PetHalfName0
[entry
].push_back(word
);
5779 while (result
->NextRow());
5783 sLog
.outString( ">> Loaded %u pet name parts", count
);
5786 void ObjectMgr::LoadPetNumber()
5788 QueryResult
* result
= CharacterDatabase
.Query("SELECT MAX(id) FROM character_pet");
5791 Field
*fields
= result
->Fetch();
5792 m_hiPetNumber
= fields
[0].GetUInt32()+1;
5800 sLog
.outString( ">> Loaded the max pet number: %d", m_hiPetNumber
-1);
5803 std::string
ObjectMgr::GeneratePetName(uint32 entry
)
5805 std::vector
<std::string
> & list0
= PetHalfName0
[entry
];
5806 std::vector
<std::string
> & list1
= PetHalfName1
[entry
];
5808 if(list0
.empty() || list1
.empty())
5810 CreatureInfo
const *cinfo
= GetCreatureTemplate(entry
);
5811 char* petname
= GetPetName(cinfo
->family
, sWorld
.GetDefaultDbcLocale());
5813 petname
= cinfo
->Name
;
5814 return std::string(petname
);
5817 return *(list0
.begin()+urand(0, list0
.size()-1)) + *(list1
.begin()+urand(0, list1
.size()-1));
5820 uint32
ObjectMgr::GeneratePetNumber()
5822 return ++m_hiPetNumber
;
5825 void ObjectMgr::LoadCorpses()
5828 // 0 1 2 3 4 5 6 7 8 10
5829 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");
5838 sLog
.outString( ">> Loaded %u corpses", count
);
5842 barGoLink
bar( result
->GetRowCount() );
5848 Field
*fields
= result
->Fetch();
5850 uint32 guid
= fields
[result
->GetFieldCount()-1].GetUInt32();
5852 Corpse
*corpse
= new Corpse
;
5853 if(!corpse
->LoadFromDB(guid
,fields
))
5859 ObjectAccessor::Instance().AddCorpse(corpse
);
5863 while (result
->NextRow());
5867 sLog
.outString( ">> Loaded %u corpses", count
);
5870 void ObjectMgr::LoadReputationOnKill()
5875 QueryResult
*result
= WorldDatabase
.Query("SELECT creature_id, RewOnKillRepFaction1, RewOnKillRepFaction2,"
5877 "IsTeamAward1, MaxStanding1, RewOnKillRepValue1, IsTeamAward2, MaxStanding2, RewOnKillRepValue2, TeamDependent "
5878 "FROM creature_onkill_reputation");
5887 sLog
.outErrorDb(">> Loaded 0 creature award reputation definitions. DB table `creature_onkill_reputation` is empty.");
5891 barGoLink
bar(result
->GetRowCount());
5895 Field
*fields
= result
->Fetch();
5898 uint32 creature_id
= fields
[0].GetUInt32();
5900 ReputationOnKillEntry repOnKill
;
5901 repOnKill
.repfaction1
= fields
[1].GetUInt32();
5902 repOnKill
.repfaction2
= fields
[2].GetUInt32();
5903 repOnKill
.is_teamaward1
= fields
[3].GetBool();
5904 repOnKill
.reputation_max_cap1
= fields
[4].GetUInt32();
5905 repOnKill
.repvalue1
= fields
[5].GetInt32();
5906 repOnKill
.is_teamaward2
= fields
[6].GetBool();
5907 repOnKill
.reputation_max_cap2
= fields
[7].GetUInt32();
5908 repOnKill
.repvalue2
= fields
[8].GetInt32();
5909 repOnKill
.team_dependent
= fields
[9].GetUInt8();
5911 if(!GetCreatureTemplate(creature_id
))
5913 sLog
.outErrorDb("Table `creature_onkill_reputation` have data for not existed creature entry (%u), skipped",creature_id
);
5917 if(repOnKill
.repfaction1
)
5919 FactionEntry
const *factionEntry1
= sFactionStore
.LookupEntry(repOnKill
.repfaction1
);
5922 sLog
.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `creature_onkill_reputation`",repOnKill
.repfaction1
);
5927 if(repOnKill
.repfaction2
)
5929 FactionEntry
const *factionEntry2
= sFactionStore
.LookupEntry(repOnKill
.repfaction2
);
5932 sLog
.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `creature_onkill_reputation`",repOnKill
.repfaction2
);
5937 mRepOnKill
[creature_id
] = repOnKill
;
5940 } while (result
->NextRow());
5945 sLog
.outString(">> Loaded %u creature award reputation definitions", count
);
5948 void ObjectMgr::LoadPointsOfInterest()
5953 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, x, y, icon, flags, data, icon_name FROM points_of_interest");
5962 sLog
.outErrorDb(">> Loaded 0 Points of Interest definitions. DB table `points_of_interest` is empty.");
5966 barGoLink
bar(result
->GetRowCount());
5970 Field
*fields
= result
->Fetch();
5973 uint32 point_id
= fields
[0].GetUInt32();
5975 PointOfInterest POI
;
5976 POI
.x
= fields
[1].GetFloat();
5977 POI
.y
= fields
[2].GetFloat();
5978 POI
.icon
= fields
[3].GetUInt32();
5979 POI
.flags
= fields
[4].GetUInt32();
5980 POI
.data
= fields
[5].GetUInt32();
5981 POI
.icon_name
= fields
[6].GetCppString();
5983 if(!MaNGOS::IsValidMapCoord(POI
.x
,POI
.y
))
5985 sLog
.outErrorDb("Table `points_of_interest` (Entry: %u) have invalid coordinates (X: %f Y: %f), ignored.",point_id
,POI
.x
,POI
.y
);
5989 mPointsOfInterest
[point_id
] = POI
;
5992 } while (result
->NextRow());
5997 sLog
.outString(">> Loaded %u Points of Interest definitions", count
);
6000 void ObjectMgr::LoadNPCSpellClickSpells()
6004 mSpellClickInfoMap
.clear();
6006 QueryResult
*result
= WorldDatabase
.Query("SELECT npc_entry, spell_id, quest_id, cast_flags FROM npc_spellclick_spells");
6015 sLog
.outErrorDb(">> Loaded 0 spellclick spells. DB table `npc_spellclick_spells` is empty.");
6019 barGoLink
bar(result
->GetRowCount());
6023 Field
*fields
= result
->Fetch();
6026 uint32 npc_entry
= fields
[0].GetUInt32();
6027 CreatureInfo
const* cInfo
= GetCreatureTemplate(npc_entry
);
6030 sLog
.outErrorDb("Table npc_spellclick_spells references unknown creature_template %u. Skipping entry.", npc_entry
);
6034 uint32 spellid
= fields
[1].GetUInt32();
6035 SpellEntry
const *spellinfo
= sSpellStore
.LookupEntry(spellid
);
6038 sLog
.outErrorDb("Table npc_spellclick_spells references unknown spellid %u. Skipping entry.", spellid
);
6042 uint32 quest
= fields
[2].GetUInt32();
6044 // quest might be 0 to enable spellclick independent of any quest
6047 if(mQuestTemplates
.find(quest
) == mQuestTemplates
.end())
6049 sLog
.outErrorDb("Table npc_spellclick_spells references unknown quest %u. Skipping entry.", spellid
);
6055 uint8 castFlags
= fields
[3].GetUInt8();
6056 SpellClickInfo info
;
6057 info
.spellId
= spellid
;
6058 info
.questId
= quest
;
6059 info
.castFlags
= castFlags
;
6060 mSpellClickInfoMap
.insert(SpellClickInfoMap::value_type(npc_entry
, info
));
6062 } while (result
->NextRow());
6067 sLog
.outString(">> Loaded %u spellclick definitions", count
);
6070 void ObjectMgr::LoadWeatherZoneChances()
6074 // 0 1 2 3 4 5 6 7 8 9 10 11 12
6075 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");
6084 sLog
.outErrorDb(">> Loaded 0 weather definitions. DB table `game_weather` is empty.");
6088 barGoLink
bar(result
->GetRowCount());
6092 Field
*fields
= result
->Fetch();
6095 uint32 zone_id
= fields
[0].GetUInt32();
6097 WeatherZoneChances
& wzc
= mWeatherZoneMap
[zone_id
];
6099 for(int season
= 0; season
< WEATHER_SEASONS
; ++season
)
6101 wzc
.data
[season
].rainChance
= fields
[season
* (MAX_WEATHER_TYPE
-1) + 1].GetUInt32();
6102 wzc
.data
[season
].snowChance
= fields
[season
* (MAX_WEATHER_TYPE
-1) + 2].GetUInt32();
6103 wzc
.data
[season
].stormChance
= fields
[season
* (MAX_WEATHER_TYPE
-1) + 3].GetUInt32();
6105 if(wzc
.data
[season
].rainChance
> 100)
6107 wzc
.data
[season
].rainChance
= 25;
6108 sLog
.outErrorDb("Weather for zone %u season %u has wrong rain chance > 100%%",zone_id
,season
);
6111 if(wzc
.data
[season
].snowChance
> 100)
6113 wzc
.data
[season
].snowChance
= 25;
6114 sLog
.outErrorDb("Weather for zone %u season %u has wrong snow chance > 100%%",zone_id
,season
);
6117 if(wzc
.data
[season
].stormChance
> 100)
6119 wzc
.data
[season
].stormChance
= 25;
6120 sLog
.outErrorDb("Weather for zone %u season %u has wrong storm chance > 100%%",zone_id
,season
);
6125 } while (result
->NextRow());
6130 sLog
.outString(">> Loaded %u weather definitions", count
);
6133 void ObjectMgr::SaveCreatureRespawnTime(uint32 loguid
, uint32 instance
, time_t t
)
6135 mCreatureRespawnTimes
[MAKE_PAIR64(loguid
,instance
)] = t
;
6136 WorldDatabase
.PExecute("DELETE FROM creature_respawn WHERE guid = '%u' AND instance = '%u'", loguid
, instance
);
6138 WorldDatabase
.PExecute("INSERT INTO creature_respawn VALUES ( '%u', '" UI64FMTD
"', '%u' )", loguid
, uint64(t
), instance
);
6141 void ObjectMgr::DeleteCreatureData(uint32 guid
)
6143 // remove mapid*cellid -> guid_set map
6144 CreatureData
const* data
= GetCreatureData(guid
);
6146 RemoveCreatureFromGrid(guid
, data
);
6148 mCreatureDataMap
.erase(guid
);
6151 void ObjectMgr::SaveGORespawnTime(uint32 loguid
, uint32 instance
, time_t t
)
6153 mGORespawnTimes
[MAKE_PAIR64(loguid
,instance
)] = t
;
6154 WorldDatabase
.PExecute("DELETE FROM gameobject_respawn WHERE guid = '%u' AND instance = '%u'", loguid
, instance
);
6156 WorldDatabase
.PExecute("INSERT INTO gameobject_respawn VALUES ( '%u', '" UI64FMTD
"', '%u' )", loguid
, uint64(t
), instance
);
6159 void ObjectMgr::DeleteRespawnTimeForInstance(uint32 instance
)
6161 RespawnTimes::iterator next
;
6163 for(RespawnTimes::iterator itr
= mGORespawnTimes
.begin(); itr
!= mGORespawnTimes
.end(); itr
= next
)
6168 if(GUID_HIPART(itr
->first
)==instance
)
6169 mGORespawnTimes
.erase(itr
);
6172 for(RespawnTimes::iterator itr
= mCreatureRespawnTimes
.begin(); itr
!= mCreatureRespawnTimes
.end(); itr
= next
)
6177 if(GUID_HIPART(itr
->first
)==instance
)
6178 mCreatureRespawnTimes
.erase(itr
);
6181 WorldDatabase
.PExecute("DELETE FROM creature_respawn WHERE instance = '%u'", instance
);
6182 WorldDatabase
.PExecute("DELETE FROM gameobject_respawn WHERE instance = '%u'", instance
);
6185 void ObjectMgr::DeleteGOData(uint32 guid
)
6187 // remove mapid*cellid -> guid_set map
6188 GameObjectData
const* data
= GetGOData(guid
);
6190 RemoveGameobjectFromGrid(guid
, data
);
6192 mGameObjectDataMap
.erase(guid
);
6195 void ObjectMgr::AddCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
, uint32 instance
)
6197 // corpses are always added to spawn mode 0 and they are spawned by their instance id
6198 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(mapid
,0)][cellid
];
6199 cell_guids
.corpses
[player_guid
] = instance
;
6202 void ObjectMgr::DeleteCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
)
6204 // corpses are always added to spawn mode 0 and they are spawned by their instance id
6205 CellObjectGuids
& cell_guids
= mMapObjectGuids
[MAKE_PAIR32(mapid
,0)][cellid
];
6206 cell_guids
.corpses
.erase(player_guid
);
6209 void ObjectMgr::LoadQuestRelationsHelper(QuestRelations
& map
,char const* table
)
6211 map
.clear(); // need for reload case
6215 QueryResult
*result
= WorldDatabase
.PQuery("SELECT id,quest FROM %s",table
);
6224 sLog
.outErrorDb(">> Loaded 0 quest relations from %s. DB table `%s` is empty.",table
,table
);
6228 barGoLink
bar(result
->GetRowCount());
6232 Field
*fields
= result
->Fetch();
6235 uint32 id
= fields
[0].GetUInt32();
6236 uint32 quest
= fields
[1].GetUInt32();
6238 if(mQuestTemplates
.find(quest
) == mQuestTemplates
.end())
6240 sLog
.outErrorDb("Table `%s: Quest %u listed for entry %u does not exist.",table
,quest
,id
);
6244 map
.insert(QuestRelations::value_type(id
,quest
));
6247 } while (result
->NextRow());
6252 sLog
.outString(">> Loaded %u quest relations from %s", count
,table
);
6255 void ObjectMgr::LoadGameobjectQuestRelations()
6257 LoadQuestRelationsHelper(mGOQuestRelations
,"gameobject_questrelation");
6259 for(QuestRelations::iterator itr
= mGOQuestRelations
.begin(); itr
!= mGOQuestRelations
.end(); ++itr
)
6261 GameObjectInfo
const* goInfo
= GetGameObjectInfo(itr
->first
);
6263 sLog
.outErrorDb("Table `gameobject_questrelation` have data for not existed gameobject entry (%u) and existed quest %u",itr
->first
,itr
->second
);
6264 else if(goInfo
->type
!= GAMEOBJECT_TYPE_QUESTGIVER
)
6265 sLog
.outErrorDb("Table `gameobject_questrelation` have data gameobject entry (%u) for quest %u, but GO is not GAMEOBJECT_TYPE_QUESTGIVER",itr
->first
,itr
->second
);
6269 void ObjectMgr::LoadGameobjectInvolvedRelations()
6271 LoadQuestRelationsHelper(mGOQuestInvolvedRelations
,"gameobject_involvedrelation");
6273 for(QuestRelations::iterator itr
= mGOQuestInvolvedRelations
.begin(); itr
!= mGOQuestInvolvedRelations
.end(); ++itr
)
6275 GameObjectInfo
const* goInfo
= GetGameObjectInfo(itr
->first
);
6277 sLog
.outErrorDb("Table `gameobject_involvedrelation` have data for not existed gameobject entry (%u) and existed quest %u",itr
->first
,itr
->second
);
6278 else if(goInfo
->type
!= GAMEOBJECT_TYPE_QUESTGIVER
)
6279 sLog
.outErrorDb("Table `gameobject_involvedrelation` have data gameobject entry (%u) for quest %u, but GO is not GAMEOBJECT_TYPE_QUESTGIVER",itr
->first
,itr
->second
);
6283 void ObjectMgr::LoadCreatureQuestRelations()
6285 LoadQuestRelationsHelper(mCreatureQuestRelations
,"creature_questrelation");
6287 for(QuestRelations::iterator itr
= mCreatureQuestRelations
.begin(); itr
!= mCreatureQuestRelations
.end(); ++itr
)
6289 CreatureInfo
const* cInfo
= GetCreatureTemplate(itr
->first
);
6291 sLog
.outErrorDb("Table `creature_questrelation` have data for not existed creature entry (%u) and existed quest %u",itr
->first
,itr
->second
);
6292 else if(!(cInfo
->npcflag
& UNIT_NPC_FLAG_QUESTGIVER
))
6293 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
);
6297 void ObjectMgr::LoadCreatureInvolvedRelations()
6299 LoadQuestRelationsHelper(mCreatureQuestInvolvedRelations
,"creature_involvedrelation");
6301 for(QuestRelations::iterator itr
= mCreatureQuestInvolvedRelations
.begin(); itr
!= mCreatureQuestInvolvedRelations
.end(); ++itr
)
6303 CreatureInfo
const* cInfo
= GetCreatureTemplate(itr
->first
);
6305 sLog
.outErrorDb("Table `creature_involvedrelation` have data for not existed creature entry (%u) and existed quest %u",itr
->first
,itr
->second
);
6306 else if(!(cInfo
->npcflag
& UNIT_NPC_FLAG_QUESTGIVER
))
6307 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
);
6311 void ObjectMgr::LoadReservedPlayersNames()
6313 m_ReservedNames
.clear(); // need for reload case
6315 QueryResult
*result
= WorldDatabase
.Query("SELECT name FROM reserved_name");
6325 sLog
.outString( ">> Loaded %u reserved player names", count
);
6329 barGoLink
bar( result
->GetRowCount() );
6335 fields
= result
->Fetch();
6336 std::string name
= fields
[0].GetCppString();
6339 if(!Utf8toWStr (name
,wstr
))
6341 sLog
.outError("Table `reserved_name` have invalid name: %s", name
.c_str() );
6347 m_ReservedNames
.insert(wstr
);
6349 } while ( result
->NextRow() );
6354 sLog
.outString( ">> Loaded %u reserved player names", count
);
6357 bool ObjectMgr::IsReservedName( const std::string
& name
) const
6360 if(!Utf8toWStr (name
,wstr
))
6365 return m_ReservedNames
.find(wstr
) != m_ReservedNames
.end();
6370 LT_BASIC_LATIN
= 0x0000,
6371 LT_EXTENDEN_LATIN
= 0x0001,
6372 LT_CYRILLIC
= 0x0002,
6373 LT_EAST_ASIA
= 0x0004,
6377 static LanguageType
GetRealmLanguageType(bool create
)
6379 switch(sWorld
.getConfig(CONFIG_REALM_ZONE
))
6381 case REALM_ZONE_UNKNOWN
: // any language
6382 case REALM_ZONE_DEVELOPMENT
:
6383 case REALM_ZONE_TEST_SERVER
:
6384 case REALM_ZONE_QA_SERVER
:
6386 case REALM_ZONE_UNITED_STATES
: // extended-Latin
6387 case REALM_ZONE_OCEANIC
:
6388 case REALM_ZONE_LATIN_AMERICA
:
6389 case REALM_ZONE_ENGLISH
:
6390 case REALM_ZONE_GERMAN
:
6391 case REALM_ZONE_FRENCH
:
6392 case REALM_ZONE_SPANISH
:
6393 return LT_EXTENDEN_LATIN
;
6394 case REALM_ZONE_KOREA
: // East-Asian
6395 case REALM_ZONE_TAIWAN
:
6396 case REALM_ZONE_CHINA
:
6397 return LT_EAST_ASIA
;
6398 case REALM_ZONE_RUSSIAN
: // Cyrillic
6401 return create
? LT_BASIC_LATIN
: LT_ANY
; // basic-Latin at create, any at login
6405 bool isValidString(std::wstring wstr
, uint32 strictMask
, bool numericOrSpace
, bool create
= false)
6407 if(strictMask
==0) // any language, ignore realm
6409 if(isExtendedLatinString(wstr
,numericOrSpace
))
6411 if(isCyrillicString(wstr
,numericOrSpace
))
6413 if(isEastAsianString(wstr
,numericOrSpace
))
6418 if(strictMask
& 0x2) // realm zone specific
6420 LanguageType lt
= GetRealmLanguageType(create
);
6421 if(lt
& LT_EXTENDEN_LATIN
)
6422 if(isExtendedLatinString(wstr
,numericOrSpace
))
6424 if(lt
& LT_CYRILLIC
)
6425 if(isCyrillicString(wstr
,numericOrSpace
))
6427 if(lt
& LT_EAST_ASIA
)
6428 if(isEastAsianString(wstr
,numericOrSpace
))
6432 if(strictMask
& 0x1) // basic Latin
6434 if(isBasicLatinString(wstr
,numericOrSpace
))
6441 bool ObjectMgr::IsValidName( const std::string
& name
, bool create
)
6444 if(!Utf8toWStr(name
,wname
))
6447 if(wname
.size() < 1 || wname
.size() > MAX_PLAYER_NAME
)
6450 uint32 strictMask
= sWorld
.getConfig(CONFIG_STRICT_PLAYER_NAMES
);
6452 return isValidString(wname
,strictMask
,false,create
);
6455 bool ObjectMgr::IsValidCharterName( const std::string
& name
)
6458 if(!Utf8toWStr(name
,wname
))
6461 if(wname
.size() < 1)
6464 uint32 strictMask
= sWorld
.getConfig(CONFIG_STRICT_CHARTER_NAMES
);
6466 return isValidString(wname
,strictMask
,true);
6469 bool ObjectMgr::IsValidPetName( const std::string
& name
)
6472 if(!Utf8toWStr(name
,wname
))
6475 if(wname
.size() < 1)
6478 uint32 strictMask
= sWorld
.getConfig(CONFIG_STRICT_PET_NAMES
);
6480 return isValidString(wname
,strictMask
,false);
6483 int ObjectMgr::GetIndexForLocale( LocaleConstant loc
)
6485 if(loc
==LOCALE_enUS
)
6488 for(size_t i
=0;i
< m_LocalForIndex
.size(); ++i
)
6489 if(m_LocalForIndex
[i
]==loc
)
6495 LocaleConstant
ObjectMgr::GetLocaleForIndex(int i
)
6497 if (i
<0 || i
>=m_LocalForIndex
.size())
6500 return m_LocalForIndex
[i
];
6503 int ObjectMgr::GetOrNewIndexForLocale( LocaleConstant loc
)
6505 if(loc
==LOCALE_enUS
)
6508 for(size_t i
=0;i
< m_LocalForIndex
.size(); ++i
)
6509 if(m_LocalForIndex
[i
]==loc
)
6512 m_LocalForIndex
.push_back(loc
);
6513 return m_LocalForIndex
.size()-1;
6516 void ObjectMgr::LoadGameObjectForQuests()
6518 mGameObjectForQuestSet
.clear(); // need for reload case
6520 if( !sGOStorage
.MaxEntry
)
6525 sLog
.outString( ">> Loaded 0 GameObjects for quests" );
6529 barGoLink
bar( sGOStorage
.MaxEntry
- 1 );
6532 // collect GO entries for GO that must activated
6533 for(uint32 go_entry
= 1; go_entry
< sGOStorage
.MaxEntry
; ++go_entry
)
6536 GameObjectInfo
const* goInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(go_entry
);
6540 switch(goInfo
->type
)
6542 // scan GO chest with loot including quest items
6543 case GAMEOBJECT_TYPE_CHEST
:
6545 uint32 loot_id
= GameObject::GetLootId(goInfo
);
6547 // find quest loot for GO
6548 if(LootTemplates_Gameobject
.HaveQuestLootFor(loot_id
))
6550 mGameObjectForQuestSet
.insert(go_entry
);
6555 case GAMEOBJECT_TYPE_GOOBER
:
6557 if(goInfo
->goober
.questId
) //quests objects
6559 mGameObjectForQuestSet
.insert(go_entry
);
6570 sLog
.outString( ">> Loaded %u GameObjects for quests", count
);
6573 bool ObjectMgr::LoadMangosStrings(DatabaseType
& db
, char const* table
, int32 min_value
, int32 max_value
)
6575 int32 start_value
= min_value
;
6576 int32 end_value
= max_value
;
6577 // some string can have negative indexes range
6578 if (start_value
< 0)
6580 if (end_value
>= start_value
)
6582 sLog
.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.",table
,min_value
,max_value
);
6586 // real range (max+1,min+1) exaple: (-10,-1000) -> -999...-10+1
6587 std::swap(start_value
,end_value
);
6593 if (start_value
>= end_value
)
6595 sLog
.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.",table
,min_value
,max_value
);
6600 // cleanup affected map part for reloading case
6601 for(MangosStringLocaleMap::iterator itr
= mMangosStringLocaleMap
.begin(); itr
!= mMangosStringLocaleMap
.end();)
6603 if (itr
->first
>= start_value
&& itr
->first
< end_value
)
6604 mMangosStringLocaleMap
.erase(itr
++);
6609 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
);
6618 if (min_value
== MIN_MANGOS_STRING_ID
) // error only in case internal strings
6619 sLog
.outErrorDb(">> Loaded 0 mangos strings. DB table `%s` is empty. Cannot continue.",table
);
6621 sLog
.outString(">> Loaded 0 string templates. DB table `%s` is empty.",table
);
6627 barGoLink
bar(result
->GetRowCount());
6631 Field
*fields
= result
->Fetch();
6634 int32 entry
= fields
[0].GetInt32();
6638 sLog
.outErrorDb("Table `%s` contain reserved entry 0, ignored.",table
);
6641 else if (entry
< start_value
|| entry
>= end_value
)
6643 sLog
.outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table
,entry
,min_value
,max_value
);
6647 MangosStringLocale
& data
= mMangosStringLocaleMap
[entry
];
6649 if (data
.Content
.size() > 0)
6651 sLog
.outErrorDb("Table `%s` contain data for already loaded entry %i (from another table?), ignored.",table
,entry
);
6655 data
.Content
.resize(1);
6658 // 0 -> default, idx in to idx+1
6659 data
.Content
[0] = fields
[1].GetCppString();
6661 for(int i
= 1; i
< MAX_LOCALE
; ++i
)
6663 std::string str
= fields
[i
+1].GetCppString();
6666 int idx
= GetOrNewIndexForLocale(LocaleConstant(i
));
6669 // 0 -> default, idx in to idx+1
6670 if (data
.Content
.size() <= idx
+1)
6671 data
.Content
.resize(idx
+2);
6673 data
.Content
[idx
+1] = str
;
6677 } while (result
->NextRow());
6682 if (min_value
== MIN_MANGOS_STRING_ID
)
6683 sLog
.outString( ">> Loaded %u MaNGOS strings from table %s", count
,table
);
6685 sLog
.outString( ">> Loaded %u string templates from %s", count
,table
);
6690 const char *ObjectMgr::GetMangosString(int32 entry
, int locale_idx
) const
6692 // locale_idx==-1 -> default, locale_idx >= 0 in to idx+1
6693 // Content[0] always exist if exist MangosStringLocale
6694 if(MangosStringLocale
const *msl
= GetMangosStringLocale(entry
))
6696 if(msl
->Content
.size() > locale_idx
+1 && !msl
->Content
[locale_idx
+1].empty())
6697 return msl
->Content
[locale_idx
+1].c_str();
6699 return msl
->Content
[0].c_str();
6703 sLog
.outErrorDb("Entry %i not found in `mangos_string` table.",entry
);
6705 sLog
.outErrorDb("Mangos string entry %i not found in DB.",entry
);
6709 void ObjectMgr::LoadFishingBaseSkillLevel()
6711 mFishingBaseForArea
.clear(); // for reload case
6714 QueryResult
*result
= WorldDatabase
.Query("SELECT entry,skill FROM skill_fishing_base_level");
6723 sLog
.outErrorDb(">> Loaded `skill_fishing_base_level`, table is empty!");
6727 barGoLink
bar( result
->GetRowCount() );
6733 Field
*fields
= result
->Fetch();
6734 uint32 entry
= fields
[0].GetUInt32();
6735 int32 skill
= fields
[1].GetInt32();
6737 AreaTableEntry
const* fArea
= GetAreaEntryByAreaID(entry
);
6740 sLog
.outErrorDb("AreaId %u defined in `skill_fishing_base_level` does not exist",entry
);
6744 mFishingBaseForArea
[entry
] = skill
;
6747 while (result
->NextRow());
6752 sLog
.outString( ">> Loaded %u areas for fishing base skill level", count
);
6755 // Searches for the same condition already in Conditions store
6756 // Returns Id if found, else adds it to Conditions and returns Id
6757 uint16
ObjectMgr::GetConditionId( ConditionType condition
, uint32 value1
, uint32 value2
)
6759 PlayerCondition lc
= PlayerCondition(condition
, value1
, value2
);
6760 for (uint16 i
=0; i
< mConditions
.size(); ++i
)
6762 if (lc
== mConditions
[i
])
6766 mConditions
.push_back(lc
);
6768 if(mConditions
.size() > 0xFFFF)
6770 sLog
.outError("Conditions store overflow! Current and later loaded conditions will ignored!");
6774 return mConditions
.size() - 1;
6777 bool ObjectMgr::CheckDeclinedNames( std::wstring mainpart
, DeclinedName
const& names
)
6779 for(int i
=0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
6782 if(!Utf8toWStr(names
.name
[i
],wname
))
6785 if(mainpart
!=GetMainPartOfName(wname
,i
+1))
6791 uint32
ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id
)
6793 AreaTriggerScriptMap::const_iterator i
= mAreaTriggerScripts
.find(trigger_id
);
6794 if(i
!= mAreaTriggerScripts
.end())
6799 // Checks if player meets the condition
6800 bool PlayerCondition::Meets(Player
const * player
) const
6803 return false; // player not present, return false
6807 case CONDITION_NONE
:
6808 return true; // empty condition, always met
6809 case CONDITION_AURA
:
6810 return player
->HasAura(value1
, value2
);
6811 case CONDITION_ITEM
:
6812 return player
->HasItemCount(value1
, value2
);
6813 case CONDITION_ITEM_EQUIPPED
:
6814 return player
->HasItemOrGemWithIdEquipped(value1
,1);
6815 case CONDITION_ZONEID
:
6816 return player
->GetZoneId() == value1
;
6817 case CONDITION_REPUTATION_RANK
:
6819 FactionEntry
const* faction
= sFactionStore
.LookupEntry(value1
);
6820 return faction
&& player
->GetReputationMgr().GetRank(faction
) >= value2
;
6822 case CONDITION_TEAM
:
6823 return player
->GetTeam() == value1
;
6824 case CONDITION_SKILL
:
6825 return player
->HasSkill(value1
) && player
->GetBaseSkillValue(value1
) >= value2
;
6826 case CONDITION_QUESTREWARDED
:
6827 return player
->GetQuestRewardStatus(value1
);
6828 case CONDITION_QUESTTAKEN
:
6830 QuestStatus status
= player
->GetQuestStatus(value1
);
6831 return (status
== QUEST_STATUS_INCOMPLETE
);
6833 case CONDITION_AD_COMMISSION_AURA
:
6835 Unit::AuraMap
const& auras
= player
->GetAuras();
6836 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
6837 if((itr
->second
->GetSpellProto()->Attributes
& 0x1000010) && itr
->second
->GetSpellProto()->SpellVisual
[0]==3580)
6841 case CONDITION_NO_AURA
:
6842 return !player
->HasAura(value1
, value2
);
6843 case CONDITION_ACTIVE_EVENT
:
6844 return gameeventmgr
.IsActiveEvent(value1
);
6850 // Verification of condition values validity
6851 bool PlayerCondition::IsValid(ConditionType condition
, uint32 value1
, uint32 value2
)
6853 if( condition
>= MAX_CONDITION
) // Wrong condition type
6855 sLog
.outErrorDb("Condition has bad type of %u, skipped ", condition
);
6861 case CONDITION_AURA
:
6863 if(!sSpellStore
.LookupEntry(value1
))
6865 sLog
.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1
);
6870 sLog
.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2
);
6875 case CONDITION_ITEM
:
6877 ItemPrototype
const *proto
= objmgr
.GetItemPrototype(value1
);
6880 sLog
.outErrorDb("Item condition requires to have non existing item (%u), skipped", value1
);
6885 case CONDITION_ITEM_EQUIPPED
:
6887 ItemPrototype
const *proto
= objmgr
.GetItemPrototype(value1
);
6890 sLog
.outErrorDb("ItemEquipped condition requires to have non existing item (%u) equipped, skipped", value1
);
6895 case CONDITION_ZONEID
:
6897 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(value1
);
6900 sLog
.outErrorDb("Zone condition requires to be in non existing area (%u), skipped", value1
);
6903 if(areaEntry
->zone
!= 0)
6905 sLog
.outErrorDb("Zone condition requires to be in area (%u) which is a subzone but zone expected, skipped", value1
);
6910 case CONDITION_REPUTATION_RANK
:
6912 FactionEntry
const* factionEntry
= sFactionStore
.LookupEntry(value1
);
6915 sLog
.outErrorDb("Reputation condition requires to have reputation non existing faction (%u), skipped", value1
);
6920 case CONDITION_TEAM
:
6922 if (value1
!= ALLIANCE
&& value1
!= HORDE
)
6924 sLog
.outErrorDb("Team condition specifies unknown team (%u), skipped", value1
);
6929 case CONDITION_SKILL
:
6931 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(value1
);
6934 sLog
.outErrorDb("Skill condition specifies non-existing skill (%u), skipped", value1
);
6937 if (value2
< 1 || value2
> sWorld
.GetConfigMaxSkillValue() )
6939 sLog
.outErrorDb("Skill condition specifies invalid skill value (%u), skipped", value2
);
6944 case CONDITION_QUESTREWARDED
:
6945 case CONDITION_QUESTTAKEN
:
6947 Quest
const *Quest
= objmgr
.GetQuestTemplate(value1
);
6950 sLog
.outErrorDb("Quest condition specifies non-existing quest (%u), skipped", value1
);
6954 sLog
.outErrorDb("Quest condition has useless data in value2 (%u)!", value2
);
6957 case CONDITION_AD_COMMISSION_AURA
:
6960 sLog
.outErrorDb("Quest condition has useless data in value1 (%u)!", value1
);
6962 sLog
.outErrorDb("Quest condition has useless data in value2 (%u)!", value2
);
6965 case CONDITION_NO_AURA
:
6967 if(!sSpellStore
.LookupEntry(value1
))
6969 sLog
.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1
);
6974 sLog
.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2
);
6979 case CONDITION_ACTIVE_EVENT
:
6981 GameEventMgr::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
6982 if(value1
>=events
.size() || !events
[value1
].isValid())
6984 sLog
.outErrorDb("Active event condition requires existed event id (%u), skipped", value1
);
6989 case CONDITION_NONE
:
6995 SkillRangeType
GetSkillRangeType(SkillLineEntry
const *pSkill
, bool racial
)
6997 switch(pSkill
->categoryId
)
6999 case SKILL_CATEGORY_LANGUAGES
: return SKILL_RANGE_LANGUAGE
;
7000 case SKILL_CATEGORY_WEAPON
:
7001 if(pSkill
->id
!=SKILL_FIST_WEAPONS
)
7002 return SKILL_RANGE_LEVEL
;
7004 return SKILL_RANGE_MONO
;
7005 case SKILL_CATEGORY_ARMOR
:
7006 case SKILL_CATEGORY_CLASS
:
7007 if(pSkill
->id
!= SKILL_LOCKPICKING
)
7008 return SKILL_RANGE_MONO
;
7010 return SKILL_RANGE_LEVEL
;
7011 case SKILL_CATEGORY_SECONDARY
:
7012 case SKILL_CATEGORY_PROFESSION
:
7013 // not set skills for professions and racial abilities
7014 if(IsProfessionSkill(pSkill
->id
))
7015 return SKILL_RANGE_RANK
;
7017 return SKILL_RANGE_NONE
;
7019 return SKILL_RANGE_MONO
;
7021 case SKILL_CATEGORY_ATTRIBUTES
: //not found in dbc
7022 case SKILL_CATEGORY_GENERIC
: //only GENERIC(DND)
7023 return SKILL_RANGE_NONE
;
7027 void ObjectMgr::LoadGameTele()
7029 m_GameTeleMap
.clear(); // for reload case
7032 QueryResult
*result
= WorldDatabase
.Query("SELECT id, position_x, position_y, position_z, orientation, map, name FROM game_tele");
7041 sLog
.outErrorDb(">> Loaded `game_tele`, table is empty!");
7045 barGoLink
bar( result
->GetRowCount() );
7051 Field
*fields
= result
->Fetch();
7053 uint32 id
= fields
[0].GetUInt32();
7057 gt
.position_x
= fields
[1].GetFloat();
7058 gt
.position_y
= fields
[2].GetFloat();
7059 gt
.position_z
= fields
[3].GetFloat();
7060 gt
.orientation
= fields
[4].GetFloat();
7061 gt
.mapId
= fields
[5].GetUInt32();
7062 gt
.name
= fields
[6].GetCppString();
7064 if(!MapManager::IsValidMapCoord(gt
.mapId
,gt
.position_x
,gt
.position_y
,gt
.position_z
,gt
.orientation
))
7066 sLog
.outErrorDb("Wrong position for id %u (name: %s) in `game_tele` table, ignoring.",id
,gt
.name
.c_str());
7070 if(!Utf8toWStr(gt
.name
,gt
.wnameLow
))
7072 sLog
.outErrorDb("Wrong UTF8 name for id %u in `game_tele` table, ignoring.",id
);
7076 wstrToLower( gt
.wnameLow
);
7078 m_GameTeleMap
[id
] = gt
;
7082 while (result
->NextRow());
7086 sLog
.outString( ">> Loaded %u GameTeleports", count
);
7089 GameTele
const* ObjectMgr::GetGameTele(const std::string
& name
) const
7091 // explicit name case
7093 if(!Utf8toWStr(name
,wname
))
7096 // converting string that we try to find to lower case
7097 wstrToLower( wname
);
7099 // Alternative first GameTele what contains wnameLow as substring in case no GameTele location found
7100 const GameTele
* alt
= NULL
;
7101 for(GameTeleMap::const_iterator itr
= m_GameTeleMap
.begin(); itr
!= m_GameTeleMap
.end(); ++itr
)
7102 if(itr
->second
.wnameLow
== wname
)
7103 return &itr
->second
;
7104 else if (alt
== NULL
&& itr
->second
.wnameLow
.find(wname
) != std::wstring::npos
)
7110 bool ObjectMgr::AddGameTele(GameTele
& tele
)
7114 for(GameTeleMap::const_iterator itr
= m_GameTeleMap
.begin(); itr
!= m_GameTeleMap
.end(); ++itr
)
7115 if(itr
->first
> new_id
)
7116 new_id
= itr
->first
;
7121 if(!Utf8toWStr(tele
.name
,tele
.wnameLow
))
7124 wstrToLower( tele
.wnameLow
);
7126 m_GameTeleMap
[new_id
] = tele
;
7128 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')",
7129 new_id
,tele
.position_x
,tele
.position_y
,tele
.position_z
,tele
.orientation
,tele
.mapId
,tele
.name
.c_str());
7132 bool ObjectMgr::DeleteGameTele(const std::string
& name
)
7134 // explicit name case
7136 if(!Utf8toWStr(name
,wname
))
7139 // converting string that we try to find to lower case
7140 wstrToLower( wname
);
7142 for(GameTeleMap::iterator itr
= m_GameTeleMap
.begin(); itr
!= m_GameTeleMap
.end(); ++itr
)
7144 if(itr
->second
.wnameLow
== wname
)
7146 WorldDatabase
.PExecuteLog("DELETE FROM game_tele WHERE name = '%s'",itr
->second
.name
.c_str());
7147 m_GameTeleMap
.erase(itr
);
7155 void ObjectMgr::LoadTrainerSpell()
7158 for (CacheTrainerSpellMap::iterator itr
= m_mCacheTrainerSpellMap
.begin(); itr
!= m_mCacheTrainerSpellMap
.end(); ++itr
)
7159 itr
->second
.Clear();
7160 m_mCacheTrainerSpellMap
.clear();
7162 std::set
<uint32
> skip_trainers
;
7164 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer");
7173 sLog
.outErrorDb(">> Loaded `npc_trainer`, table is empty!");
7177 barGoLink
bar( result
->GetRowCount() );
7184 Field
* fields
= result
->Fetch();
7186 uint32 entry
= fields
[0].GetUInt32();
7187 uint32 spell
= fields
[1].GetUInt32();
7189 CreatureInfo
const* cInfo
= GetCreatureTemplate(entry
);
7193 sLog
.outErrorDb("Table `npc_trainer` have entry for not existed creature template (Entry: %u), ignore", entry
);
7197 if(!(cInfo
->npcflag
& UNIT_NPC_FLAG_TRAINER
))
7199 if(skip_trainers
.count(entry
) == 0)
7201 sLog
.outErrorDb("Table `npc_trainer` have data for not creature template (Entry: %u) without trainer flag, ignore", entry
);
7202 skip_trainers
.insert(entry
);
7207 SpellEntry
const *spellinfo
= sSpellStore
.LookupEntry(spell
);
7210 sLog
.outErrorDb("Table `npc_trainer` for Trainer (Entry: %u ) has non existing spell %u, ignore", entry
,spell
);
7214 if(!SpellMgr::IsSpellValid(spellinfo
))
7216 sLog
.outErrorDb("Table `npc_trainer` for Trainer (Entry: %u) has broken learning spell %u, ignore", entry
, spell
);
7220 TrainerSpellData
& data
= m_mCacheTrainerSpellMap
[entry
];
7222 TrainerSpell
& trainerSpell
= data
.spellList
[spell
];
7223 trainerSpell
.spell
= spell
;
7224 trainerSpell
.spellCost
= fields
[2].GetUInt32();
7225 trainerSpell
.reqSkill
= fields
[3].GetUInt32();
7226 trainerSpell
.reqSkillValue
= fields
[4].GetUInt32();
7227 trainerSpell
.reqLevel
= fields
[5].GetUInt32();
7229 if(!trainerSpell
.reqLevel
)
7230 trainerSpell
.reqLevel
= spellinfo
->spellLevel
;
7232 // calculate learned spell for profession case when stored cast-spell
7233 trainerSpell
.learnedSpell
= spell
;
7234 for(int i
= 0; i
<3; ++i
)
7236 if(spellinfo
->Effect
[i
] != SPELL_EFFECT_LEARN_SPELL
)
7238 if(SpellMgr::IsProfessionOrRidingSpell(spellinfo
->EffectTriggerSpell
[i
]))
7240 trainerSpell
.learnedSpell
= spellinfo
->EffectTriggerSpell
[i
];
7245 if(SpellMgr::IsProfessionSpell(trainerSpell
.learnedSpell
))
7246 data
.trainerType
= 2;
7250 } while (result
->NextRow());
7254 sLog
.outString( ">> Loaded %d Trainers", count
);
7257 void ObjectMgr::LoadVendors()
7260 for (CacheVendorItemMap::iterator itr
= m_mCacheVendorItemMap
.begin(); itr
!= m_mCacheVendorItemMap
.end(); ++itr
)
7261 itr
->second
.Clear();
7262 m_mCacheVendorItemMap
.clear();
7264 std::set
<uint32
> skip_vendors
;
7266 QueryResult
*result
= WorldDatabase
.Query("SELECT entry, item, maxcount, incrtime, ExtendedCost FROM npc_vendor");
7274 sLog
.outErrorDb(">> Loaded `npc_vendor`, table is empty!");
7278 barGoLink
bar( result
->GetRowCount() );
7284 Field
* fields
= result
->Fetch();
7286 uint32 entry
= fields
[0].GetUInt32();
7287 uint32 item_id
= fields
[1].GetUInt32();
7288 uint32 maxcount
= fields
[2].GetUInt32();
7289 uint32 incrtime
= fields
[3].GetUInt32();
7290 uint32 ExtendedCost
= fields
[4].GetUInt32();
7292 if(!IsVendorItemValid(entry
,item_id
,maxcount
,incrtime
,ExtendedCost
,NULL
,&skip_vendors
))
7295 VendorItemData
& vList
= m_mCacheVendorItemMap
[entry
];
7297 vList
.AddItem(item_id
,maxcount
,incrtime
,ExtendedCost
);
7300 } while (result
->NextRow());
7304 sLog
.outString( ">> Loaded %d Vendors ", count
);
7307 void ObjectMgr::LoadNpcTextId()
7310 m_mCacheNpcTextIdMap
.clear();
7312 QueryResult
* result
= WorldDatabase
.Query("SELECT npc_guid, textid FROM npc_gossip");
7320 sLog
.outErrorDb(">> Loaded `npc_gossip`, table is empty!");
7324 barGoLink
bar( result
->GetRowCount() );
7332 Field
* fields
= result
->Fetch();
7334 guid
= fields
[0].GetUInt32();
7335 textid
= fields
[1].GetUInt32();
7337 if (!GetCreatureData(guid
))
7339 sLog
.outErrorDb("Table `npc_gossip` have not existed creature (GUID: %u) entry, ignore. ",guid
);
7342 if (!GetGossipText(textid
))
7344 sLog
.outErrorDb("Table `npc_gossip` for creature (GUID: %u) have wrong Textid (%u), ignore. ", guid
, textid
);
7348 m_mCacheNpcTextIdMap
[guid
] = textid
;
7351 } while (result
->NextRow());
7355 sLog
.outString( ">> Loaded %d NpcTextId ", count
);
7358 void ObjectMgr::LoadNpcOptions()
7360 m_mCacheNpcOptionList
.clear(); // For reload case
7362 QueryResult
*result
= WorldDatabase
.Query(
7363 // 0 1 2 3 4 5 6 7 8
7364 "SELECT id,gossip_id,npcflag,icon,action,box_money,coded,option_text,box_text "
7374 sLog
.outErrorDb(">> Loaded `npc_option`, table is empty!");
7378 barGoLink
bar( result
->GetRowCount() );
7386 Field
* fields
= result
->Fetch();
7389 go
.Id
= fields
[0].GetUInt32();
7390 go
.GossipId
= fields
[1].GetUInt32();
7391 go
.NpcFlag
= fields
[2].GetUInt32();
7392 go
.Icon
= fields
[3].GetUInt32();
7393 go
.Action
= fields
[4].GetUInt32();
7394 go
.BoxMoney
= fields
[5].GetUInt32();
7395 go
.Coded
= fields
[6].GetUInt8()!=0;
7396 go
.OptionText
= fields
[7].GetCppString();
7397 go
.BoxText
= fields
[8].GetCppString();
7399 m_mCacheNpcOptionList
.push_back(go
);
7403 } while (result
->NextRow());
7407 sLog
.outString( ">> Loaded %d npc_option entries", count
);
7410 void ObjectMgr::AddVendorItem( uint32 entry
,uint32 item
, uint32 maxcount
, uint32 incrtime
, uint32 extendedcost
)
7412 VendorItemData
& vList
= m_mCacheVendorItemMap
[entry
];
7413 vList
.AddItem(item
,maxcount
,incrtime
,extendedcost
);
7415 WorldDatabase
.PExecuteLog("INSERT INTO npc_vendor (entry,item,maxcount,incrtime,extendedcost) VALUES('%u','%u','%u','%u','%u')",entry
, item
, maxcount
,incrtime
,extendedcost
);
7418 bool ObjectMgr::RemoveVendorItem( uint32 entry
,uint32 item
)
7420 CacheVendorItemMap::iterator iter
= m_mCacheVendorItemMap
.find(entry
);
7421 if(iter
== m_mCacheVendorItemMap
.end())
7424 if(!iter
->second
.FindItem(item
))
7427 iter
->second
.RemoveItem(item
);
7428 WorldDatabase
.PExecuteLog("DELETE FROM npc_vendor WHERE entry='%u' AND item='%u'",entry
, item
);
7432 bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry
, uint32 item_id
, uint32 maxcount
, uint32 incrtime
, uint32 ExtendedCost
, Player
* pl
, std::set
<uint32
>* skip_vendors
) const
7434 CreatureInfo
const* cInfo
= GetCreatureTemplate(vendor_entry
);
7438 ChatHandler(pl
).SendSysMessage(LANG_COMMAND_VENDORSELECTION
);
7440 sLog
.outErrorDb("Table `npc_vendor` have data for not existed creature template (Entry: %u), ignore", vendor_entry
);
7444 if(!(cInfo
->npcflag
& UNIT_NPC_FLAG_VENDOR
))
7446 if(!skip_vendors
|| skip_vendors
->count(vendor_entry
)==0)
7449 ChatHandler(pl
).SendSysMessage(LANG_COMMAND_VENDORSELECTION
);
7451 sLog
.outErrorDb("Table `npc_vendor` have data for not creature template (Entry: %u) without vendor flag, ignore", vendor_entry
);
7454 skip_vendors
->insert(vendor_entry
);
7459 if(!GetItemPrototype(item_id
))
7462 ChatHandler(pl
).PSendSysMessage(LANG_ITEM_NOT_FOUND
, item_id
);
7464 sLog
.outErrorDb("Table `npc_vendor` for Vendor (Entry: %u) have in item list non-existed item (%u), ignore",vendor_entry
,item_id
);
7468 if(ExtendedCost
&& !sItemExtendedCostStore
.LookupEntry(ExtendedCost
))
7471 ChatHandler(pl
).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST
,ExtendedCost
);
7473 sLog
.outErrorDb("Table `npc_vendor` have Item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignore",item_id
,ExtendedCost
,vendor_entry
);
7477 if(maxcount
> 0 && incrtime
== 0)
7480 ChatHandler(pl
).PSendSysMessage("MaxCount!=0 (%u) but IncrTime==0", maxcount
);
7482 sLog
.outErrorDb( "Table `npc_vendor` has `maxcount` (%u) for item %u of vendor (Entry: %u) but `incrtime`=0, ignore", maxcount
, item_id
, vendor_entry
);
7485 else if(maxcount
==0 && incrtime
> 0)
7488 ChatHandler(pl
).PSendSysMessage("MaxCount==0 but IncrTime<>=0");
7490 sLog
.outErrorDb( "Table `npc_vendor` has `maxcount`=0 for item %u of vendor (Entry: %u) but `incrtime`<>0, ignore", item_id
, vendor_entry
);
7494 VendorItemData
const* vItems
= GetNpcVendorItemList(vendor_entry
);
7496 return true; // later checks for non-empty lists
7498 if(vItems
->FindItem(item_id
))
7501 ChatHandler(pl
).PSendSysMessage(LANG_ITEM_ALREADY_IN_LIST
,item_id
);
7503 sLog
.outErrorDb( "Table `npc_vendor` has duplicate items %u for vendor (Entry: %u), ignore", item_id
, vendor_entry
);
7507 if(vItems
->GetItemCount() >= MAX_VENDOR_ITEMS
)
7510 ChatHandler(pl
).SendSysMessage(LANG_COMMAND_ADDVENDORITEMITEMS
);
7512 sLog
.outErrorDb( "Table `npc_vendor` has too many items (%u >= %i) for vendor (Entry: %u), ignore", vItems
->GetItemCount(), MAX_VENDOR_ITEMS
, vendor_entry
);
7519 void ObjectMgr::LoadScriptNames()
7521 m_scriptNames
.push_back("");
7522 QueryResult
*result
= WorldDatabase
.Query(
7523 "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' "
7525 "SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' "
7527 "SELECT DISTINCT(ScriptName) FROM item_template WHERE ScriptName <> '' "
7529 "SELECT DISTINCT(ScriptName) FROM areatrigger_scripts WHERE ScriptName <> '' "
7531 "SELECT DISTINCT(script) FROM instance_template WHERE script <> ''");
7538 sLog
.outErrorDb(">> Loaded empty set of Script Names!");
7542 barGoLink
bar( result
->GetRowCount() );
7548 m_scriptNames
.push_back((*result
)[0].GetString());
7550 } while (result
->NextRow());
7553 std::sort(m_scriptNames
.begin(), m_scriptNames
.end());
7555 sLog
.outString( ">> Loaded %d Script Names", count
);
7558 uint32
ObjectMgr::GetScriptId(const char *name
)
7560 // use binary search to find the script name in the sorted vector
7561 // assume "" is the first element
7563 ScriptNameMap::const_iterator itr
=
7564 std::lower_bound(m_scriptNames
.begin(), m_scriptNames
.end(), name
);
7565 if(itr
== m_scriptNames
.end() || *itr
!= name
) return 0;
7566 return itr
- m_scriptNames
.begin();
7569 void ObjectMgr::CheckScripts(ScriptMapMap
const& scripts
,std::set
<int32
>& ids
)
7571 for(ScriptMapMap::const_iterator itrMM
= scripts
.begin(); itrMM
!= scripts
.end(); ++itrMM
)
7573 for(ScriptMap::const_iterator itrM
= itrMM
->second
.begin(); itrM
!= itrMM
->second
.end(); ++itrM
)
7575 switch(itrM
->second
.command
)
7577 case SCRIPT_COMMAND_TALK
:
7579 if(!GetMangosStringLocale (itrM
->second
.dataint
))
7580 sLog
.outErrorDb( "Table `db_script_string` not has string id %u used db script (ID: %u)", itrM
->second
.dataint
, itrMM
->first
);
7582 if(ids
.count(itrM
->second
.dataint
))
7583 ids
.erase(itrM
->second
.dataint
);
7590 void ObjectMgr::LoadDbScriptStrings()
7592 LoadMangosStrings(WorldDatabase
,"db_script_string",MIN_DB_SCRIPT_STRING_ID
,MAX_DB_SCRIPT_STRING_ID
);
7594 std::set
<int32
> ids
;
7596 for(int32 i
= MIN_DB_SCRIPT_STRING_ID
; i
< MAX_DB_SCRIPT_STRING_ID
; ++i
)
7597 if(GetMangosStringLocale(i
))
7600 CheckScripts(sQuestEndScripts
,ids
);
7601 CheckScripts(sQuestStartScripts
,ids
);
7602 CheckScripts(sSpellScripts
,ids
);
7603 CheckScripts(sGameObjectScripts
,ids
);
7604 CheckScripts(sEventScripts
,ids
);
7606 WaypointMgr
.CheckTextsExistance(ids
);
7608 for(std::set
<int32
>::const_iterator itr
= ids
.begin(); itr
!= ids
.end(); ++itr
)
7609 sLog
.outErrorDb( "Table `db_script_string` has unused string id %u", *itr
);
7612 // Functions for scripting access
7613 uint32
GetAreaTriggerScriptId(uint32 trigger_id
)
7615 return objmgr
.GetAreaTriggerScriptId(trigger_id
);
7618 bool LoadMangosStrings(DatabaseType
& db
, char const* table
,int32 start_value
, int32 end_value
)
7620 // MAX_DB_SCRIPT_STRING_ID is max allowed negative value for scripts (scrpts can use only more deep negative values
7621 // start/end reversed for negative values
7622 if (start_value
> MAX_DB_SCRIPT_STRING_ID
|| end_value
>= start_value
)
7624 sLog
.outErrorDb("Table '%s' attempt loaded with reserved by mangos range (%d - %d), strings not loaded.",table
,start_value
,end_value
+1);
7628 return objmgr
.LoadMangosStrings(db
,table
,start_value
,end_value
);
7631 uint32 MANGOS_DLL_SPEC
GetScriptId(const char *name
)
7633 return objmgr
.GetScriptId(name
);
7636 ObjectMgr::ScriptNameMap
& GetScriptNames()
7638 return objmgr
.GetScriptNames();
7641 CreatureInfo
const* GetCreatureTemplateStore(uint32 entry
)
7643 return sCreatureStorage
.LookupEntry
<CreatureInfo
>(entry
);
7646 Quest
const* GetQuestTemplateStore(uint32 entry
)
7648 return objmgr
.GetQuestTemplate(entry
);