2 * Copyright (C) 2005-2008 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
19 #include "SkillExtraItems.h"
20 #include "Database/DatabaseEnv.h"
22 #include "ProgressBar.h"
26 // some type definitions
27 // no use putting them in the header file, they're only used in this .cpp
29 // struct to store information about extra item creation
30 // one entry for every spell that is able to create an extra item
31 struct SkillExtraItemEntry
33 // the spell id of the specialization required to create extra items
34 uint32 requiredSpecialization
;
35 // the chance to create one additional item
36 float additionalCreateChance
;
37 // maximum number of extra items created per crafting
38 uint8 additionalMaxNum
;
41 : requiredSpecialization(0), additionalCreateChance(0.0f
), additionalMaxNum(0) {}
43 SkillExtraItemEntry(uint32 rS
, float aCC
, uint8 aMN
)
44 : requiredSpecialization(rS
), additionalCreateChance(aCC
), additionalMaxNum(aMN
) {}
47 // map to store the extra item creation info, the key is the spellId of the creation spell, the mapped value is the assigned SkillExtraItemEntry
48 typedef std::map
<uint32
,SkillExtraItemEntry
> SkillExtraItemMap
;
50 SkillExtraItemMap SkillExtraItemStore
;
52 // loads the extra item creation info from DB
53 void LoadSkillExtraItemTable()
57 SkillExtraItemStore
.clear(); // need for reload
60 QueryResult
*result
= WorldDatabase
.Query("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template");
64 barGoLink
bar(result
->GetRowCount());
68 Field
*fields
= result
->Fetch();
71 uint32 spellId
= fields
[0].GetUInt32();
73 if(!sSpellStore
.LookupEntry(spellId
))
75 sLog
.outError("Skill specialization %u has non-existent spell id in `skill_extra_item_template`!", spellId
);
79 uint32 requiredSpecialization
= fields
[1].GetUInt32();
80 if(!sSpellStore
.LookupEntry(requiredSpecialization
))
82 sLog
.outError("Skill specialization %u have not existed required specialization spell id %u in `skill_extra_item_template`!", spellId
,requiredSpecialization
);
86 float additionalCreateChance
= fields
[2].GetFloat();
87 if(additionalCreateChance
<= 0.0f
)
89 sLog
.outError("Skill specialization %u has too low additional create chance in `skill_extra_item_template`!", spellId
);
93 uint8 additionalMaxNum
= fields
[3].GetUInt8();
96 sLog
.outError("Skill specialization %u has 0 max number of extra items in `skill_extra_item_template`!", spellId
);
100 SkillExtraItemEntry
& skillExtraItemEntry
= SkillExtraItemStore
[spellId
];
102 skillExtraItemEntry
.requiredSpecialization
= requiredSpecialization
;
103 skillExtraItemEntry
.additionalCreateChance
= additionalCreateChance
;
104 skillExtraItemEntry
.additionalMaxNum
= additionalMaxNum
;
107 } while (result
->NextRow());
112 sLog
.outString( ">> Loaded %u spell specialization definitions", count
);
117 sLog
.outString( ">> Loaded 0 spell specialization definitions. DB table `skill_extra_item_template` is empty." );
121 bool canCreateExtraItems(Player
* player
, uint32 spellId
, float &additionalChance
, uint8
&additionalMax
)
123 // get the info for the specified spell
124 SkillExtraItemMap::const_iterator ret
= SkillExtraItemStore
.find(spellId
);
125 if(ret
==SkillExtraItemStore
.end())
128 SkillExtraItemEntry
const* specEntry
= &ret
->second
;
130 // if no entry, then no extra items can be created
134 // the player doesn't have the required specialization, return false
135 if(!player
->HasSpell(specEntry
->requiredSpecialization
))
138 // set the arguments to the appropriate values
139 additionalChance
= specEntry
->additionalCreateChance
;
140 additionalMax
= specEntry
->additionalMaxNum
;
142 // enable extra item creation