[core-zero]mod charm support
Copied from github issues: [url]https://github.com/mangoszero/server/issues/26[/url]
[COLOR=#999999][FONT=Helvetica][URL="https://github.com/Neilyo-X"]Neilyo-X[/URL] commented [URL="https://github.com/mangoszero/server/issues/26#issue-80858455"]5 days ago[/URL]
[/FONT][/COLOR]
[COLOR=#333333][FONT=Helvetica][FONT=Helvetica Neue]all spells that used by creature to charm the player are unwork,maybe lack of core support(sorry for my poor english)
[/FONT]
[/FONT][/COLOR]
[QUOTE][COLOR=#333333][FONT=Helvetica Neue]i have found one core which the charm systerm is work right.
i will post the code but it is used in TC,not for mangos.
i can not read the code very clear.[/FONT][/COLOR]
maybe others will have some idea
[/QUOTE]
[COLOR=#333333][FONT=Helvetica Neue]void Aura::HandleModPossess(bool apply, bool Real)
{
if(!Real)
return;[/FONT][/COLOR]
Unit* caster = GetCaster();
if(caster && caster->GetTypeId() == TYPEID_UNIT)
{
HandleModCharm(apply, Real);
return;
}
if(apply)
{
if(m_target->getLevel() > m_modifier.m_amount)
return;
m_target->SetCharmedOrPossessedBy(caster, true);
}
else
m_target->RemoveCharmedOrPossessedBy(caster);
}
[COLOR=#333333][FONT=Helvetica Neue]Unit* Unit::GetCharm() const
{
if(uint64 charm_guid = GetCharmGUID())
{
if(Unit* pet = ObjectAccessor::GetUnit(*this, charm_guid))
return pet;[/FONT][/COLOR]
sLog.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid));
const_cast
}
return NULL;
}
[COLOR=#333333][FONT=Helvetica Neue]void Unit::SetCharm(Unit* pet)
{
if(GetTypeId() == TYPEID_PLAYER)
SetUInt64Value(UNIT_FIELD_CHARM, pet ? pet->GetGUID() : 0);[/FONT][/COLOR]
[h=1]}[/h]
[COLOR=#333333][FONT=Helvetica Neue]void Unit::SetCharmedOrPossessedBy(Unit* charmer, bool possess)
{
if(!charmer)
return;[/FONT][/COLOR]
assert(!possess || charmer->GetTypeId() == TYPEID_PLAYER);
if(this == charmer)
return;
if(isInFlight())
return;
if(GetTypeId() == TYPEID_PLAYER && ((Player*)this)->GetTransport())
return;
RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
CastStop();
CombatStop(); //TODO: CombatStop(true) may cause crash (interrupt spells)
DeleteThreatList();
// Charmer stop charming
if(charmer->GetTypeId() == TYPEID_PLAYER)
((Player*)charmer)->StopCastingCharm();
// Charmed stop charming
if(GetTypeId() == TYPEID_PLAYER)
((Player*)this)->StopCastingCharm();
// StopCastingCharm may remove a possessed pet?
if(!IsInWorld())
return;
// Set charmed
charmer->SetCharm(this);
SetCharmerGUID(charmer->GetGUID());
setFaction(charmer->getFaction());
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
if(GetTypeId() == TYPEID_UNIT)
{
((Creature*)this)->AI()->OnCharmed(true);
GetMotionMaster()->Clear(false);
GetMotionMaster()->MoveIdle();
}
else
{
if(((Player*)this)->isAFK())
((Player*)this)->ToggleAFK();
((Player*)this)->SetViewport(GetGUID(), false);
}
// Pets already have a properly initialized CharmInfo, don't overwrite it.
if(GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet())
{
CharmInfo *charmInfo = InitCharmInfo();
if(possess)
charmInfo->InitPossessCreateSpells();
else
charmInfo->InitCharmCreateSpells();
}
//Set possessed
if(possess)
{
addUnitState(UNIT_STAT_POSSESSED);
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNKNOWN5);
AddPlayerToVision((Player*)charmer);
((Player*)charmer)->SetViewport(GetGUID(), true);
charmer->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE);
}
// Charm demon
else if(GetTypeId() == TYPEID_UNIT && charmer->GetTypeId() == TYPEID_PLAYER && charmer->getClass() == CLASS_WARLOCK)
{
CreatureInfo const *cinfo = ((Creature*)this)->GetCreatureInfo();
if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
{
//to prevent client crash
SetFlag(UNIT_FIELD_BYTES_0, 2048);
//just to enable stat window
if(GetCharmInfo())
GetCharmInfo()->SetPetNumber(objmgr.GeneratePetNumber(), true);
//if charmed two demons the same session, the 2nd gets the 1st one's name
SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
}
}
if(possess)
((Player*)charmer)->PossessSpellInitialize();
else if(charmer->GetTypeId() == TYPEID_PLAYER)
((Player*)charmer)->CharmSpellInitialize();
[COLOR=#333333][FONT=Helvetica Neue]}[/FONT][/COLOR]
[COLOR=#333333][FONT=Helvetica Neue]void Unit::RemoveCharmedOrPossessedBy(Unit *charmer)
{
if(!isCharmed())
return;[/FONT][/COLOR]
if(!charmer)
charmer = GetCharmer();
else if(charmer != GetCharmer()) // one aura overrides another?
return;
bool possess = hasUnitState(UNIT_STAT_POSSESSED);
CastStop();
CombatStop(); //TODO: CombatStop(true) may cause crash (interrupt spells)
getHostilRefManager().deleteReferences();
DeleteThreatList();
SetCharmerGUID(0);
RestoreFaction();
if(possess)
{
clearUnitState(UNIT_STAT_POSSESSED);
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNKNOWN5);
}
if(GetTypeId() == TYPEID_UNIT)
{
if(!((Creature*)this)->isPet())
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
((Creature*)this)->AI()->OnCharmed(false);
if(isAlive() && ((Creature*)this)->IsAIEnabled)
{
if(charmer && !IsFriendlyTo(charmer))
{
((Creature*)this)->AddThreat(charmer, 10000.0f);
((Creature*)this)->AI()->AttackStart(charmer);
}
else
((Creature*)this)->AI()->EnterEvadeMode();
}
}
else
((Player*)this)->SetViewport(GetGUID(), true);
// If charmer still exists
if(!charmer)
return;
assert(!possess || charmer->GetTypeId() == TYPEID_PLAYER);
charmer->SetCharm(0);
if(possess)
{
RemovePlayerFromVision((Player*)charmer);
((Player*)charmer)->SetViewport(charmer->GetGUID(), true);
charmer->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE);
}
// restore UNIT_FIELD_BYTES_0
else if(GetTypeId() == TYPEID_UNIT && charmer->GetTypeId() == TYPEID_PLAYER && charmer->getClass() == CLASS_WARLOCK)
{
CreatureInfo const *cinfo = ((Creature*)this)->GetCreatureInfo();
if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
{
CreatureDataAddon const *cainfo = ((Creature*)this)->GetCreatureAddon();
if(cainfo && cainfo->bytes0 != 0)
SetUInt32Value(UNIT_FIELD_BYTES_0, cainfo->bytes0);
else
RemoveFlag(UNIT_FIELD_BYTES_0, 2048);
if(GetCharmInfo())
GetCharmInfo()->SetPetNumber(0, true);
else
sLog.outError("Aura::HandleModCharm: target="I64FMTD" with typeid=%d has a charm aura but no charm info!", GetGUID(), GetTypeId());
}
}
if(GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet())
{
DeleteCharmInfo();
}
if(possess || charmer->GetTypeId() == TYPEID_PLAYER)
{
// Remove pet spell action bar
WorldPacket data(SMSG_PET_SPELLS, 8);
data ((Player*)charmer)->GetSession()->SendPacket(&data);
}
[COLOR=#333333][FONT=Helvetica Neue]}[/FONT][/COLOR]
[COLOR=#333333][FONT=Helvetica Neue]void Unit::RestoreFaction()
{
if(GetTypeId() == TYPEID_PLAYER)
((Player[I])this)->setFactionForRace(getRace());
else
{
CreatureInfo const *cinfo = ((Creature[/I])this)->GetCreatureInfo();[/FONT][/COLOR]
if(((Creature*)this)->isPet())
{
if(Unit* owner = GetOwner())
setFaction(owner->getFaction());
else if(cinfo)
setFaction(cinfo->faction_A);
}
else if(cinfo) // normal creature
setFaction(cinfo->faction_A);
}
[h=1]}[/h][QUOTE][COLOR=#333333][FONT=Helvetica Neue]sorry i know it is hard to read.
but this is all the files i can find,maybe will help others to fix the mod charm systerm[/FONT][/COLOR]
[/QUOTE]
Recommended Comments
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now