From f7d7f864e11344cff847b5eb5b4d101be475c2b9 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sun, 24 May 2009 06:28:46 +0400 Subject: [PATCH] [7886] Drop use table `petcreateinfo_spell` This is first commit in chain for remove oudated and not used pet functionality. * Use instead dropped table CreatureSpellData.dbc if creature_template.PetSpellDataId set (mostly hunter pets) * Use creature_template.spellN if not set creature_template.PetSpellDataId (mostly different summon creatures) * Fixed bug with not removing from action bar spell icon for not ranked unlearned spells. Note: summoned controllable creatures without PetSpellDataId must have expected spells in spellN feilds for creature_template. --- sql/mangos.sql | 25 +---- sql/updates/7886_01_mangos_petcreateinfo_spell.sql | 4 + sql/updates/Makefile.am | 2 + src/game/DBCStructure.h | 6 +- src/game/DBCfmt.h | 2 +- src/game/ObjectMgr.cpp | 3 +- src/game/Pet.cpp | 61 ++++++---- src/game/SpellMgr.cpp | 125 +++++++++++++++++++++ src/game/SpellMgr.h | 20 ++++ src/game/World.cpp | 12 +- src/shared/revision_nr.h | 2 +- 11 files changed, 205 insertions(+), 57 deletions(-) create mode 100644 sql/updates/7886_01_mangos_petcreateinfo_spell.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index 7568a20f5..80135d16d 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -23,7 +23,7 @@ DROP TABLE IF EXISTS `db_version`; CREATE TABLE `db_version` ( `version` varchar(120) default NULL, `creature_ai_version` varchar(120) default NULL, - `required_7884_02_mangos_playercreateinfo_action` bit(1) default NULL + `required_7886_01_mangos_petcreateinfo_spell` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes'; -- @@ -3661,29 +3661,6 @@ INSERT INTO `pet_name_generation` (`word`,`entry`,`half`) VALUES UNLOCK TABLES; -- --- Table structure for table `petcreateinfo_spell` --- - -DROP TABLE IF EXISTS `petcreateinfo_spell`; -CREATE TABLE `petcreateinfo_spell` ( - `entry` mediumint(8) unsigned NOT NULL default '0', - `Spell1` mediumint(8) unsigned NOT NULL default '0', - `Spell2` mediumint(8) unsigned NOT NULL default '0', - `Spell3` mediumint(8) unsigned NOT NULL default '0', - `Spell4` mediumint(8) unsigned NOT NULL default '0', - PRIMARY KEY (`entry`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Pet Create Spells'; - --- --- Dumping data for table `petcreateinfo_spell` --- - -LOCK TABLES `petcreateinfo_spell` WRITE; -/*!40000 ALTER TABLE `petcreateinfo_spell` DISABLE KEYS */; -/*!40000 ALTER TABLE `petcreateinfo_spell` ENABLE KEYS */; -UNLOCK TABLES; - --- -- Table structure for table `pickpocketing_loot_template` -- diff --git a/sql/updates/7886_01_mangos_petcreateinfo_spell.sql b/sql/updates/7886_01_mangos_petcreateinfo_spell.sql new file mode 100644 index 000000000..673d1b317 --- /dev/null +++ b/sql/updates/7886_01_mangos_petcreateinfo_spell.sql @@ -0,0 +1,4 @@ +ALTER TABLE db_version CHANGE COLUMN required_7884_02_mangos_playercreateinfo_action required_7886_01_mangos_petcreateinfo_spell bit; + +DROP TABLE IF EXISTS `petcreateinfo_spell`; + diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index f8aedf631..3dc7bc8e3 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -197,6 +197,7 @@ pkgdata_DATA = \ 7884_03_characters_character_spell.sql \ 7884_04_characters_character_aura.sql \ 7884_05_characters_character_action.sql \ + 7886_01_mangos_petcreateinfo_spell.sql \ README ## Additional files to include when running 'make dist' @@ -374,4 +375,5 @@ EXTRA_DIST = \ 7884_03_characters_character_spell.sql \ 7884_04_characters_character_aura.sql \ 7884_05_characters_character_action.sql \ + 7886_01_mangos_petcreateinfo_spell.sql \ README diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h index c63b94a58..bba5ffdf7 100644 --- a/src/game/DBCStructure.h +++ b/src/game/DBCStructure.h @@ -704,11 +704,13 @@ struct CreatureFamilyEntry // 27 m_iconFile }; +#define MAX_CREATURE_SPELL_DATA_SLOT 4 + struct CreatureSpellDataEntry { uint32 ID; // 0 m_ID - //uint32 spellId[4]; // 1-4 m_spells[4] - //uint32 availability[4]; // 4-7 m_availability[4] + uint32 spellId[MAX_CREATURE_SPELL_DATA_SLOT]; // 1-4 m_spells[4] + //uint32 availability[MAX_CREATURE_SPELL_DATA_SLOT]; // 4-7 m_availability[4] }; struct CreatureTypeEntry diff --git a/src/game/DBCfmt.h b/src/game/DBCfmt.h index 0966e2e2e..a86d6685f 100644 --- a/src/game/DBCfmt.h +++ b/src/game/DBCfmt.h @@ -37,7 +37,7 @@ const char ChrRacesEntryfmt[]="nxixiixxixxxxissssssssssssssssxxxxxxxxxxxxxxxxxxx const char CinematicSequencesEntryfmt[]="nxxxxxxxxx"; const char CreatureDisplayInfofmt[]="nxxxfxxxxxxxxxxx"; const char CreatureFamilyfmt[]="nfifiiiiixssssssssssssssssxx"; -const char CreatureSpellDatafmt[]="nxxxxxxxx"; +const char CreatureSpellDatafmt[]="niiiixxxx"; const char CreatureTypefmt[]="nxxxxxxxxxxxxxxxxxx"; const char CurrencyTypesfmt[]="xnxi"; const char DurabilityCostsfmt[]="niiiiiiiiiiiiiiiiiiiiiiiiiiiii"; diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 9955db4c9..1c159703a 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -3572,7 +3572,7 @@ void ObjectMgr::LoadPetCreateSpells() sLog.outString(); sLog.outString( ">> Loaded 0 pet create spells" ); - sLog.outErrorDb("`petcreateinfo_spell` table is empty!"); + //sLog.outErrorDb("`petcreateinfo_spell` table is empty!"); return; } @@ -3644,6 +3644,7 @@ void ObjectMgr::LoadPetCreateSpells() sLog.outString(); sLog.outString( ">> Loaded %u pet create spells", count ); + sLog.outErrorDb("`petcreateinfo_spell` table use deprecated! Must be empty!"); } void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 20cd43335..8025d3a85 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -1437,25 +1437,40 @@ bool Pet::learnSpell(uint32 spell_id) void Pet::InitLevelupSpellsForLevel() { - uint32 family = GetCreatureInfo()->family; - if(!family) - return; + uint32 level = getLevel(); - PetLevelupSpellSet const *levelupSpells = spellmgr.GetPetLevelupSpellList(family); - if(!levelupSpells) - return; + if(PetLevelupSpellSet const *levelupSpells = GetCreatureInfo()->family ? spellmgr.GetPetLevelupSpellList(GetCreatureInfo()->family) : NULL) + { + // PetLevelupSpellSet ordered by levels, process in reversed order + for(PetLevelupSpellSet::const_reverse_iterator itr = levelupSpells->rbegin(); itr != levelupSpells->rend(); ++itr) + { + // will called first if level down + if(itr->first > level) + unlearnSpell(itr->second,true); // will learn prev rank if any + // will called if level up + else + learnSpell(itr->second); // will unlearn prev rank if any + } + } - uint32 level = getLevel(); + int32 petSpellsId = GetCreatureInfo()->PetSpellDataId ? -(int32)GetCreatureInfo()->PetSpellDataId : GetEntry(); - // PetLevelupSpellSet ordered by levels, process in reversed order - for(PetLevelupSpellSet::const_reverse_iterator itr = levelupSpells->rbegin(); itr != levelupSpells->rend(); ++itr) + // default spells (can be not learned if pet level (as owner level decrease result for example) less first possible in normal game) + if(PetDefaultSpellsEntry const *defSpells = spellmgr.GetPetDefaultSpellsEntry(petSpellsId)) { - // will called first if level down - if(itr->first > level) - unlearnSpell(itr->second,true); // will learn prev rank if any - // will called if level up - else - learnSpell(itr->second); // will unlearn prev rank if any + for(int i = 0; i < MAX_CREATURE_SPELL_DATA_SLOT; ++i) + { + SpellEntry const* spellEntry = sSpellStore.LookupEntry(defSpells->spellid[i]); + if(!spellEntry) + continue; + + // will called first if level down + if(spellEntry->spellLevel > level) + unlearnSpell(spellEntry->Id,false); + // will called if level up + else + learnSpell(spellEntry->Id); + } } } @@ -1516,14 +1531,16 @@ bool Pet::removeSpell(uint32 spell_id, bool learn_prev) learnSpell(prev_id); } else - { - m_charmInfo->AddSpellToAB(spell_id, 0); + learn_prev = false; + } - // need update action bar for last removed rank - if (Unit* owner = GetOwner()) - if (owner->GetTypeId() == TYPEID_PLAYER) - ((Player*)owner)->PetSpellInitialize(); - } + // if remove last rank or non-ranked then update action bar at server and client if need + if(!learn_prev && m_charmInfo->AddSpellToAB(spell_id, 0)) + { + // need update action bar for last removed rank + if (Unit* owner = GetOwner()) + if (owner->GetTypeId() == TYPEID_PLAYER) + ((Player*)owner)->PetSpellInitialize(); } return true; diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index 5b7ba0848..9fa8cf51b 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -2223,6 +2223,131 @@ void SpellMgr::LoadPetLevelupSpellMap() sLog.outString( ">> Loaded %u pet levelup and default spells for %u families", count, family_count ); } +bool LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntry& petDefSpells) +{ + // skip empty list; + bool have_spell = false; + for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j) + { + if(petDefSpells.spellid[j]) + { + have_spell = true; + break; + } + } + if(!have_spell) + return false; + + // remove duplicates with levelupSpells if any + if(PetLevelupSpellSet const *levelupSpells = cInfo->family ? spellmgr.GetPetLevelupSpellList(cInfo->family) : NULL) + { + for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j) + { + if(!petDefSpells.spellid[j]) + continue; + + for(PetLevelupSpellSet::const_iterator itr = levelupSpells->begin(); itr != levelupSpells->end(); ++itr) + { + if (itr->second == petDefSpells.spellid[j]) + { + petDefSpells.spellid[j] = 0; + break; + } + } + } + } + + // skip empty list; + have_spell = false; + for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j) + { + if(petDefSpells.spellid[j]) + { + have_spell = true; + break; + } + } + + return have_spell; +} + +void SpellMgr::LoadPetDefaultSpells() +{ + assert(MAX_CREATURE_SPELL_DATA_SLOT==CREATURE_MAX_SPELLS); + + mPetDefaultSpellsMap.clear(); + + uint32 countCreature = 0; + uint32 countData = 0; + + for(uint32 i = 0; i < sCreatureStorage.MaxEntry; ++i ) + { + CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i); + if(!cInfo) + continue; + + if(!cInfo->PetSpellDataId) + continue; + + // for creature with PetSpellDataId get default pet spells from dbc + CreatureSpellDataEntry const* spellDataEntry = sCreatureSpellDataStore.LookupEntry(cInfo->PetSpellDataId); + if(!spellDataEntry) + continue; + + int32 petSpellsId = -(int32)cInfo->PetSpellDataId; + PetDefaultSpellsEntry petDefSpells; + for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j) + petDefSpells.spellid[j] = spellDataEntry->spellId[j]; + + if(LoadPetDefaultSpells_helper(cInfo, petDefSpells)) + { + mPetDefaultSpellsMap[petSpellsId] = petDefSpells; + ++countData; + } + } + + // different summon spells + for(uint32 i = 0; i < sSpellStore.GetNumRows(); ++i ) + { + SpellEntry const* spellEntry = sSpellStore.LookupEntry(i); + if(!spellEntry) + continue; + + for(int k = 0; k < 3; ++k) + { + if(spellEntry->Effect[k]==SPELL_EFFECT_SUMMON || spellEntry->Effect[k]==SPELL_EFFECT_SUMMON_PET) + { + uint32 creature_id = spellEntry->EffectMiscValue[k]; + CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(creature_id); + if(!cInfo) + continue; + + // already loaded + if(cInfo->PetSpellDataId) + continue; + + // for creature without PetSpellDataId get default pet spells from creature_template + int32 petSpellsId = cInfo->Entry; + if(mPetDefaultSpellsMap.find(cInfo->Entry) != mPetDefaultSpellsMap.end()) + continue; + + PetDefaultSpellsEntry petDefSpells; + for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j) + petDefSpells.spellid[j] = cInfo->spells[j]; + + if(LoadPetDefaultSpells_helper(cInfo, petDefSpells)) + { + mPetDefaultSpellsMap[petSpellsId] = petDefSpells; + ++countCreature; + } + } + } + } + + sLog.outString(); + sLog.outString( ">> Loaded addition spells for %u pet spell data entries and %u summonable creature templates", countData, countCreature ); +} + /// Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book, etc bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg) { diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h index 860655fd3..59915e800 100644 --- a/src/game/SpellMgr.h +++ b/src/game/SpellMgr.h @@ -564,6 +564,15 @@ typedef std::multimap SkillLineAbilityMap; typedef std::multimap PetLevelupSpellSet; typedef std::map PetLevelupSpellMap; +struct PetDefaultSpellsEntry +{ + uint32 spellid[MAX_CREATURE_SPELL_DATA_SLOT]; +}; + +// < 0 for petspelldata id, > 0 for creature_id +typedef std::map PetDefaultSpellsMap; + + inline bool IsPrimaryProfessionSkill(uint32 skill) { SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill); @@ -814,6 +823,15 @@ class SpellMgr return NULL; } + // < 0 for petspelldata id, > 0 for creature_id + PetDefaultSpellsEntry const* GetPetDefaultSpellsEntry(int32 id) const + { + PetDefaultSpellsMap::const_iterator itr = mPetDefaultSpellsMap.find(id); + if(itr != mPetDefaultSpellsMap.end()) + return &itr->second; + return NULL; + } + SpellCastResult GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player = NULL); SpellAreaMapBounds GetSpellAreaMapBounds(uint32 spell_id) const @@ -862,6 +880,7 @@ class SpellMgr void LoadSkillLineAbilityMap(); void LoadSpellPetAuras(); void LoadPetLevelupSpellMap(); + void LoadPetDefaultSpells(); void LoadSpellAreas(); private: @@ -878,6 +897,7 @@ class SpellMgr SkillLineAbilityMap mSkillLineAbilityMap; SpellPetAuraMap mSpellPetAuraMap; PetLevelupSpellMap mPetLevelupSpellMap; + PetDefaultSpellsMap mPetDefaultSpellsMap; // only spells not listed in related mPetLevelupSpellMap entry SpellAreaMap mSpellAreaMap; SpellAreaForQuestMap mSpellAreaForQuestMap; SpellAreaForQuestMap mSpellAreaForActiveQuestMap; diff --git a/src/game/World.cpp b/src/game/World.cpp index fa8cdfa73..0e1026ea1 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1158,12 +1158,15 @@ void World::SetInitialWorldSettings() sLog.outString( "Loading Points Of Interest Data..." ); objmgr.LoadPointsOfInterest(); - sLog.outString( "Loading Pet Create Spells..." ); - objmgr.LoadPetCreateSpells(); - sLog.outString( "Loading Creature Data..." ); objmgr.LoadCreatures(); + sLog.outString( "Loading pet levelup spells..." ); + spellmgr.LoadPetLevelupSpellMap(); + + sLog.outString( "Loading pet default spell additional to levelup spells..." ); + spellmgr.LoadPetDefaultSpells(); + sLog.outString( "Loading Creature Addon Data..." ); sLog.outString(); objmgr.LoadCreatureAddons(); // must be after LoadCreatureTemplates() and LoadCreatures() @@ -1230,9 +1233,6 @@ void World::SetInitialWorldSettings() sLog.outString( "Loading spell pet auras..." ); spellmgr.LoadSpellPetAuras(); - sLog.outString( "Loading pet levelup spells..." ); - spellmgr.LoadPetLevelupSpellMap(); - sLog.outString( "Loading Player Create Info & Level Stats..." ); sLog.outString(); objmgr.LoadPlayerInfo(); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 38d0d111c..64b2349c9 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7885" + #define REVISION_NR "7886" #endif // __REVISION_NR_H__ -- 2.11.4.GIT