Example #1
0
 SpellCastResult CheckTarget()
 {
     Unit* target = GetTargetUnit();
     if(!target)
         return SPELL_FAILED_BAD_TARGETS;
     if(target->GetEntry() == NPC_OZZIE_TOGGLEVOLT || target->GetEntry() == NPC_MILLI_FEATHERWHISTLE || target->GetEntry() == NPC_TOG_RUSTSPROCKET)
         return SPELL_CAST_OK;
     return SPELL_FAILED_BAD_TARGETS;
 }
Example #2
0
bool MasterDemonologist5(uint32 i, Spell* s)
{
    Player* p_caster = s->p_caster;
    Unit* unitTarget = s->GetUnitTarget();

    if (!p_caster || !unitTarget)
        return false; //can't imagine how this talent got to anybody else then a player casting on pet

    uint32 casted_spell_id = 0;
    uint32 inc_resist_by_level = 0;
    uint32 inc_resist_by_level_spell = 0;

    if (unitTarget->GetEntry() == 416)    //in case it is imp
        casted_spell_id = 23829;
    else if (unitTarget->GetEntry() == 1860)    //VoidWalker
        casted_spell_id = 23844;
    else if (unitTarget->GetEntry() == 1863)    //Succubus
        casted_spell_id = 23836;
    else if (unitTarget->GetEntry() == 417)    //Felhunter
    {
        casted_spell_id = 0;
        inc_resist_by_level_spell = 23840;
        inc_resist_by_level = 100;
    }
    else if (unitTarget->GetEntry() == 17252)    //Felguard
    {
        casted_spell_id = 35706;
        inc_resist_by_level_spell = 23840;
        inc_resist_by_level = 50;
    }
    if (casted_spell_id)
    {
        //for self
        Spell* sp = sSpellFactoryMgr.NewSpell(p_caster, dbcSpell.LookupEntry(casted_spell_id), true, NULL);
        SpellCastTargets tgt(p_caster->GetGUID());
        sp->prepare(&tgt);
        //for pet
        sp = sSpellFactoryMgr.NewSpell(unitTarget, dbcSpell.LookupEntry(casted_spell_id), true, NULL);
        SpellCastTargets tgt1(unitTarget->GetGUID());
        sp->prepare(&tgt1);
    }

    if (inc_resist_by_level_spell)
    {
        //for self
        Spell* sp = sSpellFactoryMgr.NewSpell(p_caster, dbcSpell.LookupEntry(inc_resist_by_level_spell), true, NULL);
        SpellCastTargets tgt(p_caster->GetGUID());
        sp->prepare(&tgt);
        //for pet
        sp = sSpellFactoryMgr.NewSpell(unitTarget, dbcSpell.LookupEntry(inc_resist_by_level_spell), true, NULL);
        SpellCastTargets tgt1(unitTarget->GetGUID());
        sp->prepare(&tgt1);
    }

    return true;
}
Example #3
0
bool ItemUse_item_muiseks_vessel(Player* player, Item* _Item, SpellCastTargets const& targets)
{
    Unit* uTarget = targets.getUnitTarget();
    uint32 itemSpell = _Item->GetProto()->Spells[0].SpellId;
    uint32 cEntry = 0;
    uint32 cEntry2 = 0;
    uint32 cEntry3 = 0;
    uint32 cEntry4 = 0;

    if (itemSpell)
    {
        switch (itemSpell)
        {
        case 11885:                                     //Wandering Forest Walker
            cEntry =  7584;
            break;
        case 11886:                                     //Owlbeasts
            cEntry =  2927;
            cEntry2 = 2928;
            cEntry3 = 2929;
            cEntry4 = 7808;
            break;
        case 11887:                                     //Freyfeather Hippogryphs
            cEntry =  5300;
            cEntry2 = 5304;
            cEntry3 = 5305;
            cEntry4 = 5306;
            break;
        case 11888:                                     //Sprite Dragon Sprite Darters
            cEntry =  5276;
            cEntry2 = 5278;
            break;
        case 11889:                                     //Zapped Land Walker Land Walker Zapped Cliff Giant Cliff Giant
            cEntry =  5357;
            cEntry2 = 5358;
            cEntry3 = 14640;
            cEntry4 = 14604;
            break;
        }
        if (uTarget && uTarget->GetTypeId() == TYPEID_UNIT && uTarget->isDead() &&
            (uTarget->GetEntry() == cEntry || uTarget->GetEntry() == cEntry2 || uTarget->GetEntry() == cEntry3 || uTarget->GetEntry() == cEntry4))
        {
            CAST_CRE(uTarget)->RemoveCorpse();
            return false;
        }
    }

    WorldPacket data(SMSG_CAST_FAILED, (4 + 2));            // prepare packet error message
    data << uint32(_Item->GetEntry());                      // itemId
    data << uint8(SPELL_FAILED_BAD_TARGETS);                // reason
    player->GetSession()->SendPacket(&data);                // send message: Invalid target

    player->SendEquipError(EQUIP_ERR_NONE, _Item, NULL);    // break spell
    return true;
}
    void KilledUnit(Unit* /*victim*/)
    {
        if (LeftHead && RightHead)
        {
            Unit* Left  = Unit::GetUnit(*me, LeftHead);
            Unit* Right = Unit::GetUnit(*me, RightHead);

            if (!Left || !Right)
                return;

            ikilling = rand() % 2;

            Unit* source = (Left->GetEntry() == Killing[ikilling].creature ? Left : Right);

            switch (ikilling)
            {
            case 0:
                DoScriptText(Killing[ikilling].id, source);
                Delay_Timer = 3500;
                KillingYell = true;
                break;
            case 1:
                DoScriptText(Killing[ikilling].id, source);
                KillingYell = false;
                break;
            }
        }
    }
        void IsSummonedBy(Unit* summoner)
        {			
            Summoner = summoner;

            Intialized = true;

            switch(Summoner->GetEntry())
            {
            case BOSS_MAGMAW:
                events.ScheduleEvent(EVENT_BLAZING_INFERNO, 5000);
                me->SetFlying(true);
                break;

            case BOSS_OMNOTRON:
                events.ScheduleEvent(EVENT_GRIP_ZONE, 40000);
                events.ScheduleEvent(EVENT_ENCASING_SHADOWS, 100000);
                events.ScheduleEvent(EVENT_OVERCHARGED, 40000);
                me->SetDisplayId(32440);
                break;

            case BOSS_ATRAMEDES:
                break;

            case BOSS_MALORIAK:
                break;

            case BOSS_CHIMAERON:
                me->SetDisplayId(32440);
                DoCast(me, SPELL_MOCKING_SHADOWS, true);
                break;

            default:
                break;
            }
        }
Example #6
0
Unit* MoonScriptCreatureAI::ForceCreatureFind(uint32 pCreatureId, float pX, float pY, float pZ, bool pCurrentPosition)
{
	Unit *pUnit = NULL;
	MapMgr *pMapMgr = _unit->GetMapMgr();
	if (pMapMgr == NULL)
		return pUnit;

	if (pCurrentPosition)
		pUnit = pMapMgr->GetInterface()->GetCreatureNearestCoords(_unit->GetPositionX(), _unit->GetPositionY(), _unit->GetPositionZ(), pCreatureId);
	else
		pUnit = pMapMgr->GetInterface()->GetCreatureNearestCoords(pX, pY, pZ, pCreatureId);

	if (pUnit == NULL)
	{
		for (int i = 0; i != pMapMgr->m_CreatureHighGuid; ++i)
		{
			if (pMapMgr->m_CreatureStorage[i] != NULL)
			{ 
				pUnit = pMapMgr->m_CreatureStorage[i];
				if (pUnit->GetEntry() == pCreatureId)
					return pUnit;

				pUnit = NULL;
			}
		}
	}

	return pUnit;
}
            void KilledUnit(Unit* /*victim*/)
            {
                Unit* pLeftHead  = Unit::GetUnit(*me, LeftHeadGUID);
                Unit* pRightHead = Unit::GetUnit(*me, RightHeadGUID);

                if (!pLeftHead || !pRightHead)
                    return;

                ikilling = rand()%2;

                Unit* source = (pLeftHead->GetEntry() == Killing[ikilling].creature ? pLeftHead : pRightHead);

                switch (ikilling)
                {
                    case 0:
                        DoScriptText(Killing[ikilling].id, source);
                        Delay_Timer = 3500;
                        KillingYell = true;
                        break;
                    case 1:
                        DoScriptText(Killing[ikilling].id, source);
                        KillingYell = false;
                        break;
                }
            }
 void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
 {
     Unit* caster = GetCaster();
     if (caster && caster->GetEntry() == NPC_ACIDMAW)
         if (Creature* acidmaw = caster->ToCreature())
             acidmaw->AI()->Talk(SAY_SPECIAL, GetTarget());
 }
Example #9
0
void WorldSession::HandlePetAction(WorldPacket& recvData)
{
    ObjectGuid guid1;
    uint32 data;
    ObjectGuid guid2;
    float x, y, z;
    recvData >> guid1;                                     //pet guid
    recvData >> data;
    recvData >> guid2;                                     //tag guid
    // Position
    recvData >> x;
    recvData >> y;
    recvData >> z;

    uint32 spellid = UNIT_ACTION_BUTTON_ACTION(data);
    uint8 flag = UNIT_ACTION_BUTTON_TYPE(data);             //delete = 0x07 CastSpell = C1

    // used also for charmed creature
    Unit* pet = ObjectAccessor::GetUnit(*_player, guid1);
    TC_LOG_DEBUG("network", "HandlePetAction: %s - flag: %u, spellid: %u, target: %s.", guid1.ToString().c_str(), uint32(flag), spellid, guid2.ToString().c_str());

    if (!pet)
    {
        TC_LOG_DEBUG("network", "HandlePetAction: %s doesn't exist for %s %s", guid1.ToString().c_str(), GetPlayer()->GetGUID().ToString().c_str(), GetPlayer()->GetName().c_str());
        return;
    }

    if (pet != GetPlayer()->GetFirstControlled())
    {
        TC_LOG_DEBUG("network", "HandlePetAction: %s does not belong to %s %s", guid1.ToString().c_str(), GetPlayer()->GetGUID().ToString().c_str(), GetPlayer()->GetName().c_str());
        return;
    }

    if (!pet->IsAlive())
    {
        SpellInfo const* spell = (flag == ACT_ENABLED || flag == ACT_PASSIVE) ? sSpellMgr->GetSpellInfo(spellid) : NULL;
        if (!spell)
            return;
        if (!spell->HasAttribute(SPELL_ATTR0_CASTABLE_WHILE_DEAD))
            return;
    }

    /// @todo allow control charmed player?
    if (pet->GetTypeId() == TYPEID_PLAYER && !(flag == ACT_COMMAND && spellid == COMMAND_ATTACK))
        return;

    if (GetPlayer()->m_Controlled.size() == 1)
        HandlePetActionHelper(pet, guid1, spellid, flag, guid2, x, y, z);
    else
    {
        //If a pet is dismissed, m_Controlled will change
        std::vector<Unit*> controlled;
        for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr)
            if ((*itr)->GetEntry() == pet->GetEntry() && (*itr)->IsAlive())
                controlled.push_back(*itr);
        for (std::vector<Unit*>::iterator itr = controlled.begin(); itr != controlled.end(); ++itr)
            HandlePetActionHelper(*itr, guid1, spellid, flag, guid2, x, y, z);
    }
}
        void UpdateAI(const uint32 diff)
        {
            if(!Intialized)
                return;

            events.Update(diff);

            // Magmaw fight
            if(Summoner->GetEntry() == BOSS_MAGMAW && Summoner->HealthBelowPct(30) && !SpecialPhaseSwitchActive)
            {
                events.Reset();

                events.ScheduleEvent(EVENT_SHADOWFLAME_BARRAGE, 3000);
                SpecialPhaseSwitchActive = true;
            }

            while (uint32 eventId = events.ExecuteEvent())
            {
                switch(eventId)
                {
                    // Magmaw fight
                case EVENT_BLAZING_INFERNO:
                    if(Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 500, true))
                        DoCast(target, SPELL_BLAZING_INFERNO, true);

                    events.ScheduleEvent(EVENT_BLAZING_INFERNO, 35000);
                    break;
                case EVENT_SHADOWFLAME_BARRAGE:
                    if(Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 500, true))
                        DoCast(target, SPELL_SHADOWFLAME_BARRAGE, true);

                    events.ScheduleEvent(EVENT_SHADOWFLAME_BARRAGE, 7000);
                    break;

                    // Omnotron Fight
                case EVENT_GRIP_ZONE :
                    if (Unit *target = SelectTarget(SELECT_TARGET_RANDOM, 1, 10.0f, true))
                        DoCast(target, SPELL_GRIP_OF_DEATH);
                    events.ScheduleEvent(EVENT_GRIP_ZONE, 40000);
                    return;
                case EVENT_ENCASING_SHADOWS :
                    if (Unit *target = SelectTarget(SELECT_TARGET_RANDOM, 0, 80.0f, true))
                        DoCast(target, SPELL_ENCASING_SHADOWS);
                    events.ScheduleEvent(EVENT_ENCASING_SHADOWS, 100000);
                    return;

                case EVENT_OVERCHARGED :
                    if (Unit *target = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true))
                        DoCast(target, SPELL_OVERCHARGED_POWER_GENERATOR);
                    events.ScheduleEvent(EVENT_OVERCHARGED, 40000);
                    return;

                default:
                    break;
                }
            }
        }
    void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
    {
        Unit* caster = GetCaster();
        if (!caster || caster->GetEntry() != NPC_SNOBOLD_VASSAL)
            return;

        if (Creature* gormok = GetTarget()->ToCreature())
            if (Unit* target = gormok->AI()->SelectTarget(SELECT_TARGET_RANDOM, 0, SnobolledTargetSelector()))
            {
                gormok->AI()->Talk(EMOTE_SNOBOLLED);
                caster->GetAI()->DoAction(ACTION_ACTIVE_SNOBOLD);
                caster->CastSpell(target, SPELL_RIDE_PLAYER, true);
            }
    }
        void SendLavaWaves(bool start)
        {
            Unit* cr = NULL;
            for (SummonList::const_iterator itr = summons.begin(); itr != summons.end(); ++itr)
            {
                cr = ObjectAccessor::GetUnit(*me, *itr);
                if (!cr || cr->GetEntry() != NPC_FLAME_TSUNAMI)
                    continue;

                if (start)
                    cr->GetMotionMaster()->MovePoint(0, ((cr->GetPositionX() < 3250.0f) ? 3283.44f : 3208.44f), cr->GetPositionY(), cr->GetPositionZ());
                else
                    cr->SetObjectScale(0.1f);
            }
        }
            void DoYellForThreat()
            {
                Unit* pLeftHead  = Unit::GetUnit(*me, LeftHeadGUID);
                Unit* pRightHead = Unit::GetUnit(*me, RightHeadGUID);

                if (!pLeftHead || !pRightHead)
                    return;

                ithreat = rand()%4;

                Unit* source = (pLeftHead->GetEntry() == Threat[ithreat].creature ? pLeftHead : pRightHead);

                DoScriptText(Threat[ithreat].id, source);

                Delay_Timer = 3500;
                ThreatYell = true;
            }
Example #14
0
bool MinionsOfGurok(uint32 i, Spell* pSpell)
{
	Unit*   target = pSpell->GetUnitTarget();
	if(!pSpell->p_caster || !target || !target->IsCreature() || target->GetEntry() != 17157) return true;

	TO_CREATURE(target)->Despawn(500, 360000);

	float SSX = target->GetPositionX();
	float SSY = target->GetPositionY();
	float SSZ = target->GetPositionZ();
	float SSO = target->GetOrientation();

	pSpell->p_caster->GetMapMgr()->GetInterface()->SpawnCreature(18181, SSX + rand() % 8 - 4, SSY + rand() % 8 - 4, SSZ, SSO, true, false, 0, 0);
	pSpell->p_caster->GetMapMgr()->GetInterface()->SpawnCreature(18181, SSX + rand() % 8 - 4, SSY + rand() % 8 - 4, SSZ, SSO, true, false, 0, 0);
	pSpell->p_caster->GetMapMgr()->GetInterface()->SpawnCreature(18181, SSX + rand() % 8 - 4, SSY + rand() % 8 - 4, SSZ, SSO, true, false, 0, 0);

	return true;
}
    void DoYellForThreat()
    {
        if (LeftHead && RightHead)
        {
            Unit* Left  = Unit::GetUnit(*me, LeftHead);
            Unit* Right = Unit::GetUnit(*me, RightHead);

            if (!Left || !Right)
                return;

            ithreat = rand() % 4;

            Unit* source = (Left->GetEntry() == Threat[ithreat].creature ? Left : Right);

            DoScriptText(Threat[ithreat].id, source);

            Delay_Timer = 3500;
            ThreatYell = true;
        }
    }
Example #16
0
Unit* AscentScriptCreatureAI::ForceCreatureFind( uint32 pCreatureId, float pX, float pY, float pZ )
{
	Unit* UnitPtr = NULL; 
	MapMgr* Mgr = _unit->GetMapMgr();
	if ( Mgr == NULL )
		return UnitPtr;

	UnitPtr = Mgr->GetInterface()->GetCreatureNearestCoords( pX, pY, pZ, pCreatureId );
	if ( UnitPtr == NULL )
	{
		UnitArray Array;
		for ( uint32 i = 0; i != Mgr->m_CreatureHighGuid; ++i )
		{
			UnitPtr = Mgr->m_CreatureStorage[ i ];
			if ( UnitPtr != NULL )
			{ 
				if ( UnitPtr->GetEntry() == pCreatureId && UnitPtr != _unit )
					Array.push_back( UnitPtr );
			};
		};

		if ( Array.size() == 1 )
			return Array[ 0 ];

		UnitPtr = NULL;
		float Distance, NearestDistance = 99999;
		for ( UnitArray::iterator UnitIter = Array.begin(); UnitIter != Array.end(); ++UnitIter )
		{
			Distance = _unit->CalcDistance( pX, pY, pZ, ( *UnitIter )->GetPositionX(), ( *UnitIter )->GetPositionY(), ( *UnitIter )->GetPositionZ() );
			if ( Distance < NearestDistance )
			{
				NearestDistance = Distance;
				UnitPtr = ( *UnitIter );
			};
		};
	};

	return UnitPtr;
};
Example #17
0
bool ChatHandler::HandleListAIAgentCommand(const char* args, WorldSession* m_session)
{
	Unit* target = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(m_session->GetPlayer()->GetSelection()));
	if(!target)
	{
		RedSystemMessage(m_session, "You have to select a Creature!");
		return false;
	}

	std::stringstream sstext;
	sstext << "agentlist of creature: " << target->GetGUID() << '\n';

	std::stringstream ss;
	ss << "SELECT * FROM ai_agents where entry=" << target->GetEntry();
	QueryResult* result = WorldDatabase.Query(ss.str().c_str());

	if(!result)
		return false;

	do
	{
		Field* fields = result->Fetch();
		sstext << "agent: "   << fields[1].GetUInt16()
		       << " | spellId: " << fields[5].GetUInt32()
		       << " | Event: "   << fields[2].GetUInt32()
		       << " | chance: "  << fields[3].GetUInt32()
		       << " | count: "   << fields[4].GetUInt32() << '\n';
	}
	while(result->NextRow());

	delete result;

	SendMultilineMessage(m_session, sstext.str().c_str());

	return true;
}
Example #18
0
void WorldSession::HandlePetSetAction(WorldPacket & recvData)
{
    TC_LOG_INFO("network", "HandlePetSetAction. CMSG_PET_SET_ACTION");

    ObjectGuid petguid;
    uint32 position;
    uint32 data;

    recvData >> data >> position;
    recvData.ReadBitSeq<1, 7, 3, 5, 2, 6, 4, 0>(petguid);
    recvData.ReadByteSeq<0, 1, 2, 3, 7, 4, 6, 5>(petguid);

    Unit* pet = ObjectAccessor::GetUnit(*_player, petguid);

    if (!pet || pet != _player->GetFirstControlled())
    {
        TC_LOG_ERROR("network", "HandlePetSetAction: Unknown pet (GUID: %u) or pet owner (GUID: %u)", GUID_LOPART(petguid), _player->GetGUIDLow());
        return;
    }

    CharmInfo* charmInfo = pet->GetCharmInfo();
    if (!charmInfo)
    {
        TC_LOG_ERROR("network", "WorldSession::HandlePetSetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
        return;
    }

    uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data);

    //ignore invalid position
    if (position >= MAX_UNIT_ACTION_BAR_INDEX)
        return;

    uint8 act_state_0 = UNIT_ACTION_BUTTON_TYPE(data);
    if ((act_state_0 == ACT_COMMAND && UNIT_ACTION_BUTTON_ACTION(data) != COMMAND_MOVE_TO) || act_state_0 == ACT_REACTION)
    {
        uint32 spell_id_0 = UNIT_ACTION_BUTTON_ACTION(data);
        UnitActionBarEntry const* actionEntry_1 = charmInfo->GetActionBarEntry(position);
        if (!actionEntry_1 || spell_id_0 != actionEntry_1->GetAction() ||
            act_state_0 != actionEntry_1->GetType())
            return;
    }

    uint32 spell_id = UNIT_ACTION_BUTTON_ACTION(data);
    //uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data);

    TC_LOG_INFO("network", "Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X",
                _player->GetName().c_str(), position, spell_id, uint32(act_state));

    //if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add
    if (!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_PASSIVE) && spell_id && !pet->HasSpell(spell_id)))
    {
        if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id))
        {
            //sign for autocast
            if (act_state == ACT_ENABLED)
            {
                if (pet->GetTypeId() == TYPEID_UNIT && pet->ToCreature()->isPet())
                    ((Pet*)pet)->ToggleAutocast(spellInfo, true);
                else
                    for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr)
                        if ((*itr)->GetEntry() == pet->GetEntry())
                            (*itr)->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, true);
            }
            //sign for no/turn off autocast
            else if (act_state == ACT_DISABLED)
            {
                if (pet->GetTypeId() == TYPEID_UNIT && pet->ToCreature()->isPet())
                    ((Pet*)pet)->ToggleAutocast(spellInfo, false);
                else
                    for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr)
                        if ((*itr)->GetEntry() == pet->GetEntry())
                            (*itr)->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, false);
            }
        }

        charmInfo->SetActionBar(position, spell_id, ActiveStates(act_state));
    }
}
Example #19
0
void WorldSession::HandleCharmForceCastSpell(WorldPacket & recvPacket)
{
	DEBUG_LOG( "WORLD"," got CMSG_PET_CAST_SPELL." );
	uint64 guid;
	uint32 spellid;
	uint8 counter, flags;
	Unit* caster;
	SpellCastTargets targets;
	list<AI_Spell*>::iterator itr;

	recvPacket >> guid >> counter >> spellid >> flags;
	SpellEntry *sp = dbcSpell.LookupEntry(spellid);

	// Summoned Elemental's Freeze
	if(spellid == 33395)
	{
		caster = _player->m_Summon;
		if( caster && TO_PET(caster)->GetAISpellForSpellId(spellid) == NULL )
			return;
	}
	else
	{
		if(_player->m_CurrentVehicle)
			caster = _player->m_CurrentVehicle;
		else
			caster = _player->m_CurrentCharm;
		if( caster != NULL )
		{
			if(caster->IsVehicle() && !caster->IsPlayer())
			{
				CreatureProtoVehicle* vehpro = CreatureProtoVehicleStorage.LookupEntry(caster->GetEntry());
				bool hasspell = false;

				for(int i = 0; i < 6; ++i)
				{
					if(vehpro->VehicleSpells[i] = spellid)
					{
						hasspell = true;
						break;
					}
				}
				if(!hasspell)
				{
					WorldPacket data(SMSG_PET_CAST_FAILED, 1 + 4 + 1);
					data << uint8(0);
					data << uint32(spellid);
					data << uint8(SPELL_FAILED_NOT_KNOWN);
					SendPacket(&data); // Send packet to owner
					return;
				}
			}
			else
			{
				for(itr = caster->GetAIInterface()->m_spells.begin(); itr != caster->GetAIInterface()->m_spells.end(); ++itr)
				{
					if( (*itr)->spell->Id == spellid )
						break;
				}

				if( itr == caster->GetAIInterface()->m_spells.end() )
					return;
			}
		}
	}

	if( caster == NULL || guid != caster->GetGUID())
	{
		WorldPacket data(SMSG_PET_CAST_FAILED, 1 + 4 + 1);
		data << uint8(0);
		data << uint32(spellid);
		data << uint8(SPELL_FAILED_SPELL_UNAVAILABLE);
		SendPacket(&data); // Send packet to owner
		return;
	}

	if( caster->IsVehicle() && !_player->m_CurrentVehicle)
	{
		WorldPacket data(SMSG_PET_CAST_FAILED, 1 + 4 + 1);
		data << uint8(0);
		data << uint32(spellid);
		data << uint8(SPELL_FAILED_NOT_ON_TRANSPORT);
		SendPacket(&data); // Send packet to owner
		return;
	}

	targets.read(recvPacket, _player->GetGUID());

	Spell* pSpell = new Spell(caster, sp, false, NULL);
	pSpell->prepare(&targets);
}
    void UpdateAI(const uint32 diff)
    {
        if (Delay_Timer <= diff)
        {
            Delay_Timer = 3500;

            if (!LeftHead || !RightHead)
                return;

            Unit* Left  = Unit::GetUnit(*me, LeftHead);
            Unit* Right = Unit::GetUnit(*me, RightHead);

            if (!Left || !Right)
                return;

            if (AggroYell)
            {
                DoScriptText(GoCombatDelay[iaggro].id, Right);
                AggroYell = false;
            }

            if (ThreatYell2)
            {
                Unit* source = (Left->GetEntry() == ThreatDelay2[ithreat].creature ? Left : Right);

                DoScriptText(ThreatDelay2[ithreat].id, source);
                ThreatYell2 = false;
            }

            if (ThreatYell)
            {
                Unit* source = (Left->GetEntry() == ThreatDelay1[ithreat].creature ? Left : Right);

                DoScriptText(ThreatDelay1[ithreat].id, source);
                ThreatYell = false;
                ThreatYell2 = true;
            }

            if (KillingYell)
            {
                Unit* source = (Left->GetEntry() == KillingDelay[ikilling].creature ? Left : Right);

                DoScriptText(KillingDelay[ikilling].id, source);
                KillingYell = false;
            }
        }
        else Delay_Timer -= diff;

        if (!UpdateVictim())
            return;

        if (BlastCount && BlastWave_Timer <= diff)
        {
            DoCast(me, SPELL_BLAST_WAVE);
            BlastWave_Timer = 5000;
            ++BlastCount;

            if (BlastCount == 3)
                BlastCount = 0;
        }
        else BlastWave_Timer -= diff;

        if (BurningMaul_Timer <= diff)
        {
            DoScriptText(EMOTE_ENRAGE, me);
            DoCast(me, HeroicMode ? H_SPELL_BURNING_MAUL : SPELL_BURNING_MAUL);
            BurningMaul_Timer = 40000;
            BlastWave_Timer = 16000;
            BlastCount = 1;
        }
        else BurningMaul_Timer -= diff;

        if (ResetThreat_Timer <= diff)
        {
            if (Unit* pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0))
            {
                DoYellForThreat();
                DoResetThreat();
                me->AddThreat(pTarget, 0.0f);
            }
            ResetThreat_Timer = 35000 + rand() % 10000;
        }
        else ResetThreat_Timer -= diff;

        if (Fear_Timer <= diff)
        {
            DoCast(me, SPELL_FEAR);
            Fear_Timer = 15000 + rand() % 25000;
        }
        else Fear_Timer -= diff;

        if (ThunderClap_Timer <= diff)
        {
            DoCast(me, SPELL_THUNDERCLAP);
            ThunderClap_Timer = 25000 + rand() % 15000;
        }
        else ThunderClap_Timer -= diff;

        DoMeleeAttackIfReady();
    }
Example #21
0
void WorldSession::HandlePetSetAction(WorldPacket & recv_data)
{
    sLog->outDetail("HandlePetSetAction. CMSG_PET_SET_ACTION");

    uint64 petguid;
    uint8  count;

    recv_data >> petguid;

    Unit* pet = ObjectAccessor::GetUnit(*_player, petguid);

    if (!pet || pet != _player->GetFirstControlled())
    {
        sLog->outError("HandlePetSetAction: Unknown pet (GUID: %u) or pet owner (GUID: %u)", GUID_LOPART(petguid), _player->GetGUIDLow());
        return;
    }

    CharmInfo* charmInfo = pet->GetCharmInfo();
    if (!charmInfo)
    {
        sLog->outError("WorldSession::HandlePetSetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
        return;
    }

    count = (recv_data.size() == 24) ? 2 : 1;

    uint32 position[2];
    uint32 data[2];
    bool move_command = false;

    for (uint8 i = 0; i < count; ++i)
    {
        recv_data >> position[i];
        recv_data >> data[i];

        uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]);

        //ignore invalid position
        if (position[i] >= MAX_UNIT_ACTION_BAR_INDEX)
            return;

        // in the normal case, command and reaction buttons can only be moved, not removed
        // at moving count == 2, at removing count == 1
        // ignore attempt to remove command|reaction buttons (not possible at normal case)
        if (act_state == ACT_COMMAND || act_state == ACT_REACTION)
        {
            if (count == 1)
                return;

            move_command = true;
        }
    }

    // check swap (at command->spell swap client remove spell first in another packet, so check only command move correctness)
    if (move_command)
    {
        uint8 act_state_0 = UNIT_ACTION_BUTTON_TYPE(data[0]);
        if (act_state_0 == ACT_COMMAND || act_state_0 == ACT_REACTION)
        {
            uint32 spell_id_0 = UNIT_ACTION_BUTTON_ACTION(data[0]);
            UnitActionBarEntry const* actionEntry_1 = charmInfo->GetActionBarEntry(position[1]);
            if (!actionEntry_1 || spell_id_0 != actionEntry_1->GetAction() ||
                act_state_0 != actionEntry_1->GetType())
                return;
        }

        uint8 act_state_1 = UNIT_ACTION_BUTTON_TYPE(data[1]);
        if (act_state_1 == ACT_COMMAND || act_state_1 == ACT_REACTION)
        {
            uint32 spell_id_1 = UNIT_ACTION_BUTTON_ACTION(data[1]);
            UnitActionBarEntry const* actionEntry_0 = charmInfo->GetActionBarEntry(position[0]);
            if (!actionEntry_0 || spell_id_1 != actionEntry_0->GetAction() ||
                act_state_1 != actionEntry_0->GetType())
                return;
        }
    }

    for (uint8 i = 0; i < count; ++i)
    {
        uint32 spell_id = UNIT_ACTION_BUTTON_ACTION(data[i]);
        uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]);

        sLog->outDetail("Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X", _player->GetName(), position[i], spell_id, uint32(act_state));

        //if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add
        if (!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_PASSIVE) && spell_id && !pet->HasSpell(spell_id)))
        {
            if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id))
            {
                //sign for autocast
                if (act_state == ACT_ENABLED)
                {
                    if (pet->GetTypeId() == TYPEID_UNIT && pet->ToCreature()->isPet())
                        ((Pet*)pet)->ToggleAutocast(spellInfo, true);
                    else
                        for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr)
                            if ((*itr)->GetEntry() == pet->GetEntry())
                                (*itr)->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, true);
                }
                //sign for no/turn off autocast
                else if (act_state == ACT_DISABLED)
                {
                    if (pet->GetTypeId() == TYPEID_UNIT && pet->ToCreature()->isPet())
                        ((Pet*)pet)->ToggleAutocast(spellInfo, false);
                    else
                        for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr)
                            if ((*itr)->GetEntry() == pet->GetEntry())
                                (*itr)->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, false);
                }
            }

            charmInfo->SetActionBar(position[i], spell_id, ActiveStates(act_state));
        }
    }
}
Example #22
0
        void UpdateAI(const uint32 diff)
        {
            if (!UpdateVictim())
                return;

            events.Update(diff);

            if (me->hasUnitState(UNIT_STAT_CASTING) || me->HasAura(SPELL_SYSTEMS_SHUTDOWN))
                return;

            while(uint32 eventId = events.ExecuteEvent())
            {
                switch(eventId)
                {
                case 0:
                    break;
                case EVENT_PURSUE:
                    DoScriptText(RAND(SAY_TARGET_1, SAY_TARGET_2, SAY_TARGET_3), me);
                    {
                        DoZoneInCombat();
                        Unit* pTarget;
                        std::vector<Unit *> target_list;
                        std::list<HostileReference*> ThreatList = me->getThreatManager().getThreatList();
                        for (std::list<HostileReference*>::const_iterator itr = ThreatList.begin(); itr != ThreatList.end(); ++itr)
                        {
                            pTarget = Unit::GetUnit(*me, (*itr)->getUnitGuid());

                            if (!pTarget)
                                continue;

                            if (pTarget->GetEntry() == VEHICLE_SIEGE || pTarget->GetEntry() == VEHICLE_DEMOLISHER)
                                target_list.push_back(pTarget);

                            pTarget = NULL;
                        }

                        if (!target_list.empty())
                            pTarget = *(target_list.begin()+rand()%target_list.size());
                        else
                            pTarget = me->getVictim();

                        if (pTarget && pTarget->isAlive())
                        {
                            DoResetThreat();
                            me->AddThreat(pTarget, 5000000.0f);
                            me->AddAura(SPELL_PURSUED, pTarget);
                            me->MonsterTextEmote(EMOTE_PURSUE, pTarget->GetGUID(), true);
                        }
                    }
                    events.RescheduleEvent(EVENT_PURSUE, 35000);
                    break;
                case EVENT_MISSILE:
                    DoCastAOE(SPELL_MISSILE_BARRAGE);
                    events.RescheduleEvent(EVENT_MISSILE, 1500);
                    break;
                case EVENT_VENT:
                    DoCastAOE(SPELL_FLAME_VENTS);
                    events.RescheduleEvent(EVENT_VENT, 20000);
                    break;
                case EVENT_SPEED:
                    DoCastAOE(SPELL_GATHERING_SPEED);
                    events.RescheduleEvent(EVENT_SPEED, 10000);
                    break;
                case EVENT_SUMMON:
                    if(summons.size() < 15) // 4seat+1turret+10lift
                        if(Creature *lift = DoSummonFlyer(MOB_MECHANOLIFT, me, rand()%20 + 20, 50, 0))
                            lift->GetMotionMaster()->MoveRandom(100);
                    events.RescheduleEvent(EVENT_SUMMON, 2000);
                    break;
                case EVENT_SHUTDOWN:
                    DoScriptText(RAND(SAY_OVERLOAD_1, SAY_OVERLOAD_2, SAY_OVERLOAD_3), me);
                    me->MonsterTextEmote(EMOTE_OVERLOAD, 0, true);
                    DoCast(SPELL_SYSTEMS_SHUTDOWN);
                    me->RemoveAurasDueToSpell(SPELL_GATHERING_SPEED);
                    me->MonsterTextEmote(EMOTE_REPAIR, 0, true);
                    events.RescheduleEvent(EVENT_SHUTDOWN, 80000);
                    break;
                default:
                    events.PopEvent();
                    break;
                }
            }

            if (me->IsWithinMeleeRange(me->getVictim()))
                DoSpellAttackIfReady(SPELL_BATTERING_RAM);
        }