*Allow pets to cast devour magic on both friends and enemies.

--HG--
branch : trunk
This commit is contained in:
megamage
2008-12-10 15:14:49 -06:00
parent 4182df058c
commit bcb39b263d
5 changed files with 61 additions and 26 deletions
+4 -4
View File
@@ -788,7 +788,7 @@ enum Targets
TARGET_PET = 5, TARGET_PET = 5,
//TARGET_UNIT_PET //TARGET_UNIT_PET
TARGET_CHAIN_DAMAGE = 6, TARGET_CHAIN_DAMAGE = 6,
//TARGET_UNIT_TARGET_ENEMY TARGET_UNIT_TARGET_ENEMY = 6,
TARGET_UNIT_AREA_ENTRY = 7, TARGET_UNIT_AREA_ENTRY = 7,
TARGET_AREAEFFECT_CUSTOM = 8, TARGET_AREAEFFECT_CUSTOM = 8,
//TARGET_UNIT_AREA_ENTRY_GROUND //TARGET_UNIT_AREA_ENTRY_GROUND
@@ -806,7 +806,7 @@ enum Targets
TARGET_ALL_PARTY_AROUND_CASTER = 20, TARGET_ALL_PARTY_AROUND_CASTER = 20,
//TARGET_UNIT_PARTY_CASTER //TARGET_UNIT_PARTY_CASTER
TARGET_SINGLE_FRIEND = 21, TARGET_SINGLE_FRIEND = 21,
//TARGET_UNIT_TARGET_ALLY TARGET_UNIT_TARGET_ALLY = 21,
TARGET_ALL_AROUND_CASTER = 22, // used only in TargetA, target selection dependent from TargetB TARGET_ALL_AROUND_CASTER = 22, // used only in TargetA, target selection dependent from TargetB
//TARGET_DEST_CASTER //TARGET_DEST_CASTER
TARGET_GAMEOBJECT = 23, TARGET_GAMEOBJECT = 23,
@@ -833,7 +833,7 @@ enum Targets
TARGET_ALL_PARTY_AROUND_CASTER_2 = 34, // used in Tranquility TARGET_ALL_PARTY_AROUND_CASTER_2 = 34, // used in Tranquility
//TARGET_UNIT_AREA_PARTY_GROUND //TARGET_UNIT_AREA_PARTY_GROUND
TARGET_SINGLE_PARTY = 35, TARGET_SINGLE_PARTY = 35,
//TARGET_UNIT_TARGET_PARTY TARGET_UNIT_TARGET_PARTY = 35,
TARGET_DEST_CASTER_RANDOM_UNKNOWN = 36, //unknown TARGET_DEST_CASTER_RANDOM_UNKNOWN = 36, //unknown
TARGET_AREAEFFECT_PARTY = 37, TARGET_AREAEFFECT_PARTY = 37,
//TARGET_UNIT_PARTY_TARGET //TARGET_UNIT_PARTY_TARGET
@@ -864,7 +864,7 @@ enum Targets
TARGET_RANDOM_RAID_MEMBER = 56, TARGET_RANDOM_RAID_MEMBER = 56,
//TARGET_UNIT_AREA_RAID //TARGET_UNIT_AREA_RAID
TARGET_SINGLE_FRIEND_2 = 57, TARGET_SINGLE_FRIEND_2 = 57,
//TARGET_UNIT_TARGET_RAID TARGET_UNIT_TARGET_RAID = 57,
TARGET_UNIT_CONE_ALLY = 59, TARGET_UNIT_CONE_ALLY = 59,
TARGET_UNIT_AREA_SCRIPT = 60, TARGET_UNIT_AREA_SCRIPT = 60,
TARGET_AREAEFFECT_PARTY_AND_CLASS = 61, TARGET_AREAEFFECT_PARTY_AND_CLASS = 61,
+30 -19
View File
@@ -4496,26 +4496,8 @@ int16 Spell::PetCanCast(Unit* target)
if(!_target->isAlive()) if(!_target->isAlive())
return SPELL_FAILED_BAD_TARGETS; return SPELL_FAILED_BAD_TARGETS;
if(IsPositiveSpell(m_spellInfo->Id)) if(!IsValidSingleTargetSpell(_target))
{
if(m_caster->IsHostileTo(_target))
return SPELL_FAILED_BAD_TARGETS; return SPELL_FAILED_BAD_TARGETS;
}
else
{
bool duelvsplayertar = false;
for(int j=0;j<3;j++)
{
//TARGET_DUELVSPLAYER is positive AND negative
duelvsplayertar |= (m_spellInfo->EffectImplicitTargetA[j] == TARGET_DUELVSPLAYER);
}
// AoE spells have the caster as their target
// AOE spells should not have target
if(m_caster->IsFriendlyTo(target) /*&& m_caster != target*/ && !duelvsplayertar)
{
return SPELL_FAILED_BAD_TARGETS;
}
}
} }
//cooldown //cooldown
if(((Creature*)m_caster)->HasSpellCooldown(m_spellInfo->Id)) if(((Creature*)m_caster)->HasSpellCooldown(m_spellInfo->Id))
@@ -5553,3 +5535,32 @@ bool SpellEvent::IsDeletable() const
{ {
return m_Spell->IsDeletable(); return m_Spell->IsDeletable();
} }
bool Spell::IsValidSingleTargetEffect(Unit const* target, Targets type) const
{
switch(type)
{
case TARGET_UNIT_TARGET_ENEMY:
return !m_caster->IsFriendlyTo(target);
case TARGET_UNIT_TARGET_ALLY:
return m_caster->IsFriendlyTo(target);
case TARGET_UNIT_TARGET_PARTY:
return m_caster->IsInPartyWith(target);
case TARGET_UNIT_TARGET_RAID:
return m_caster->IsInRaidWith(target);
}
return true;
}
bool Spell::IsValidSingleTargetSpell(Unit const* target) const
{
for(int i = 0; i < 3; ++i)
{
if(!IsValidSingleTargetEffect(target, Targets(m_spellInfo->EffectImplicitTargetA[i])))
return false;
// Need to check B?
//if(!IsValidSingleTargetEffect(m_spellInfo->EffectImplicitTargetB[i], target)
// return false;
}
return true;
}
+2
View File
@@ -537,6 +537,8 @@ class Spell
SpellTargets TargetType, uint32 entry = 0); SpellTargets TargetType, uint32 entry = 0);
Unit* SearchNearbyTarget(float radius, SpellTargets TargetType, uint32 entry = 0); Unit* SearchNearbyTarget(float radius, SpellTargets TargetType, uint32 entry = 0);
void SearchChainTarget(std::list<Unit*> &data, Unit* pUnitTarget, float max_range, uint32 unMaxTargets); void SearchChainTarget(std::list<Unit*> &data, Unit* pUnitTarget, float max_range, uint32 unMaxTargets);
bool IsValidSingleTargetEffect(Unit const* target, Targets type) const;
bool IsValidSingleTargetSpell(Unit const* target) const;
// ------------------------------------------- // -------------------------------------------
//List For Triggered Spells //List For Triggered Spells
+21 -1
View File
@@ -8303,7 +8303,7 @@ Unit *Unit::GetCharmer() const
return NULL; return NULL;
} }
Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself() Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself() const
{ {
uint64 guid = GetCharmerOrOwnerGUID(); uint64 guid = GetCharmerOrOwnerGUID();
if(IS_PLAYER_GUID(guid)) if(IS_PLAYER_GUID(guid))
@@ -12835,3 +12835,23 @@ void Unit::SetConfused(bool apply)
if(GetTypeId() == TYPEID_PLAYER) if(GetTypeId() == TYPEID_PLAYER)
((Player*)this)->SetClientControl(this, !apply); ((Player*)this)->SetClientControl(this, !apply);
} }
bool Unit::IsInPartyWith(Unit const *unit) const
{
const Player *p1 = GetCharmerOrOwnerPlayerOrPlayerItself();
const Player *p2 = unit->GetCharmerOrOwnerPlayerOrPlayerItself();
if(p1 && p2)
return p1->IsInSameGroupWith(p2);
else
return false;
}
bool Unit::IsInRaidWith(Unit const *unit) const
{
const Player *p1 = GetCharmerOrOwnerPlayerOrPlayerItself();
const Player *p2 = unit->GetCharmerOrOwnerPlayerOrPlayerItself();
if(p1 && p2)
return p1->IsInSameRaidWith(p2);
else
return false;
}
+3 -1
View File
@@ -871,6 +871,8 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
bool IsHostileToPlayers() const; bool IsHostileToPlayers() const;
bool IsFriendlyTo(Unit const* unit) const; bool IsFriendlyTo(Unit const* unit) const;
bool IsNeutralToAll() const; bool IsNeutralToAll() const;
bool IsInPartyWith(Unit const* unit) const;
bool IsInRaidWith(Unit const* unit) const;
bool IsContestedGuard() const bool IsContestedGuard() const
{ {
if(FactionTemplateEntry const* entry = getFactionTemplateEntry()) if(FactionTemplateEntry const* entry = getFactionTemplateEntry())
@@ -1055,7 +1057,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
return this; return this;
} }
Player* GetCharmerOrOwnerPlayerOrPlayerItself(); Player* GetCharmerOrOwnerPlayerOrPlayerItself() const;
void SetPet(Pet* pet); void SetPet(Pet* pet);
void SetCharm(Unit* pet); void SetCharm(Unit* pet);