Jump to content

Charm spells on players


Auntie Mangos

Recommended Posts

  • 39 years later...

What bug does the patch fix? What features does the patch add?

Implements that players affected with aura type charm start attacking other players.

(Mind controls casted by NPCs on players)

For which repository revision was the patch created?

8756

Is there a thread in the bug report section or at lighthouse? If yes, please add a link to the thread.

i made a bug report but noone replied

Who has been writing this patch? Please include either forum user names or email addresses.

myself, debilvul

From 213c15bc172895a4f229ec6296810a24db21ee28 Mon Sep 17 00:00:00 2001
From: unknown <Tygr@.(none)>
Date: Mon, 2 Nov 2009 13:46:50 +0100
Subject: [PATCH] [8756]Added new function SetPlayerCharmed to make work charm effects on players
---
src/game/SpellAuras.cpp |    3 +++
src/game/Unit.cpp       |   44 ++++++++++++++++++++++++++++++++++++++++++++
src/game/Unit.h         |    1 +
3 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp
index 8af7235..b16435f 100644
--- a/src/game/SpellAuras.cpp
+++ b/src/game/SpellAuras.cpp
@@ -3578,6 +3578,9 @@ void Aura::HandleModCharm(bool apply, bool Real)
                ((Creature*)m_target)->AI()->AttackedBy(caster);
        }
    }
+
+    if(m_target->GetTypeId() == TYPEID_PLAYER)    
+        m_target->SetPlayerCharmed(apply, GetCasterGUID(), GetId());
}

void Aura::HandleModConfuse(bool apply, bool Real)
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index ac5f15d..1d90aea 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -180,6 +180,17 @@ void Unit::Update( uint32 p_time )
    if(!IsInWorld())
        return;

+    // handling charmed effects on players
+    if (GetTypeId() == TYPEID_PLAYER)
+        if (HasAuraType(SPELL_AURA_MOD_CHARM))
+            if (isAttackReady())
+                //If we are within range melee the target
+                if (IsWithinDistInMap(getVictim(), ATTACK_DISTANCE))
+                {
+                    AttackerStateUpdate(getVictim());
+                    resetAttackTimer();
+                }
+
    /*if(p_time > m_AurasCheck)
    {
    m_AurasCheck = 2000;
@@ -11859,6 +11870,39 @@ void Unit::SetConfused(bool apply, uint64 const& casterGUID, uint32 spellID)
        ((Player*)this)->SetClientControl(this, !apply);
}

+void Unit::SetPlayerCharmed(bool apply, uint64 casterGUID, uint32 spellID)
+{
+    if (GetTypeId() != TYPEID_PLAYER)
+        return;
+
+    ((Player*)this)->SetClientControl(this, !apply);
+
+    if (apply)
+        if (Unit* pCaster = ObjectAccessor::GetObjectInWorld(casterGUID, (Unit*)NULL))
+        {
+            std::list<HostilReference*>& threatlist = pCaster->getThreatManager().getThreatList();
+            if (threatlist.size())
+                for (;
+                {
+                    std::list<HostilReference*>::iterator itr = threatlist.begin();
+                    advance(itr,(rand() % (threatlist.size())));
+                    if (Unit* pTarget = Unit::GetUnit((*pCaster),
(*itr)->getUnitGuid()))
+                        if (pTarget != this)
+                        {
+                            GetMotionMaster()->MoveChase(pTarget);
+                            Attack(pTarget,true);       //attack to make a victim for further attacks
+                            break;
+                        }
+                }
+        }
+
+    if (!apply)
+    {
+        GetMotionMaster()->Clear();
+        AttackStop();
+    }
+}
+
void Unit::SetFeignDeath(bool apply, uint64 const& casterGUID, uint32 spellID)
{
    if( apply )
diff --git a/src/game/Unit.h b/src/game/Unit.h
index b481c37..47ef114 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -1510,6 +1510,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject

        void SetFeared(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0, uint32 time = 0);
        void SetConfused(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);
+        void SetPlayerCharmed(bool apply, uint64 const& caterGUID = 0,uint32 spellID = 0);
        void SetFeignDeath(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);

        void AddComboPointHolder(uint32 lowguid) { m_ComboPointHolders.insert(lowguid); }
-- 
1.6.3.msysgit.0

Link to comment
Share on other sites

Please try to avoid for(;;) loops! Try keeping the loop condition inside the for() statement, if possible.

okay, then

for(uint8 i = 0; i < threatlist.size();++i)

could work:)

anyway, feel free to modify and reply

and ofc i forgot this condition:

replace

if (pTarget != this)

with

 if (pTarget != this || !pTarget->isAlive())

Link to comment
Share on other sites

converted to the Player.cpp and added some fixes

From 1e9f700be3e7bcd0e6e1e6304f1ddb3f67a81ea4 Mon Sep 17 00:00:00 2001
From: unknown <>
Date: Sat, 7 Nov 2009 11:17:30 +0100
Subject: [PATCH] added support for charming players
---
src/game/Player.cpp     |   30 ++++++++++++++++++++++++++++++
src/game/Player.h       |    2 ++
src/game/SpellAuras.cpp |    8 ++++++++
3 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index bdf6b53..cc79241 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -4065,6 +4065,36 @@ void Player::SetMovement(PlayerMovementType pType)
    GetSession()->SendPacket( &data );
}

+void Player::SetCharmed(bool apply, uint64 casterGUID, uint32 spellID)
+{
+    SetClientControl(this, !apply);
+
+    if (apply)
+        if (Unit* pCaster = ObjectAccessor::GetObjectInWorld(casterGUID, (Unit*)NULL))
+        {
+            std::list<HostilReference*>& threatlist = pCaster->getThreatManager().getThreatList();
+            if (threatlist.size())
+                for (uint8 i = 0;i < 3;++i)
+                {
+                    std::list<HostilReference*>::iterator itr = threatlist.begin();
+                    advance(itr,(rand() % (threatlist.size())));
+                    if (Unit* pTarget = Unit::GetUnit((*pCaster),
(*itr)->getUnitGuid()))
+                        if (pTarget != this || !pTarget->isAlive())
+                        {
+                            GetMotionMaster()->MoveChase(pTarget);
+                            Attack(pTarget,true);       //attack to make a victim for further attacks
+                            break;
+                        }
+                }
+        }
+
+    if (!apply)
+    {
+        GetMotionMaster()->Clear();
+        AttackStop();
+    }
+}
+
/* Preconditions:
  - a resurrectable corpse must not be loaded for the player (only bones)
  - the player must be in world
diff --git a/src/game/Player.h b/src/game/Player.h
index a6b1ea7..4afa91b 100644
--- a/src/game/Player.h
+++ b/src/game/Player.h
@@ -1811,6 +1811,8 @@ class MANGOS_DLL_SPEC Player : public Unit

        void SetMovement(PlayerMovementType pType);

+        void SetCharmed(bool apply, uint64 casterGUID, uint32 spellID)
+
        void JoinedChannel(Channel *c);
        void LeftChannel(Channel *c);
        void CleanupChannels();
diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp
index 8af7235..ba0b645 100644
--- a/src/game/SpellAuras.cpp
+++ b/src/game/SpellAuras.cpp
@@ -3490,6 +3490,11 @@ void Aura::HandleModCharm(bool apply, bool Real)

    if( apply )
    {
+        //cannot charm only one player enemy
+        if(m_target->GetTypeId() == TYPEID_PLAYER)
+            if(caster->getThreatManager().getThreatList().size() < 2)
+                return;
+
        m_target->SetCharmerGUID(GetCasterGUID());
        m_target->setFaction(caster->getFaction());
        m_target->CastStop(m_target == caster ? GetId() : 0);
@@ -3578,6 +3583,9 @@ void Aura::HandleModCharm(bool apply, bool Real)
                ((Creature*)m_target)->AI()->AttackedBy(caster);
        }
    }
+
+    if(m_target->GetTypeId() == TYPEID_PLAYER)
+        ((Player*)m_target)->SetCharmed(apply, GetCasterGUID(), GetId());
}

void Aura::HandleModConfuse(bool apply, bool Real)
-- 
1.6.3.msysgit.0

Link to comment
Share on other sites

I cant test it, because on my test server is only one player, but can other players attack the MC's one? For example polymorph him or he is still friendly?

of course, before this patch when you were MCd only faction was changed, so you could polymorph them, my patch only makes the MCd ones attack another

Link to comment
Share on other sites

  • 3 months later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use