Core/ConditionMgr: added CONDITION_SOURCE_TYPE_VEHICLE_SPELL, sourceGroup=creatureTemplate.entry, sourceEntry=spellEntry

--HG--
branch : trunk
This commit is contained in:
Rat
2010-10-22 22:45:11 +02:00
parent 3ee05b26ce
commit e67f04d362
3 changed files with 79 additions and 5 deletions
@@ -309,6 +309,22 @@ ConditionList ConditionMgr::GetConditionsForNotGroupedEntry(ConditionSourceType
return spellCond;
}
ConditionList ConditionMgr::GetConditionsForVehicleSpell(uint32 creatureID, uint32 spellID)
{
ConditionList cond;
VehicleSpellConditionMap::const_iterator itr = m_VehicleSpellConditions.find(creatureID);
if (itr != m_VehicleSpellConditions.end())
{
ConditionTypeMap::const_iterator i = (*itr).second.find(spellID);
if (i != (*itr).second.end())
{
cond = (*i).second;
sLog.outDebug("GetConditionsForVehicleSpell: found conditions for Vehicle entry %u spell %u", creatureID, spellID);
}
}
return cond;
}
void ConditionMgr::LoadConditions(bool isReload)
{
Clean();
@@ -482,6 +498,24 @@ void ConditionMgr::LoadConditions(bool isReload)
case CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION:
bIsDone = addToGossipMenuItems(cond);
break;
case CONDITION_SOURCE_TYPE_VEHICLE_SPELL:
{
//if no list for vehicle create one
if (m_VehicleSpellConditions.find(cond->mSourceGroup) == m_VehicleSpellConditions.end())
{
ConditionTypeMap cmap;
m_VehicleSpellConditions[cond->mSourceGroup] = cmap;
}
//if no list for vehicle's spell create one
if (m_VehicleSpellConditions[cond->mSourceGroup].find(cond->mSourceEntry) == m_VehicleSpellConditions[cond->mSourceGroup].end())
{
ConditionList clist;
m_VehicleSpellConditions[cond->mSourceGroup][cond->mSourceEntry] = clist;
}
m_VehicleSpellConditions[cond->mSourceGroup][cond->mSourceEntry].push_back(cond);
bIsDone = true;
break;
}
default:
break;
}
@@ -944,6 +978,21 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
}
}
break;
case CONDITION_SOURCE_TYPE_VEHICLE_SPELL:
{
if (!sCreatureStorage.LookupEntry<CreatureInfo>(cond->mSourceGroup))
{
sLog.outErrorDb("SourceEntry %u in `condition` table, does not exist in `creature_template`, ignoring.", cond->mSourceGroup);
return false;
}
SpellEntry const* spellProto = sSpellStore.LookupEntry(cond->mSourceEntry);
if (!spellProto)
{
sLog.outErrorDb("SourceEntry %u in `condition` table, does not exist in `spell.dbc`, ignoring.", cond->mSourceEntry);
return false;
}
break;
}
case CONDITION_SOURCE_TYPE_GOSSIP_MENU:
case CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION:
case CONDITION_SOURCE_TYPE_NONE:
@@ -1321,6 +1370,20 @@ void ConditionMgr::Clean()
m_ConditionMap.clear();
for (VehicleSpellConditionMap::iterator itr = m_VehicleSpellConditions.begin(); itr != m_VehicleSpellConditions.end(); ++itr)
{
for (ConditionTypeMap::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
{
for (ConditionList::const_iterator i = it->second.begin(); i != it->second.end(); ++i)
delete *i;
it->second.clear();
}
itr->second.clear();
}
m_VehicleSpellConditions.clear();
// this is a BIG hack, feel free to fix it if you can figure out the ConditionMgr ;)
for (std::list<Condition*>::const_iterator itr = m_AllocatedMemory.begin(); itr != m_AllocatedMemory.end(); ++itr)
delete *itr;
+10 -5
View File
@@ -91,7 +91,8 @@ enum ConditionSourceType
CONDITION_SOURCE_TYPE_ITEM_REQUIRED_TARGET = 18,//DONE
CONDITION_SOURCE_TYPE_QUEST_ACCEPT = 19,//DONE
CONDITION_SOURCE_TYPE_QUEST_SHOW_MARK = 20,//DONE
CONDITION_SOURCE_TYPE_MAX = 21//MAX
CONDITION_SOURCE_TYPE_VEHICLE_SPELL = 21,//DONE
CONDITION_SOURCE_TYPE_MAX = 22//MAX
};
struct Condition
@@ -129,7 +130,8 @@ struct Condition
typedef std::list<Condition*> ConditionList;
typedef std::map<uint32, ConditionList > ConditionTypeMap;
typedef std::map<ConditionSourceType, ConditionTypeMap > ConditionMap;//used for all conditions, except references
typedef std::map<ConditionSourceType, ConditionTypeMap > ConditionMap;
typedef std::map<uint32, ConditionTypeMap > VehicleSpellConditionMap;
typedef std::map<uint32, ConditionList > ConditionReferenceMap;//only used for references
@@ -147,11 +149,13 @@ class ConditionMgr
bool IsPlayerMeetToConditions(Player* player, ConditionList conditions, Unit* invoker = NULL);
ConditionList GetConditionsForNotGroupedEntry(ConditionSourceType sType, uint32 uEntry);
ConditionList GetConditionsForVehicleSpell(uint32 creatureID, uint32 spellID);
protected:
ConditionMap m_ConditionMap;
ConditionReferenceMap m_ConditionReferenceMap;
ConditionMap m_ConditionMap;
ConditionReferenceMap m_ConditionReferenceMap;
VehicleSpellConditionMap m_VehicleSpellConditions;
private:
@@ -176,7 +180,8 @@ class ConditionMgr
sourceType == CONDITION_SOURCE_TYPE_SKINNING_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_SPELL_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_GOSSIP_MENU ||
sourceType == CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION);
sourceType == CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION ||
sourceType == CONDITION_SOURCE_TYPE_VEHICLE_SPELL);
}
void Clean(); // free up resources
@@ -19028,6 +19028,12 @@ void Player::VehicleSpellInitialize()
if (!spellInfo)
continue;
ConditionList conditions = sConditionMgr.GetConditionsForVehicleSpell(veh->ToCreature()->GetEntry(), spellId);
if (!sConditionMgr.IsPlayerMeetToConditions(this, conditions))
{
sLog.outDebug("VehicleSpellInitialize: conditions not met for Vehicle entry %u spell %u", veh->ToCreature()->GetEntry(), spellId);
continue;
}
if (IsPassiveSpell(spellId))
{
veh->CastSpell(veh, spellId, true);