[7133] Re-implement explicit spell discovery code.

* Replace reqClass by reqSkillVlaue field in `skill_discovery_template`
  and check expected skill points amount for specific reipe discovery.
* Add new `spell_loot_template` loot table for store item selection data for spells.
  At this moment for expclicit recipes discovery spells.
* Code cleanups.
This commit is contained in:
VladimirMangos 2009-01-21 06:14:34 +03:00
parent 205957df0a
commit 2b91a790bc
15 changed files with 201 additions and 95 deletions

View file

@ -22,7 +22,7 @@
DROP TABLE IF EXISTS `db_version`;
CREATE TABLE `db_version` (
`version` varchar(120) default NULL,
`required_7118_01_mangos_skill_discovery_template` bit(1) default NULL
`required_7133_02_mangos_spell_loot_template` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes';
--
@ -12999,7 +12999,7 @@ DROP TABLE IF EXISTS `skill_discovery_template`;
CREATE TABLE `skill_discovery_template` (
`spellId` mediumint(8) unsigned NOT NULL default '0' COMMENT 'SpellId of the discoverable spell',
`reqSpell` mediumint(8) unsigned NOT NULL default '0' COMMENT 'spell requirement',
`reqClass` tinyint(2) unsigned NOT NULL default '0' COMMENT 'class requirement',
`reqSkillValue` smallint(5) unsigned NOT NULL default '0' COMMENT 'skill points requirement',
`chance` float NOT NULL default '0' COMMENT 'chance to discover',
PRIMARY KEY (`spellId`,`reqSpell`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Skill Discovery System';
@ -16225,6 +16225,33 @@ INSERT INTO `spell_learn_spell` VALUES
/*!40000 ALTER TABLE `spell_learn_spell` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `spell_loot_template`
--
DROP TABLE IF EXISTS `spell_loot_template`;
CREATE TABLE `spell_loot_template` (
`entry` mediumint(8) unsigned NOT NULL default '0',
`item` mediumint(8) unsigned NOT NULL default '0',
`ChanceOrQuestChance` float NOT NULL default '100',
`groupid` tinyint(3) unsigned NOT NULL default '0',
`mincountOrRef` mediumint(9) NOT NULL default '1',
`maxcount` tinyint(3) unsigned NOT NULL default '1',
`lootcondition` tinyint(3) unsigned NOT NULL default '0',
`condition_value1` mediumint(8) unsigned NOT NULL default '0',
`condition_value2` mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (`entry`,`item`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Loot System';
--
-- Dumping data for table `spell_loot_template`
--
LOCK TABLES `spell_loot_template` WRITE;
/*!40000 ALTER TABLE `spell_loot_template` DISABLE KEYS */;
/*!40000 ALTER TABLE `spell_loot_template` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `spell_pet_auras`
--

View file

@ -0,0 +1,5 @@
ALTER TABLE db_version CHANGE COLUMN required_7118_01_mangos_skill_discovery_template required_7133_01_mangos_skill_discovery_template bit;
ALTER TABLE skill_discovery_template
DROP `reqClass`,
ADD COLUMN `reqSkillValue` smallint(5) unsigned NOT NULL default '0' COMMENT 'skill points requirement' AFTER reqSpell;

View file

@ -0,0 +1,15 @@
ALTER TABLE db_version CHANGE COLUMN required_7133_01_mangos_skill_discovery_template required_7133_02_mangos_spell_loot_template bit;
DROP TABLE IF EXISTS `spell_loot_template`;
CREATE TABLE `spell_loot_template` (
`entry` mediumint(8) unsigned NOT NULL default '0',
`item` mediumint(8) unsigned NOT NULL default '0',
`ChanceOrQuestChance` float NOT NULL default '100',
`groupid` tinyint(3) unsigned NOT NULL default '0',
`mincountOrRef` mediumint(9) NOT NULL default '1',
`maxcount` tinyint(3) unsigned NOT NULL default '1',
`lootcondition` tinyint(3) unsigned NOT NULL default '0',
`condition_value1` mediumint(8) unsigned NOT NULL default '0',
`condition_value2` mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (`entry`,`item`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Loot System';

View file

@ -143,6 +143,8 @@ pkgdata_DATA = \
7107_01_mangos_string.sql \
7113_01_characters_character_achievement_progress.sql \
7118_01_mangos_skill_discovery_template.sql \
7133_01_mangos_skill_discovery_template.sql \
7133_02_mangos_spell_loot_template.sql \
README
## Additional files to include when running 'make dist'
@ -266,4 +268,6 @@ EXTRA_DIST = \
7107_01_mangos_string.sql \
7113_01_characters_character_achievement_progress.sql \
7118_01_mangos_skill_discovery_template.sql \
7133_01_mangos_skill_discovery_template.sql \
7133_02_mangos_spell_loot_template.sql \
README

View file

@ -284,6 +284,7 @@ ChatCommand * ChatHandler::getCommandTable()
{ "spell_chain", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellChainCommand, "", NULL },
{ "spell_elixir", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellElixirCommand, "", NULL },
{ "spell_learn_spell", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellLearnSpellCommand, "", NULL },
{ "spell_loot_template", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadLootTemplatesSpellCommand, "", NULL },
{ "spell_pet_auras", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellPetAurasCommand, "", NULL },
{ "spell_proc_event", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellProcEventCommand, "", NULL },
{ "spell_script_target", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellScriptTargetCommand, "", NULL },

View file

@ -233,6 +233,7 @@ class ChatHandler
bool HandleReloadLootTemplatesReferenceCommand(const char* args);
bool HandleReloadLootTemplatesQuestMailCommand(const char* args);
bool HandleReloadLootTemplatesSkinningCommand(const char* args);
bool HandleReloadLootTemplatesSpellCommand(const char* args);
bool HandleReloadMangosStringCommand(const char* args);
bool HandleReloadNpcGossipCommand(const char* args);
bool HandleReloadNpcOptionCommand(const char* args);

View file

@ -339,6 +339,15 @@ bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
return true;
}
bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
{
sLog.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
LoadLootTemplates_Spell();
LootTemplates_Spell.CheckLootRefs();
SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
return true;
}
bool ChatHandler::HandleReloadMangosStringCommand(const char*)
{
sLog.outString( "Re-Loading mangos_string Table!" );

View file

@ -23,6 +23,7 @@
#include "World.h"
#include "Util.h"
#include "SharedDefines.h"
#include "SpellMgr.h"
static Rates const qualityToRate[MAX_ITEM_QUALITY] = {
RATE_DROP_ITEM_POOR, // ITEM_QUALITY_POOR
@ -45,6 +46,7 @@ LootStore LootTemplates_Prospecting( "prospecting_loot_template", "item entry
LootStore LootTemplates_QuestMail( "quest_mail_loot_template", "quest id (with mail template)",false);
LootStore LootTemplates_Reference( "reference_loot_template", "reference id", false);
LootStore LootTemplates_Skinning( "skinning_loot_template", "creature skinning id", true);
LootStore LootTemplates_Spell( "spell_loot_template", "spell id (explicitly discovering ability)",false);
class LootTemplate::LootGroup // A set of loot definitions for items (refs are not allowed)
{
@ -1258,6 +1260,32 @@ void LoadLootTemplates_Skinning()
LootTemplates_Skinning.ReportUnusedIds(ids_set);
}
void LoadLootTemplates_Spell()
{
LootIdSet ids_set;
LootTemplates_Spell.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for(uint32 spell_id = 1; spell_id < sSpellStore.GetNumRows(); ++spell_id)
{
SpellEntry const* spellInfo = sSpellStore.LookupEntry (spell_id);
if(!spellInfo)
continue;
// possible cases
if(!IsExplicitDiscoverySpell (spellInfo))
continue;
if(!ids_set.count(spell_id))
LootTemplates_Spell.ReportNotExistedId(spell_id);
else
ids_set.erase(spell_id);
}
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_QuestMail.ReportUnusedIds(ids_set);
}
void LoadLootTemplates_Reference()
{
LootIdSet ids_set;

View file

@ -304,6 +304,7 @@ extern LootStore LootTemplates_Skinning;
extern LootStore LootTemplates_Disenchant;
extern LootStore LootTemplates_Prospecting;
extern LootStore LootTemplates_QuestMail;
extern LootStore LootTemplates_Spell;
void LoadLootTemplates_Creature();
void LoadLootTemplates_Fishing();
@ -316,6 +317,7 @@ void LoadLootTemplates_Disenchant();
void LoadLootTemplates_Prospecting();
void LoadLootTemplates_QuestMail();
void LoadLootTemplates_Spell();
void LoadLootTemplates_Reference();
inline void LoadLootTables()
@ -330,6 +332,7 @@ inline void LoadLootTables()
LoadLootTemplates_Disenchant();
LoadLootTemplates_Prospecting();
LoadLootTemplates_QuestMail();
LoadLootTemplates_Spell();
LoadLootTemplates_Reference();
}

View file

@ -19313,3 +19313,23 @@ void Player::InitRunes()
for(uint32 i = 0; i < NUM_RUNE_TYPES; ++i)
SetFloatValue(PLAYER_RUNE_REGEN_1 + i, 0.1f);
}
void Player::AutoStoreLootItem(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store)
{
Loot loot;
loot.FillLoot (loot_id,store,this);
if(loot.items.empty ())
return;
LootItem const* lootItem = &loot.items[0];
ItemPosCountVec dest;
uint8 msg = CanStoreNewItem (bag,slot,dest,lootItem->itemid,lootItem->count);
if(msg != EQUIP_ERR_OK && slot != NULL_SLOT)
msg = CanStoreNewItem( bag, NULL_SLOT,dest,lootItem->itemid,lootItem->count);
if( msg != EQUIP_ERR_OK && bag != NULL_BAG)
msg = CanStoreNewItem( NULL_BAG, NULL_SLOT,dest,lootItem->itemid,lootItem->count);
if(msg != EQUIP_ERR_OK)
return;
StoreNewItem (dest,lootItem->itemid,true,lootItem->randomPropertyId);
}

View file

@ -1154,6 +1154,8 @@ class MANGOS_DLL_SPEC Player : public Unit
Item* EquipItem( uint16 pos, Item *pItem, bool update );
void AutoUnequipOffhandIfNeed();
bool StoreNewItemInBestSlots(uint32 item_id, uint32 item_count);
void AutoStoreLootItem(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store);
void AutoStoreLootItem(uint32 loot_id, LootStore const& store) { AutoStoreLootItem(NULL_BAG,NULL_SLOT,loot_id,store); }
uint8 _CanTakeMoreSimilarItems(uint32 entry, uint32 count, Item* pItem, uint32* no_space_count = NULL) const;
uint8 _CanStoreItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 entry, uint32 count, Item *pItem = NULL, bool swap = false, uint32* no_space_count = NULL ) const;

View file

@ -30,14 +30,14 @@
struct SkillDiscoveryEntry
{
uint32 spellId; // discavered spell
uint32 reqClass; // class limitation
uint32 reqSkillValue; // skill level limitation
float chance; // chance
SkillDiscoveryEntry()
: spellId(0), reqClass(0), chance(0) {}
: spellId(0), reqSkillValue(0), chance(0) {}
SkillDiscoveryEntry(uint16 _spellId, uint32 req_class, float _chance)
: spellId(_spellId), reqClass(req_class), chance(_chance) {}
SkillDiscoveryEntry(uint16 _spellId, uint32 req_skill_val, float _chance)
: spellId(_spellId), reqSkillValue(req_skill_val), chance(_chance) {}
};
typedef std::list<SkillDiscoveryEntry> SkillDiscoveryList;
@ -52,8 +52,8 @@ void LoadSkillDiscoveryTable()
uint32 count = 0;
// 0 1 2 3
QueryResult *result = WorldDatabase.Query("SELECT spellId, reqSpell, reqClass, chance FROM skill_discovery_template");
// 0 1 2 3
QueryResult *result = WorldDatabase.Query("SELECT spellId, reqSpell, reqSkillValue, chance FROM skill_discovery_template");
if (result)
{
@ -68,18 +68,13 @@ void LoadSkillDiscoveryTable()
uint32 spellId = fields[0].GetUInt32();
int32 reqSkillOrSpell = fields[1].GetInt32();
uint32 reqClass = fields[2].GetInt32();
uint32 reqSkillValue = fields[2].GetInt32();
float chance = fields[3].GetFloat();
if( chance <= 0 ) // chance
{
ssNonDiscoverableEntries << "spellId = " << spellId << " reqSkillOrSpell = " << reqSkillOrSpell << " reqClass = " << reqClass << " chance = " << chance << "(chance problem)\n";
continue;
}
if(reqClass && (reqClass >= MAX_CLASSES || ((1 << (reqClass-1)) & CLASSMASK_ALL_PLAYABLE)==0))
{
ssNonDiscoverableEntries << "spellId = " << spellId << " reqSkillOrSpell = " << reqSkillOrSpell << " reqClass = " << reqClass << " chance = " << chance << "(class problem)\n";
ssNonDiscoverableEntries << "spellId = " << spellId << " reqSkillOrSpell = " << reqSkillOrSpell
<< " reqSkillValue = " << reqSkillValue << " chance = " << chance << "(chance problem)\n";
continue;
}
@ -101,7 +96,7 @@ void LoadSkillDiscoveryTable()
continue;
}
SkillDiscoveryStore[reqSkillOrSpell].push_back( SkillDiscoveryEntry(spellId, reqClass, chance) );
SkillDiscoveryStore[reqSkillOrSpell].push_back( SkillDiscoveryEntry(spellId, reqSkillValue, chance) );
}
else if( reqSkillOrSpell == 0 ) // skill case
{
@ -116,7 +111,7 @@ void LoadSkillDiscoveryTable()
for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx)
{
SkillDiscoveryStore[-int32(_spell_idx->second->skillId)].push_back( SkillDiscoveryEntry(spellId, reqClass, chance) );
SkillDiscoveryStore[-int32(_spell_idx->second->skillId)].push_back( SkillDiscoveryEntry(spellId, reqSkillValue, chance) );
}
}
else
@ -142,53 +137,57 @@ void LoadSkillDiscoveryTable()
}
}
uint32 GetExplicitDiscoverySpell(uint32 spellId, Player* player)
{
// explicit discovery spell chances (always success if case exist)
// in this case we have both skill and spell
SkillDiscoveryMap::iterator tab = SkillDiscoveryStore.find(spellId);
if(tab == SkillDiscoveryStore.end())
return 0;
SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spellId);
SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spellId);
uint32 skillvalue = lower != upper ? player->GetSkillValue(lower->second->skillId) : 0;
float full_chance = 0;
for(SkillDiscoveryList::iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
if(item_iter->reqSkillValue <= skillvalue)
if(!player->HasSpell(item_iter->spellId))
full_chance += item_iter->chance;
float rate = full_chance / 100.0f;
float roll = rand_chance() * rate; // roll now in range 0..full_chance
for(SkillDiscoveryList::iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
{
if(item_iter->reqSkillValue > skillvalue)
continue;
if(player->HasSpell(item_iter->spellId))
continue;
if(item_iter->chance > roll)
return item_iter->spellId;
roll -= item_iter->chance;
}
return 0;
}
uint32 GetSkillDiscoverySpell(uint32 skillId, uint32 spellId, Player* player)
{
uint32 skillvalue = skillId ? player->GetSkillValue(skillId) : 0;
// check spell case
SkillDiscoveryMap::iterator tab = SkillDiscoveryStore.find(spellId);
if(tab != SkillDiscoveryStore.end())
{
SpellEntry const* spellInfo = sSpellStore.LookupEntry (spellId);
if(!spellInfo)
return 0;
// explicit discovery spell chances (alwasy success if case exist)
if(IsExplicitDiscoverySpell(spellInfo))
{
float full_chance = 0;
for(SkillDiscoveryList::iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
if(!item_iter->reqClass || player->getClass ()==item_iter->reqClass)
if(!player->HasSpell(item_iter->spellId))
full_chance += item_iter->chance;
float rate = full_chance / 100.0f;
float roll = rand_chance() * rate; // roll now in range 0..full_chance
for(SkillDiscoveryList::iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
{
if(item_iter->reqClass && player->getClass ()!= item_iter->reqClass)
continue;
if(player->HasSpell(item_iter->spellId))
continue;
if(item_iter->chance > roll)
return item_iter->spellId;
roll -= item_iter->chance;
}
return 0;
}
for(SkillDiscoveryList::iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
{
if(item_iter->reqClass && player->getClass ()!= item_iter->reqClass)
continue;
if( roll_chance_f(item_iter->chance * sWorld.getRate(RATE_SKILL_DISCOVERY))
&& item_iter->reqSkillValue <= skillvalue
&& !player->HasSpell(item_iter->spellId) )
return item_iter->spellId;
}
@ -205,10 +204,8 @@ uint32 GetSkillDiscoverySpell(uint32 skillId, uint32 spellId, Player* player)
{
for(SkillDiscoveryList::iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
{
if(item_iter->reqClass && player->getClass ()!= item_iter->reqClass)
continue;
if( roll_chance_f(item_iter->chance * sWorld.getRate(RATE_SKILL_DISCOVERY))
&& item_iter->reqSkillValue <= skillvalue
&& !player->HasSpell(item_iter->spellId) )
return item_iter->spellId;
}

View file

@ -25,4 +25,5 @@ class Player;
void LoadSkillDiscoveryTable();
uint32 GetSkillDiscoverySpell(uint32 skillId, uint32 spellId, Player* player);
uint32 GetExplicitDiscoverySpell(uint32 spellId, Player* player);
#endif

View file

@ -4610,21 +4610,17 @@ void Spell::EffectScriptEffect(uint32 effIndex)
// PX-238 Winter Wondervolt TRAP
case 26275:
{
if (unitTarget->HasAura(26272,0) ||
unitTarget->HasAura(26157,0) ||
unitTarget->HasAura(26273,0) ||
unitTarget->HasAura(26274,0))
return;
uint32 spells[4] = { 26272, 26157, 26273, 26274 };
uint32 iTmpSpellId;
switch(urand(0,3))
{
case 0: iTmpSpellId = 26272; break;
case 1: iTmpSpellId = 26157; break;
case 2: iTmpSpellId = 26273; break;
case 3: iTmpSpellId = 26274; break;
}
// check presence
for(int j = 0; j < 4; ++j)
if(unitTarget->HasAura(spells[j],0))
return;
// select spell
uint32 iTmpSpellId = spells[urand(0,3)];
// cast
unitTarget->CastSpell(unitTarget, iTmpSpellId, true);
return;
}
@ -4668,16 +4664,16 @@ void Spell::EffectScriptEffect(uint32 effIndex)
uint32 spellid;
switch(m_spellInfo->Id)
{
case 25140: spellid = 32571; break;
case 25143: spellid = 32572; break;
case 25650: spellid = 30140; break;
case 25652: spellid = 30141; break;
case 29128: spellid = 32568; break;
case 29129: spellid = 32569; break;
case 35376: spellid = 25649; break;
case 35727: spellid = 35730; break;
default:
return;
case 25140: spellid = 32571; break;
case 25143: spellid = 32572; break;
case 25650: spellid = 30140; break;
case 25652: spellid = 30141; break;
case 29128: spellid = 32568; break;
case 29129: spellid = 32569; break;
case 35376: spellid = 25649; break;
case 35727: spellid = 35730; break;
default:
return;
}
unitTarget->CastSpell(unitTarget,spellid,false);
@ -4803,18 +4799,10 @@ void Spell::EffectScriptEffect(uint32 effIndex)
uint32 spellId;
switch(rand()%4)
{
case 0:
spellId=46740;
break;
case 1:
spellId=46739;
break;
case 2:
spellId=46738;
break;
case 3:
spellId=46736;
break;
case 0: spellId = 46740; break;
case 1: spellId = 46739; break;
case 2: spellId = 46738; break;
case 3: spellId = 46736; break;
}
unitTarget->CastSpell(unitTarget, spellId, true);
break;
@ -4865,6 +4853,7 @@ void Spell::EffectScriptEffect(uint32 effIndex)
// need replace effect 0 item by loot
uint32 reagent_id = m_spellInfo->EffectItemType[0];
if(!player->HasItemCount(reagent_id,1))
return;
@ -4872,7 +4861,11 @@ void Spell::EffectScriptEffect(uint32 effIndex)
uint32 count = 1;
player->DestroyItemCount (reagent_id,count,true);
if(uint32 discoveredSpell = GetSkillDiscoverySpell(0, m_spellInfo->Id, player))
// create some random items
player->AutoStoreLootItem(m_spellInfo->Id,LootTemplates_Spell);
// learn random explicit discovery recipe (if any)
if(uint32 discoveredSpell = GetExplicitDiscoverySpell(m_spellInfo->Id, player))
player->learnSpell(discoveredSpell);
return;
}

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "7132"
#define REVISION_NR "7133"
#endif // __REVISION_NR_H__