Core/Disables: Add flags SPELL_DISABLE_MAP and SPELL_DISABLE_AREA for sourceType DISABLE_TYPE_SPELL.

This will allow you to disable spells on certain maps/areas. Note that you must have at least flag SPELL_DISABLE_PLAYER or SPELL_DISABLE_CREATURE or SPELL_DISABLE_PET set too, as they take preference.
The parameters for mapIds and areaIds are defined in new columns params_0 and params_1 respectively, in a comma-seperated string.

Example:
INSERT INTO disables VALUES(0, 8921, (1+16+32), "571,1", "1519", "Moonfire Example");

This will disable spell moonfire for players in maps 571,1 and area 1519.

--HG--
branch : trunk
This commit is contained in:
Machiavelli
2010-12-04 18:29:14 +01:00
parent 3240a4ec33
commit b9fb7554c5
5 changed files with 81 additions and 24 deletions

View File

@@ -42,7 +42,7 @@ void DisableMgr::LoadDisables()
m_DisableMap.clear();
QueryResult result = WorldDatabase.Query("SELECT sourceType,entry,flags FROM disables");
QueryResult result = WorldDatabase.Query("SELECT sourceType,entry,flags,params_0,params_1 FROM disables");
uint32 total_count = 0;
@@ -69,22 +69,46 @@ void DisableMgr::LoadDisables()
sLog.outErrorDb("Invalid type %u specified in `disables` table, skipped.", type);
continue;
}
uint32 entry = fields[1].GetUInt32();
uint8 flags = fields[2].GetUInt8();
std::string params_0 = fields[3].GetString();
std::string params_1 = fields[4].GetString();
DisableData data;
data.flags = flags;
switch (type)
{
case DISABLE_TYPE_SPELL:
{
if (!(sSpellStore.LookupEntry(entry) || flags & SPELL_DISABLE_DEPRECATED_SPELL))
{
sLog.outErrorDb("Spell entry %u from `disables` doesn't exist in dbc, skipped.", entry);
continue;
}
if (!flags || flags > 15)
if (!flags || flags > MAX_SPELL_DISABLE_TYPE)
{
sLog.outErrorDb("Disable flags for spell %u are invalid, skipped.", entry);
continue;
}
break;
if (flags & SPELL_DISABLE_MAP)
{
Tokens tokens(params_0, ',');
for (uint8 i = 0; i < tokens.size(); )
data.params[0].insert(atoi(tokens[i++]));
}
if (flags & SPELL_DISABLE_AREA)
{
Tokens tokens(params_1, ',');
for (uint8 i = 0; i < tokens.size(); )
data.params[1].insert(atoi(tokens[i++]));
}
} break;
// checked later
case DISABLE_TYPE_QUEST:
break;
@@ -153,7 +177,7 @@ void DisableMgr::LoadDisables()
break;
}
m_DisableMap[type].insert(DisableTypeMap::value_type(entry, flags));
m_DisableMap[type].insert(DisableTypeMap::value_type(entry, data));
++total_count;
}
while (result->NextRow());
@@ -186,7 +210,7 @@ void DisableMgr::CheckQuestDisables()
m_DisableMap[DISABLE_TYPE_QUEST].erase(itr++);
continue;
}
if (itr->second)
if (itr->second.flags)
sLog.outErrorDb("Disable flags specified for quest %u, useless data.", entry);
++itr;
}
@@ -209,21 +233,38 @@ bool DisableMgr::IsDisabledFor(DisableType type, uint32 entry, Unit const* pUnit
{
case DISABLE_TYPE_SPELL:
{
uint8 flags = itr->second;
uint8 flags = itr->second.flags;
if (pUnit)
{
if (flags & SPELL_DISABLE_PLAYER && pUnit->GetTypeId() == TYPEID_PLAYER)
return true;
else if (pUnit->GetTypeId() == TYPEID_UNIT)
if ((flags & SPELL_DISABLE_PLAYER && pUnit->GetTypeId() == TYPEID_PLAYER) ||
(pUnit->GetTypeId() == TYPEID_UNIT && (pUnit->ToCreature()->isPet() && flags & SPELL_DISABLE_PET || flags & SPELL_DISABLE_CREATURE)))
{
if (pUnit->ToCreature()->isPet())
if (flags & SPELL_DISABLE_MAP)
{
if (flags & SPELL_DISABLE_PET)
return true;
std::set<uint32> const& mapIds = itr->second.params[0];
if (mapIds.find(pUnit->GetMapId()) != mapIds.end())
return true; // Spell is disabled on current map
if (!(flags & SPELL_DISABLE_AREA))
return false; // Spell is disabled on another map, but not this one, return false
// Spell is disabled in an area, but not explicitly our current mapId. Continue processing.
}
else if (flags & SPELL_DISABLE_CREATURE)
return true;
if (flags & SPELL_DISABLE_AREA)
{
std::set<uint32> const& areaIds = itr->second.params[1];
if (areaIds.find(pUnit->GetAreaId()) != areaIds.end())
return true; // Spell is disabled in this area
return false; // Spell is disabled in another area, but not this one, return false
}
else
return true; // Spell disabled for all maps
}
return false;
}
else if (flags & SPELL_DISABLE_DEPRECATED_SPELL) // call not from spellcast
@@ -235,7 +276,7 @@ bool DisableMgr::IsDisabledFor(DisableType type, uint32 entry, Unit const* pUnit
MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
if (mapEntry->IsDungeon())
{
uint8 disabledModes = itr->second;
uint8 disabledModes = itr->second.flags;
Difficulty targetDifficulty = pPlayer->GetDifficulty(mapEntry->IsRaid());
GetDownscaledMapDifficultyData(entry, targetDifficulty);
switch(targetDifficulty)

View File

@@ -20,6 +20,7 @@
#define TRINITY_DISABLEMGR_H
#include <ace/Singleton.h>
class Unit;
enum DisableType
@@ -32,9 +33,27 @@ enum DisableType
DISABLE_TYPE_OUTDOORPVP = 5,
};
enum SpellDisableTypes
{
SPELL_DISABLE_PLAYER = 0x1,
SPELL_DISABLE_CREATURE = 0x2,
SPELL_DISABLE_PET = 0x4,
SPELL_DISABLE_DEPRECATED_SPELL = 0x8,
SPELL_DISABLE_MAP = 0x10,
SPELL_DISABLE_AREA = 0x20,
MAX_SPELL_DISABLE_TYPE = ( SPELL_DISABLE_PLAYER | SPELL_DISABLE_CREATURE | SPELL_DISABLE_PET |
SPELL_DISABLE_DEPRECATED_SPELL | SPELL_DISABLE_MAP | SPELL_DISABLE_AREA),
};
#define MAX_DISABLE_TYPES 6
typedef std::map<uint32, uint8> DisableTypeMap; // single disables here with optional data
struct DisableData
{
uint8 flags;
std::set<uint32> params[2]; // params0, params1
};
typedef std::map<uint32, DisableData> DisableTypeMap; // single disables here with optional data
typedef std::map<DisableType, DisableTypeMap> DisableMap; // global disable map by source
class DisableMgr

View File

@@ -48,14 +48,6 @@ enum SpellCategories
SPELLCATEGORY_DRINK = 59,
};
enum SpellDisableTypes
{
SPELL_DISABLE_PLAYER = 0x1,
SPELL_DISABLE_CREATURE = 0x2,
SPELL_DISABLE_PET = 0x4,
SPELL_DISABLE_DEPRECATED_SPELL = 0x8
};
enum SpellEffectTargetTypes
{
SPELL_REQUIRE_NONE,