From 675e9c2deac1ce61ae4c60fcdccc7c5be2295d3c Mon Sep 17 00:00:00 2001 From: killerwife Date: Fri, 2 Dec 2016 18:02:46 +0100 Subject: [PATCH] Implement npc_trainer/_template condition_id --- sql/base/mangos.sql | 2 ++ sql/updates/mangos/trainer_conditon_id.sql | 4 +++ src/game/Creature.h | 8 +++--- src/game/NPCHandler.cpp | 6 +++++ src/game/ObjectMgr.cpp | 31 ++++++++++++++-------- src/game/ObjectMgr.h | 1 + 6 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 sql/updates/mangos/trainer_conditon_id.sql diff --git a/sql/base/mangos.sql b/sql/base/mangos.sql index ec1b9da6ff3..cab1f2e9634 100644 --- a/sql/base/mangos.sql +++ b/sql/base/mangos.sql @@ -4836,6 +4836,7 @@ CREATE TABLE `npc_trainer` ( `reqskill` smallint(5) unsigned NOT NULL DEFAULT '0', `reqskillvalue` smallint(5) unsigned NOT NULL DEFAULT '0', `reqlevel` tinyint(3) unsigned NOT NULL DEFAULT '0', + `condition_id` INT(11) unsigned NOT NULL default '0', UNIQUE KEY `entry_spell` (`entry`,`spell`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; @@ -4860,6 +4861,7 @@ CREATE TABLE `npc_trainer_template` ( `reqskill` smallint(5) unsigned NOT NULL DEFAULT '0', `reqskillvalue` smallint(5) unsigned NOT NULL DEFAULT '0', `reqlevel` tinyint(3) unsigned NOT NULL DEFAULT '0', + `condition_id` INT(11) unsigned NOT NULL default '0', UNIQUE KEY `entry_spell` (`entry`,`spell`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/sql/updates/mangos/trainer_conditon_id.sql b/sql/updates/mangos/trainer_conditon_id.sql new file mode 100644 index 00000000000..55f15075fde --- /dev/null +++ b/sql/updates/mangos/trainer_conditon_id.sql @@ -0,0 +1,4 @@ +ALTER TABLE npc_trainer ADD COLUMN `condition_id` INT(11) unsigned NOT NULL default '0' AFTER reqlevel; +ALTER TABLE npc_trainer_template ADD COLUMN `condition_id` INT(11) unsigned NOT NULL default '0' AFTER reqlevel; + + diff --git a/src/game/Creature.h b/src/game/Creature.h index 3aad5312252..da05dc0ed37 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -395,11 +395,10 @@ typedef std::list VendorItemCounts; struct TrainerSpell { - TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0), learnedSpell(0), isProvidedReqLevel(false) {} + TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0), learnedSpell(0), isProvidedReqLevel(false), conditionId(0) {} - TrainerSpell(uint32 _spell, uint32 _spellCost, uint32 _reqSkill, uint32 _reqSkillValue, uint32 _reqLevel, uint32 _learnedspell, bool _isProvidedReqLevel) - : spell(_spell), spellCost(_spellCost), reqSkill(_reqSkill), reqSkillValue(_reqSkillValue), reqLevel(_reqLevel), learnedSpell(_learnedspell), isProvidedReqLevel(_isProvidedReqLevel) - {} + TrainerSpell(uint32 _spell, uint32 _spellCost, uint32 _reqSkill, uint32 _reqSkillValue, uint32 _reqLevel, uint32 _learnedspell, bool _isProvidedReqLevel, uint32 _conditionId) + : spell(_spell), spellCost(_spellCost), reqSkill(_reqSkill), reqSkillValue(_reqSkillValue), reqLevel(_reqLevel), learnedSpell(_learnedspell), isProvidedReqLevel(_isProvidedReqLevel), conditionId(_conditionId) {} uint32 spell; uint32 spellCost; @@ -407,6 +406,7 @@ struct TrainerSpell uint32 reqSkillValue; uint32 reqLevel; uint32 learnedSpell; + uint32 conditionId; bool isProvidedReqLevel; // helpers diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index 2c05ef88a66..03161bbb723 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -184,6 +184,9 @@ void WorldSession::SendTrainerList(ObjectGuid guid, const std::string& strTitle) if (!_player->IsSpellFitByClassAndRace(tSpell->learnedSpell, &reqLevel)) continue; + if (tSpell->conditionId && !sObjectMgr.IsPlayerMeetToCondition(tSpell->conditionId, GetPlayer(), unit->GetMap(), unit, CONDITION_FROM_TRAINER)) + continue; + reqLevel = tSpell->isProvidedReqLevel ? tSpell->reqLevel : std::max(reqLevel, tSpell->reqLevel); TrainerSpellState state = _player->GetTrainerSpellState(tSpell, reqLevel); @@ -204,6 +207,9 @@ void WorldSession::SendTrainerList(ObjectGuid guid, const std::string& strTitle) if (!_player->IsSpellFitByClassAndRace(tSpell->learnedSpell, &reqLevel)) continue; + if (tSpell->conditionId && !sObjectMgr.IsPlayerMeetToCondition(tSpell->conditionId, GetPlayer(), unit->GetMap(), unit, CONDITION_FROM_TRAINER)) + continue; + reqLevel = tSpell->isProvidedReqLevel ? tSpell->reqLevel : std::max(reqLevel, tSpell->reqLevel); TrainerSpellState state = _player->GetTrainerSpellState(tSpell, reqLevel); diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 43d139a64bb..1e9dddac70a 100755 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -7667,16 +7667,17 @@ bool ObjectMgr::CheckDeclinedNames(const std::wstring& mainpart, DeclinedName co char const* conditionSourceToStr[] = { - "loot system", - "referencing loot", - "gossip menu", - "gossip menu option", - "event AI", - "hardcoded", - "vendor's item check", - "spell_area check", - "npc_spellclick_spells check", - "DBScript engine" + "loot system", // CONDITION_FROM_LOOT + "referencing loot", // CONDITION_FROM_REFERING_LOOT + "gossip menu", // CONDITION_FROM_GOSSIP_MENU + "gossip menu option", // CONDITION_FROM_GOSSIP_OPTION + "event AI", // CONDITION_FROM_EVENTAI + "hardcoded", // CONDITION_FROM_HARDCODED + "vendor's item check", // CONDITION_FROM_VENDOR + "spell_area check", // CONDITION_FROM_SPELL_AREA + "npc_spellclick_spells check", // CONDITION_FROM_SPELLCLICK + "DBScript engine", // CONDITION_FROM_DBSCRIPTS + "trainer's spell check", // CONDITION_FROM_TRAINER }; // Checks if player meets the condition @@ -8742,7 +8743,7 @@ void ObjectMgr::LoadTrainers(char const* tableName, bool isTemplates) std::set skip_trainers; - QueryResult* result = WorldDatabase.PQuery("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM %s", tableName); + QueryResult* result = WorldDatabase.PQuery("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel,condition_id FROM %s", tableName); if (!result) { @@ -8828,6 +8829,7 @@ void ObjectMgr::LoadTrainers(char const* tableName, bool isTemplates) trainerSpell.reqSkill = fields[3].GetUInt32(); trainerSpell.reqSkillValue = fields[4].GetUInt32(); trainerSpell.reqLevel = fields[5].GetUInt32(); + trainerSpell.conditionId = fields[6].GetUInt16(); trainerSpell.isProvidedReqLevel = trainerSpell.reqLevel > 0; @@ -8880,6 +8882,13 @@ void ObjectMgr::LoadTrainers(char const* tableName, bool isTemplates) trainerSpell.reqLevel = learnSpellinfo->spellLevel; } + if (trainerSpell.conditionId) + { + const PlayerCondition* condition = sConditionStorage.LookupEntry(trainerSpell.conditionId); + if (!condition) // condition does not exist for some reason + sLog.outErrorDb("Table `%s` (Entry: %u) has `condition_id` = %u but does not exist.", tableName, entry, trainerSpell.conditionId); + } + ++count; } while (result->NextRow()); diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index fbf83c8195f..aa411ace789 100755 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -401,6 +401,7 @@ enum ConditionSource // From where was th CONDITION_FROM_SPELL_AREA = 7, // Used to check a condition from spell_area table CONDITION_FROM_SPELLCLICK = 8, // Used to check a condition from npc_spellclick_spells table CONDITION_FROM_DBSCRIPTS = 9, // Used to check a condition from DB Scripts Engine + CONDITION_FROM_TRAINER = 10, // Used to check a condition from npc_trainer and npc_trainer_template }; class PlayerCondition