Skip to content

Commit

Permalink
Implement npc_trainer/_template condition_id
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife authored and cyberium committed Dec 19, 2016
1 parent 5167118 commit 675e9c2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
2 changes: 2 additions & 0 deletions sql/base/mangos.sql
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions 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;


8 changes: 4 additions & 4 deletions src/game/Creature.h
Expand Up @@ -395,18 +395,18 @@ typedef std::list<VendorItemCount> 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;
uint32 reqSkill;
uint32 reqSkillValue;
uint32 reqLevel;
uint32 learnedSpell;
uint32 conditionId;
bool isProvidedReqLevel;

// helpers
Expand Down
6 changes: 6 additions & 0 deletions src/game/NPCHandler.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
31 changes: 20 additions & 11 deletions src/game/ObjectMgr.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -8742,7 +8743,7 @@ void ObjectMgr::LoadTrainers(char const* tableName, bool isTemplates)

std::set<uint32> 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)
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -8880,6 +8882,13 @@ void ObjectMgr::LoadTrainers(char const* tableName, bool isTemplates)
trainerSpell.reqLevel = learnSpellinfo->spellLevel;
}

if (trainerSpell.conditionId)
{
const PlayerCondition* condition = sConditionStorage.LookupEntry<PlayerCondition>(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());
Expand Down
1 change: 1 addition & 0 deletions src/game/ObjectMgr.h
Expand Up @@ -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
Expand Down

0 comments on commit 675e9c2

Please sign in to comment.