All pastes #967111 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-04-02 05:51 UTC
rendered paste body
void Aura::HandleModConfuse(bool apply, bool Real)
{
    Unit* caster = GetCaster();

    if( apply )
    {
        m_target->addUnitState(UNIT_STAT_CONFUSED);
        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);

        if(m_target->GetTypeId() == TYPEID_PLAYER)
        {
            Player *player = (Player*)m_target;
            WorldPacket data(SMSG_DEATH_NOTIFY_OBSOLETE, 10);
            data.append(player->GetPackGUID());             // target's viewpoint
            data << uint8(0x00);                            // movement disabled
            player->GetSession()->SendPacket(&data);
        }

        // Rogue/Blind ability stops attack
        // TODO: does all confuses ?
        if (caster && GetSpellProto()->SpellFamilyName == SPELLFAMILY_ROGUE &&
            (GetSpellProto()->Mechanic == MECHANIC_CONFUSED || GetSpellProto()->EffectMechanic[GetEffIndex()] == MECHANIC_CONFUSED))
            caster->AttackStop();

        // only at real add aura
        if(Real)
        {
            //This fixes blind so it doesn't continue to attack
            // TODO: may other spells casted confuse aura (but not all) stop attack
            if(caster && caster->GetTypeId() == TYPEID_PLAYER &&
                GetSpellProto()->SpellFamilyName == SPELLFAMILY_ROGUE &&
                (GetSpellProto()->Mechanic == MECHANIC_CONFUSED || GetSpellProto()->EffectMechanic[GetEffIndex()] == MECHANIC_CONFUSED))
                caster->AttackStop();

            if (m_target->GetTypeId() == TYPEID_UNIT)
                m_target->GetMotionMaster()->Mutate(new ConfusedMovementGenerator<Creature>(*((Creature*)m_target)));
            else
                m_target->GetMotionMaster()->Mutate(new ConfusedMovementGenerator<Player>(*((Player*)m_target)));
        }
    }
    else
    {
        m_target->clearUnitState(UNIT_STAT_CONFUSED);
        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);

        if(m_target->GetTypeId() == TYPEID_PLAYER)
        {
            Player *player = (Player*)m_target;
            WorldPacket data(SMSG_DEATH_NOTIFY_OBSOLETE, 10);
            data.append(player->GetPackGUID());             // target's viewpoint
            data << uint8(0x01);                            // movement enabled
            player->GetSession()->SendPacket(&data);
        }

        // only at real remove aura
        if(Real)
        {
            m_target->GetMotionMaster()->MovementExpired(false);

            if (m_target->GetTypeId() == TYPEID_UNIT)
            {
                Creature* c = (Creature*)m_target;
                // if in combat restore movement generator
                if(c->getVictim())
                    c->GetMotionMaster()->Mutate(new TargetedMovementGenerator<Creature>(*c->getVictim()));
            }
        }
    }
}