All pastes #917352 Raw Edit

Something

public text v1 · immutable
#917352 ·published 2008-02-25 09:16 UTC
rendered paste body
Index: src/game/Player.cpp
===================================================================
--- src/game/Player.cpp	(revision 5305)
+++ src/game/Player.cpp	(working copy)
@@ -14481,7 +14481,45 @@
 
     charm->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM);
     charm->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS);
+	if(charm->GetTypeId() == TYPEID_UNIT)
+	{
+        // restore factions
+		CreatureInfo const *cinfo = ((Creature*)charm)->GetCreatureInfo();
+        if(((Creature*)charm)->isPet())
+        {
+        if(Unit* owner = charm->GetOwner())
+        charm->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,owner->getFaction());
+        else if(cinfo)
+        charm->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
+        }
+        else if(cinfo)                              // normal creature
+        charm->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
+		
+		// restore UNIT_FIELD_BYTES_0
+        if(cinfo && getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
+        {
+        CreatureDataAddon const *cainfo = ((Creature*)charm)->GetCreatureAddon();
+        if(cainfo && cainfo->bytes0 != 0)
+        charm->SetUInt32Value(UNIT_FIELD_BYTES_0, cainfo->bytes0);
+        else charm->RemoveFlag(UNIT_FIELD_BYTES_0, 2048);
+		if(charm->GetCharmInfo())
+        charm->GetCharmInfo()->SetPetNumber(0, true);
+        else
+        sLog.outError("Uncharm: target="I64FMTD" with typeid=%d has a charm aura but no charm info!", charm->GetGUID(), charm->GetTypeId());
+        }
 
+		// restore movementgenerators
+		charm->StopMoving();
+        charm->GetMotionMaster()->MovementExpired(false);
+		if(charm->getVictim())
+        charm->GetMotionMaster()->Mutate(new TargetedMovementGenerator<Creature>(*charm->getVictim()));
+        else  charm->GetMotionMaster()->Initialize();
+		// reinit AI
+		((Creature*)charm)->AIM_Initialize();
+  	}
+	else ((Player*)charm)->setFactionForRace(charm->getRace());
+	charm->SetCharmerGUID(0);   // delete link to player from charmers
+	SetCharm(0); // delete link to charmers from players
 }
 
 void Player::Say(const std::string text, const uint32 language)