*Fix that bug that charmed player still be charmed even after death.
--HG-- branch : trunk
This commit is contained in:
+77
-75
@@ -2945,85 +2945,93 @@ void Aura::HandleModCharm(bool apply, bool Real)
|
||||
return;
|
||||
|
||||
Unit* caster = GetCaster();
|
||||
if(!caster)
|
||||
return;
|
||||
|
||||
if(int32(m_target->getLevel()) <= m_modifier.m_amount)
|
||||
if( apply )
|
||||
{
|
||||
if( apply )
|
||||
if(!caster)
|
||||
return;
|
||||
|
||||
if(int32(m_target->getLevel()) > m_modifier.m_amount)
|
||||
return;
|
||||
|
||||
m_target->SetCharmerGUID(GetCasterGUID());
|
||||
m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,caster->getFaction());
|
||||
m_target->CastStop(m_target==caster ? GetId() : 0);
|
||||
caster->SetCharm(m_target);
|
||||
|
||||
m_target->CombatStop();
|
||||
m_target->DeleteThreatList();
|
||||
|
||||
if(m_target->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
m_target->SetCharmerGUID(GetCasterGUID());
|
||||
m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,caster->getFaction());
|
||||
m_target->CastStop(m_target==caster ? GetId() : 0);
|
||||
caster->SetCharm(m_target);
|
||||
((Creature*)m_target)->AIM_Initialize();
|
||||
CharmInfo *charmInfo = ((Creature*)m_target)->InitCharmInfo(m_target);
|
||||
charmInfo->InitCharmCreateSpells();
|
||||
charmInfo->SetReactState( REACT_DEFENSIVE );
|
||||
|
||||
m_target->CombatStop();
|
||||
m_target->DeleteThreatList();
|
||||
|
||||
if(m_target->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
((Creature*)m_target)->AIM_Initialize();
|
||||
CharmInfo *charmInfo = ((Creature*)m_target)->InitCharmInfo(m_target);
|
||||
charmInfo->InitCharmCreateSpells();
|
||||
charmInfo->SetReactState( REACT_DEFENSIVE );
|
||||
|
||||
if(caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK)
|
||||
{
|
||||
CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
|
||||
if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
|
||||
{
|
||||
//to prevent client crash
|
||||
m_target->SetFlag(UNIT_FIELD_BYTES_0, 2048);
|
||||
//just to enable stat window
|
||||
charmInfo->SetPetNumber(objmgr.GeneratePetNumber(), true);
|
||||
//if charmed two demons the same session, the 2nd gets the 1st one's name
|
||||
m_target->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(caster->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
((Player*)caster)->CharmSpellInitialize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_target->SetCharmerGUID(0);
|
||||
|
||||
if(m_target->GetTypeId() == TYPEID_PLAYER)
|
||||
((Player*)m_target)->setFactionForRace(m_target->getRace());
|
||||
else
|
||||
if(caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK)
|
||||
{
|
||||
CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
|
||||
|
||||
// restore faction
|
||||
if(((Creature*)m_target)->isPet())
|
||||
if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
|
||||
{
|
||||
if(Unit* owner = m_target->GetOwner())
|
||||
m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,owner->getFaction());
|
||||
else if(cinfo)
|
||||
m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
|
||||
}
|
||||
else if(cinfo) // normal creature
|
||||
m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
|
||||
|
||||
// restore UNIT_FIELD_BYTES_0
|
||||
if(cinfo && caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
|
||||
{
|
||||
CreatureDataAddon const *cainfo = ((Creature*)m_target)->GetCreatureAddon();
|
||||
if(cainfo && cainfo->bytes0 != 0)
|
||||
m_target->SetUInt32Value(UNIT_FIELD_BYTES_0, cainfo->bytes0);
|
||||
else
|
||||
m_target->RemoveFlag(UNIT_FIELD_BYTES_0, 2048);
|
||||
|
||||
if(m_target->GetCharmInfo())
|
||||
m_target->GetCharmInfo()->SetPetNumber(0, true);
|
||||
else
|
||||
sLog.outError("Aura::HandleModCharm: target="I64FMTD" with typeid=%d has a charm aura but no charm info!", m_target->GetGUID(), m_target->GetTypeId());
|
||||
//to prevent client crash
|
||||
m_target->SetFlag(UNIT_FIELD_BYTES_0, 2048);
|
||||
//just to enable stat window
|
||||
charmInfo->SetPetNumber(objmgr.GeneratePetNumber(), true);
|
||||
//if charmed two demons the same session, the 2nd gets the 1st one's name
|
||||
m_target->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(caster->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
((Player*)caster)->CharmSpellInitialize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_target->SetCharmerGUID(0);
|
||||
|
||||
if(m_target->GetTypeId() == TYPEID_PLAYER)
|
||||
((Player*)m_target)->setFactionForRace(m_target->getRace());
|
||||
else
|
||||
{
|
||||
CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
|
||||
|
||||
// restore faction
|
||||
if(((Creature*)m_target)->isPet())
|
||||
{
|
||||
if(Unit* owner = m_target->GetOwner())
|
||||
m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,owner->getFaction());
|
||||
else if(cinfo)
|
||||
m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
|
||||
}
|
||||
else if(cinfo) // normal creature
|
||||
m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
|
||||
|
||||
// restore UNIT_FIELD_BYTES_0
|
||||
if(caster && cinfo && caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
|
||||
{
|
||||
CreatureDataAddon const *cainfo = ((Creature*)m_target)->GetCreatureAddon();
|
||||
if(cainfo && cainfo->bytes0 != 0)
|
||||
m_target->SetUInt32Value(UNIT_FIELD_BYTES_0, cainfo->bytes0);
|
||||
else
|
||||
m_target->RemoveFlag(UNIT_FIELD_BYTES_0, 2048);
|
||||
|
||||
if(m_target->GetCharmInfo())
|
||||
m_target->GetCharmInfo()->SetPetNumber(0, true);
|
||||
else
|
||||
sLog.outError("Aura::HandleModCharm: target="I64FMTD" with typeid=%d has a charm aura but no charm info!", m_target->GetGUID(), m_target->GetTypeId());
|
||||
}
|
||||
|
||||
((Creature*)m_target)->AIM_Initialize();
|
||||
if(((Creature*)m_target)->AI() && caster)
|
||||
((Creature*)m_target)->AI()->AttackStart(caster);
|
||||
}
|
||||
|
||||
if(caster)
|
||||
{
|
||||
caster->SetCharm(0);
|
||||
|
||||
if(caster->GetTypeId() == TYPEID_PLAYER)
|
||||
@@ -3032,12 +3040,6 @@ void Aura::HandleModCharm(bool apply, bool Real)
|
||||
data << uint64(0);
|
||||
((Player*)caster)->GetSession()->SendPacket(&data);
|
||||
}
|
||||
if(m_target->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
((Creature*)m_target)->AIM_Initialize();
|
||||
if (((Creature*)m_target)->AI())
|
||||
((Creature*)m_target)->AI()->AttackStart(caster);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user