void ExecuteEvent(uint32 eventId) override
        {
            switch (eventId)
            {
                case EVENT_BLESS:
                {
                    std::list<Unit*> TargetList;
                    Trinity::AnyFriendlyUnitInObjectRangeCheck checker(me, me, 100.0f);
                    Trinity::UnitListSearcher<Trinity::AnyFriendlyUnitInObjectRangeCheck> searcher(me, TargetList, checker);
                    Cell::VisitAllObjects(me, searcher, 100.0f);

                    if (!TargetList.empty())
                    {
                        Unit* target = Trinity::Containers::SelectRandomContainerElement(TargetList);
                        DoCast(target, RAND(SPELL_BLESS_PROTECTION, SPELL_BLESS_SPELL_WARDING));
                    }
                    events.Repeat(Seconds(30), Seconds(45));
                    break;
                }
                case EVENT_AURA:
                    DoCastSelf(RAND(SPELL_CHROMATIC_AURA, SPELL_DEVOTION_AURA));
                    events.Repeat(Seconds(30));
                    break;
                case EVENT_HAMMER_OF_JUSTICE:
                    if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 1, HammerTargetSelector(me)))
                        DoCast(target, SPELL_HAMMER_OF_JUSTICE);
                    events.Repeat(Seconds(20));
                    break;
                case EVENT_JUDGEMENT:
                    DoCastVictim(SPELL_JUDGEMENT);
                    events.Repeat(Seconds(15));
                    break;
                case EVENT_CONSECRATION:
                    DoCastSelf(SPELL_CONSECRATION);
                    events.Repeat(Seconds(30), Seconds(35));
                    break;
                default:
                    break;
            }
        }
Example #2
0
bool OPvPCapturePoint::Update(uint32 diff)
{
    if (!m_capturePoint)
        return false;

    float radius = (float)m_capturePoint->GetGOInfo()->capturePoint.radius;

    for (uint32 team = 0; team < 2; ++team)
    {
        for (PlayerSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();)
        {
            uint64 playerGuid = *itr;
            ++itr;

            if (Player* player = ObjectAccessor::FindPlayer(playerGuid))
                if (!m_capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
                    HandlePlayerLeave(player);
        }
    }

    std::list<Player*> players;
    Trinity::AnyPlayerInObjectRangeCheck checker(m_capturePoint, radius);
    Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(m_capturePoint, players, checker);
    m_capturePoint->VisitNearbyWorldObject(radius, searcher);

    for (std::list<Player*>::iterator itr = players.begin(); itr != players.end(); ++itr)
    {
        Player* const player = *itr;
        if (player->IsOutdoorPvPActive())
        {
            if (m_activePlayers[player->GetTeamId()].insert(player->GetGUID()).second)
                HandlePlayerEnter(*itr);
        }
    }

    // get the difference of numbers
    float fact_diff = ((float)m_activePlayers[0].size() - (float)m_activePlayers[1].size()) * diff / OUTDOORPVP_OBJECTIVE_UPDATE_INTERVAL;
    if (!fact_diff)
        return false;

    uint32 Challenger = 0;
    float maxDiff = m_maxSpeed * diff;

    if (fact_diff < 0)
    {
        // horde is in majority, but it's already horde-controlled -> no change
        if (m_State == OBJECTIVESTATE_HORDE && m_value <= -m_maxValue)
            return false;

        if (fact_diff < -maxDiff)
            fact_diff = -maxDiff;

        Challenger = HORDE;
    }
    else
    {
        // ally is in majority, but it's already ally-controlled -> no change
        if (m_State == OBJECTIVESTATE_ALLIANCE && m_value >= m_maxValue)
            return false;

        if (fact_diff > maxDiff)
            fact_diff = maxDiff;

        Challenger = ALLIANCE;
    }

    float oldValue = m_value;
    TeamId oldTeam = m_team;

    m_OldState = m_State;

    m_value += fact_diff;

    if (m_value < -m_minValue) // red
    {
        if (m_value < -m_maxValue)
            m_value = -m_maxValue;
        m_State = OBJECTIVESTATE_HORDE;
        m_team = TEAM_HORDE;
    }
    else if (m_value > m_minValue) // blue
    {
        if (m_value > m_maxValue)
            m_value = m_maxValue;
        m_State = OBJECTIVESTATE_ALLIANCE;
        m_team = TEAM_ALLIANCE;
    }
    else if (oldValue * m_value <= 0) // grey, go through mid point
    {
        // if challenger is ally, then n->a challenge
        if (Challenger == ALLIANCE)
            m_State = OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE;
        // if challenger is horde, then n->h challenge
        else if (Challenger == HORDE)
            m_State = OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE;
        m_team = TEAM_NEUTRAL;
    }
    else // grey, did not go through mid point
    {
        // old phase and current are on the same side, so one team challenges the other
        if (Challenger == ALLIANCE && (m_OldState == OBJECTIVESTATE_HORDE || m_OldState == OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE))
            m_State = OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE;
        else if (Challenger == HORDE && (m_OldState == OBJECTIVESTATE_ALLIANCE || m_OldState == OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE))
            m_State = OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE;
        m_team = TEAM_NEUTRAL;
    }

    if (m_value != oldValue)
        SendChangePhase();

    if (m_OldState != m_State)
    {
        //TC_LOG_ERROR("outdoorpvp", "%u->%u", m_OldState, m_State);
        if (oldTeam != m_team)
            ChangeTeam(oldTeam);
        ChangeState();
        return true;
    }

    return false;
}
            void UpdateAI(uint32 diff) override
            {
                if (!UpdateVictim() || me->HasUnitState(UNIT_STATE_STUNNED) || me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED))
                    return;

                events.Update(diff);

                if (me->HasUnitState(UNIT_STATE_CASTING))
                    return;

                if (HealthBelowPct(30))
                    DoCast(me, SPELL_GREATER_HEAL);

                while (uint32 eventId = events.ExecuteEvent())
                {
                    switch (eventId)
                    {
                        case EVENT_HEAL:
                            DoCastAOE(SPELL_GREATER_HEAL);
                            events.ScheduleEvent(EVENT_HEAL, urand(7500, 10000));
                            break;
                        case EVENT_DISPEL_MAGIC:
                        {
                            std::list<Unit*> TargetList;
                            Trinity::AnyFriendlyUnitInObjectRangeCheck checker(me, me, 30.0f);
                            Trinity::UnitListSearcher<Trinity::AnyFriendlyUnitInObjectRangeCheck> searcher(me, TargetList, checker);
                            me->VisitNearbyObject(30.0f, searcher);
                            for (std::list<Unit*>::iterator itr = TargetList.begin(); itr != TargetList.end(); ++itr)
                                if ((*itr)->HasAura(SPELL_FREEZE))
                                    DoCast(*itr, SPELL_DISPEL_MAGIC, true);
                            events.ScheduleEvent(EVENT_DISPEL_MAGIC, urand(15000, 20000));
                            break;
                        }
                        default:
                            break;
                    }
                }

                DoSpellAttackIfReady(SPELL_SMITE);
            }
 SpellCastResult CheckIfCorpseNear()
 {
     Unit* caster = GetCaster();
     float max_range = GetSpellInfo()->GetMaxRange(false);
     WorldObject* result = NULL;
     // search for nearby enemy corpse in range
     Trinity::AnyDeadUnitSpellTargetInRangeCheck check(caster, max_range, GetSpellInfo(), TARGET_SELECT_CHECK_ENEMY);
     Trinity::WorldObjectSearcher<Trinity::AnyDeadUnitSpellTargetInRangeCheck> searcher(caster, result, check);
     caster->GetMap()->VisitFirstFound(caster->m_positionX, caster->m_positionY, max_range, searcher);
     if (!result)
         return SPELL_FAILED_NO_EDIBLE_CORPSES;
     return SPELL_CAST_OK;
 }
            /*
            Resets all variables and also find the ids of the four closests color clusters, since every simon
            node have diferent ids for clusters this is absolutely NECESSARY.
            */
            void StartGame()
            {
                listening = false;
                gameLevel = 0;
                fails = 0;
                gameTicks = 0;
                zCoordCorrection = large ? 8.0f : 2.75f;
                searchDistance = large ? 13.0f : 5.0f;
                colorSequence.clear();
                playableSequence.clear();
                playerSequence.clear();
                me->SetObjectScale(large ? 2.0f : 1.0f);

                std::list<WorldObject*> ClusterList;
                Trinity::AllWorldObjectsInRange objects(me, searchDistance);
                Trinity::WorldObjectListSearcher<Trinity::AllWorldObjectsInRange> searcher(me, ClusterList, objects);
                me->VisitNearbyObject(searchDistance, searcher);

                for (std::list<WorldObject*>::const_iterator i = ClusterList.begin(); i != ClusterList.end(); ++i)
                {
                    if (GameObject* go = (*i)->ToGameObject())
                    {
                        // We are checking for displayid because all simon nodes have 4 clusters with different entries
                        if (large)
                        {
                            switch (go->GetGOInfo()->displayId)
                            {
                                case GO_BLUE_CLUSTER_DISPLAY_LARGE:
                                    clusterIds[SIMON_BLUE] = go->GetEntry();
                                    break;

                                case GO_RED_CLUSTER_DISPLAY_LARGE:
                                    clusterIds[SIMON_RED] = go->GetEntry();
                                    break;

                                case GO_GREEN_CLUSTER_DISPLAY_LARGE:
                                    clusterIds[SIMON_GREEN] = go->GetEntry();
                                    break;

                                case GO_YELLOW_CLUSTER_DISPLAY_LARGE:
                                    clusterIds[SIMON_YELLOW] = go->GetEntry();
                                    break;
                            }
                        }
                        else
                        {
                            switch (go->GetGOInfo()->displayId)
                            {
                                case GO_BLUE_CLUSTER_DISPLAY:
                                    clusterIds[SIMON_BLUE] = go->GetEntry();
                                    break;

                                case GO_RED_CLUSTER_DISPLAY:
                                    clusterIds[SIMON_RED] = go->GetEntry();
                                    break;

                                case GO_GREEN_CLUSTER_DISPLAY:
                                    clusterIds[SIMON_GREEN] = go->GetEntry();
                                    break;

                                case GO_YELLOW_CLUSTER_DISPLAY:
                                    clusterIds[SIMON_YELLOW] = go->GetEntry();
                                    break;
                            }
                        }
                    }
                }

                _events.Reset();
                _events.ScheduleEvent(EVENT_SIMON_ROUND_FINISHED, 1000);
                _events.ScheduleEvent(EVENT_SIMON_PERIODIC_PLAYER_CHECK, 2000);

                if (GameObject* relic = me->FindNearestGameObject(large ? GO_APEXIS_MONUMENT : GO_APEXIS_RELIC, searchDistance))
                    relic->SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE);
            }
		void UpdateAI(const uint32 diff)
		{
			events.Update(diff);

			if (!UpdateVictim())
				return;

			if (fixated)
			{
				if (target_after != NULL && target_after && target_after->IsInWorld() && target_after->isAlive() && target_after->HasAura(FIXATE_AURA))
				{
					me->AttackStop();                                       // Stop attacking DoMeleeAttackIfReady()
					me->SetReactState(REACT_PASSIVE);

					me->GetMotionMaster()->MovePoint(1, target_after->GetPositionX(), target_after->GetPositionY(), target_after->GetPositionZ());
				}
				else
				{
					fixated = false;
					target_after = NULL;

					AttackStart(me->getVictim());                           // Start attack the victim (random?)
					me->SetReactState(REACT_AGGRESSIVE);
				}
			}

			// band of valor
			std::list<Creature*> Cr_list;

			JadeCore::AnyCreatureInObjectRangeCheck check(me, 8.0f);
			JadeCore::CreatureListSearcher<JadeCore::AnyCreatureInObjectRangeCheck> searcher(me, Cr_list, check);
			me->VisitNearbyObject(8.0f, searcher);

			for (std::list<Creature*>::const_iterator it = Cr_list.begin(); it != Cr_list.end(); ++it)
			{
				if (!(*it))
					return;

 
                if ((*it)->GetEntry() == 63591 || (*it)->GetEntry() == 64453)
                {
                    if (me->HasAura(125422))
                    {
                        AuraPtr band_of_valor = me->GetAura(125422);

                        if (band_of_valor)
                        {
                            band_of_valor->SetStackAmount(Cr_list.size() - 1);
                        }
                    }
                    else
                    {
                        me->AddAura(125422, me);
                    }
                }
			} 
			while (uint32 eventId = events.ExecuteEvent())
			{
				switch (eventId)
				{
				case EVENT_FIXATE:
					if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
					{
						me->CastSpell(target, FIXATE);

						fixated = true;
						target_after = target->ToPlayer();

						events.ScheduleEvent(EVENT_FIXATE, urand(32000, 60000));
					}
					break;
				case EVENT_SONIC_BLADE:
					me->CastSpell(me->getVictim(), SONIC_BOMB);
					events.ScheduleEvent(EVENT_SONIC_BLADE, urand(6000, 10000));
					break;
				case EVENT_DISPATCH:
					me->AddAura(DISPATCH, me);
					events.ScheduleEvent(DISPATCH, 21000);
					break;
				case EVENT_STICKY_RESIN:
					Position pos;
					int32 reduction = urand(0, 1);

					if (reduction == 1)
					{
						me->GetRandomNearPosition(pos, frand(5.0f, 10.0f));
						me->SummonCreature(STICKY_RESIN_TRIGGER, pos, TEMPSUMMON_MANUAL_DESPAWN);
						events.ScheduleEvent(EVENT_STICKY_RESIN, urand(15000, 22000));
					}
					break;
				}
			}

			DoMeleeAttackIfReady();
		}
		void UpdateAI(uint32 const diff)
		{
			events.Update(diff);

			std::list<Player*> PL_list;
			std::list<Creature*> Cr_list;
			

			if (pre)
			{
				JadeCore::AnyPlayerInObjectRangeCheck check(me, 1.0f);
				JadeCore::PlayerListSearcher<JadeCore::AnyPlayerInObjectRangeCheck> searcher(me, PL_list, check);
				me->VisitNearbyObject(1.0f, searcher);

				for (std::list<Player*>::const_iterator it = PL_list.begin(); it != PL_list.end(); ++it)
				{
					if (!(*it))
						return;

					if ((*it)->HasAura(STICKY_RESIN_DOT))
					{
						(*it)->RemoveAura(STICKY_RESIN_DOT);

						if (!me->HasAura(AMBER_TRAP_STACKS_PRE_FROZEN))
						{
							me->AddAura(AMBER_TRAP_STACKS_PRE_FROZEN, me);
						}
						else
						{
							AuraPtr aura_B = me->GetAura(AMBER_TRAP_STACKS_PRE_FROZEN);

							if (aura_B)
							{

								aura_B->SetStackAmount(aura_B->GetStackAmount() + 1);
							}
						}
					}
				}
				if (me->HasAura(AMBER_TRAP_STACKS_PRE_FROZEN))
				{
					AuraPtr aur = me->GetAura(AMBER_TRAP_STACKS_PRE_FROZEN);

					if (pre)
					{
						if (aur)
						{
							if (aur->GetStackAmount() >= 5)
							{
								me->SetObjectScale(1.5f);
								pre = false;
								post = true;
							}
						}
					}
				}
			}
			if (post)
			{
				JadeCore::AnyCreatureInObjectRangeCheck check(me, 3.0f);
				JadeCore::CreatureListSearcher<JadeCore::AnyCreatureInObjectRangeCheck> searcher(me, Cr_list, check);
				me->VisitNearbyObject(3.0f, searcher);

				for (std::list<Creature*>::const_iterator it = Cr_list.begin(); it != Cr_list.end(); ++it)
				{
					if (!(*it))
						return;

					if ((*it)->GetEntry() == 63591)
					{
						(*it)->AddAura(AMBER_TRAP, (*it));
						me->DespawnOrUnsummon();
					}
				}
			}
		}
Example #8
0
    void UpdateAI(const uint32 uiDiff)
    {
        if (!UpdateVictim())
            return;

        //Common to PHASE_START && PHASE_END
        if (m_uiPhase == PHASE_START || m_uiPhase == PHASE_END)
        {
            //Specific to PHASE_START || PHASE_END
            if (m_uiPhase == PHASE_START)
            {
                if (me->GetHealth()*100 / me->GetMaxHealth() < 60)
                {
                    m_uiPhase = PHASE_BREATH;
                    
                    if (m_pInstance)
                        m_pInstance->SetData(DATA_ONYXIA_PHASE, m_uiPhase);

                    SetCombatMovement(false);
                    me->GetMotionMaster()->Clear(false);
                    me->GetMotionMaster()->MoveIdle();
                    me->SetFlying(true);

                    DoScriptText(SAY_PHASE_2_TRANS, me);

                    if (m_pPointData)
                        me->GetMotionMaster()->MovePoint(m_pPointData->uiLocId, m_pPointData->fX, m_pPointData->fY, m_pPointData->fZ);

                    m_uiWhelpTimer = 1000;
                    return;
                }
            }
            else
            {
                if (m_uiBellowingRoarTimer <= uiDiff)
                {
                    DoCastVictim(SPELL_BELLOWING_ROAR);
                    // Eruption
                    GameObject* pFloor = NULL;
                    Trinity::GameObjectInRangeCheck check(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ(), 15);
                    Trinity::GameObjectLastSearcher<Trinity::GameObjectInRangeCheck> searcher(me, pFloor, check);
                    me->VisitNearbyGridObject(30, searcher);
                    if (m_pInstance && pFloor)
                        m_pInstance->SetData64(DATA_FLOOR_ERUPTION_GUID, pFloor->GetGUID());
                    m_uiBellowingRoarTimer = 30000;
                }
                else
                    m_uiBellowingRoarTimer -= uiDiff;
            }

            if (m_uiFlameBreathTimer <= uiDiff)
            {
                DoCastVictim(SPELL_FLAME_BREATH);
                m_uiFlameBreathTimer = urand(10000, 20000);
            }
            else
                m_uiFlameBreathTimer -= uiDiff;

            if (m_uiTailSweepTimer <= uiDiff)
            {
                DoCastAOE(SPELL_TAIL_SWEEP);
                m_uiTailSweepTimer = urand(15000, 20000);
            }
            else
                m_uiTailSweepTimer -= uiDiff;

            if (m_uiCleaveTimer <= uiDiff)
            {
                DoCastVictim(SPELL_CLEAVE);
                m_uiCleaveTimer = urand(2000, 5000);
            }
            else
                m_uiCleaveTimer -= uiDiff;

            if (m_uiWingBuffetTimer <= uiDiff)
            {
                DoCastVictim(SPELL_WING_BUFFET);
                m_uiWingBuffetTimer = urand(15000, 30000);
            }
            else
                m_uiWingBuffetTimer -= uiDiff;

            DoMeleeAttackIfReady();
        }
        else
        {
            if (me->GetHealth()*100 / me->GetMaxHealth() < 40)
            {
                m_uiPhase = PHASE_END;
                if (m_pInstance)
                    m_pInstance->SetData(DATA_ONYXIA_PHASE, m_uiPhase);
                DoScriptText(SAY_PHASE_3_TRANS, me);

                SetCombatMovement(true);
                me->SetFlying(false);
                m_bIsMoving = false;
                me->GetMotionMaster()->MovePoint(9,me->GetHomePosition());
                return;
            }

            if (m_uiDeepBreathTimer <= uiDiff)
            {
                if (!m_bIsMoving) 
                {
                    if (me->IsNonMeleeSpellCasted(false))
                        me->InterruptNonMeleeSpells(false);

                    DoScriptText(EMOTE_BREATH, me);
                    DoCast(me, m_pPointData->uiSpellId);
                    m_uiDeepBreathTimer = 70000;
                }
            }
            else
                m_uiDeepBreathTimer -= uiDiff;

            if (m_uiMovementTimer <= uiDiff)
            {
                if (!m_bIsMoving) 
                {
                    SetNextRandomPoint();
                    m_pPointData = GetMoveData();

                    if (!m_pPointData)
                        return;

                    me->GetMotionMaster()->MovePoint(m_pPointData->uiLocId, m_pPointData->fX, m_pPointData->fY, m_pPointData->fZ);
                    m_bIsMoving = true;
                    m_uiMovementTimer = 25000;
                }
            }
            else
                m_uiMovementTimer -= uiDiff;

            if (m_uiFireballTimer <= uiDiff)
            {
                if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE)
                {
                    if (Unit* pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0))
                        DoCast(pTarget, SPELL_FIREBALL);

                    m_uiFireballTimer = 8000;
                }
            }
            else
                m_uiFireballTimer -= uiDiff;

            if (m_uiLairGuardTimer <= uiDiff)            
            {
                me->SummonCreature(NPC_LAIRGUARD, aSpawnLocations[2].GetPositionX(), aSpawnLocations[2].GetPositionY(), aSpawnLocations[2].GetPositionZ(), 0.0f, TEMPSUMMON_CORPSE_DESPAWN);
                if (m_uiSummonLairGuardCount >= RAID_MODE(1,2))
                {
                    m_uiSummonLairGuardCount = 0;
                    m_uiLairGuardTimer = 30000;
                }
                else
                    m_uiLairGuardTimer = 2000;
            }
            else
                m_uiLairGuardTimer -= uiDiff;

            if (m_uiWhelpTimer <= uiDiff)
            {
                me->SummonCreature(NPC_WHELP, aSpawnLocations[0].GetPositionX(), aSpawnLocations[0].GetPositionY(), aSpawnLocations[0].GetPositionZ(), 0.0f, TEMPSUMMON_CORPSE_DESPAWN);
                me->SummonCreature(NPC_WHELP, aSpawnLocations[1].GetPositionX(), aSpawnLocations[1].GetPositionY(), aSpawnLocations[1].GetPositionZ(), 0.0f, TEMPSUMMON_CORPSE_DESPAWN);
                if (m_uiSummonWhelpCount >= RAID_MODE(20,40))
                {
                    m_uiSummonWhelpCount = 0;
                    m_uiWhelpTimer = 90000;    
                } 
                else
                    m_uiWhelpTimer = 500;
            }
            else
                m_uiWhelpTimer -= uiDiff;
        }
    }
            void UpdateAI(uint32 const diff)
            {
                // trigger
                if (_instance->GetBossState(DATA_VALITHRIA_DREAMWALKER) != IN_PROGRESS)
                    return;

                _events.Update(diff);

                while (uint32 eventId = _events.ExecuteEvent())
                {
                    switch (eventId)
                    {
                        case EVENT_CHECK_PLAYER:
                        {
                            Player* player = NULL;
                            Trinity::AnyPlayerInObjectRangeCheck check(me, 5.0f);
                            Trinity::PlayerSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(me, player, check);
                            me->VisitNearbyWorldObject(7.5f, searcher);
                            _events.ScheduleEvent(player ? EVENT_EXPLODE : EVENT_CHECK_PLAYER, 1000);
                            break;
                        }
                        case EVENT_EXPLODE:
                            me->GetMotionMaster()->MoveIdle();
                            // must use originalCaster the same for all clouds to allow stacking
                            me->CastSpell(me, EMERALD_VIGOR, false, NULL, NULL, _instance->GetData64(DATA_VALITHRIA_DREAMWALKER));
                            me->ForcedDespawn(100);
                            break;
                        default:
                            break;
                    }
                }
            }
            void ReleaseDogs()
            {
                std::list<Creature*> templist;
                float x, y, z;
                me->GetPosition(x, y, z);

                {
                    CellCoord pair(JadeCore::ComputeCellCoord(x, y));
                    Cell cell(pair);
                    cell.SetNoCreate();

                    JadeCore::AllCreaturesOfEntryInRange check(me, MOB_OBEDIENT_HOUND, 200);
                    JadeCore::CreatureListSearcher<JadeCore::AllCreaturesOfEntryInRange> searcher(me, templist, check);
                    TypeContainerVisitor<JadeCore::CreatureListSearcher<JadeCore::AllCreaturesOfEntryInRange>, GridTypeMapContainer> cSearcher(searcher);
                    cell.Visit(pair, cSearcher, *me->GetMap(), *me, me->GetGridActivationRange());
                }

                if (templist.empty())
                return;

                for (std::list<Creature*>::const_iterator i = templist.begin(); i != templist.end(); ++i)
                {
                   // (*i)->setFaction(35);
                    (*i)->SetReactState(REACT_AGGRESSIVE);
                    (*i)->AI()->DoAction(ACTION_ATTACK_BRAUN);
                }
            }
void TotemAI::UpdateAI(uint32 /*diff*/)
{
    if (me->ToTotem()->GetTotemType() != TOTEM_ACTIVE)
        return;

    if (!me->isAlive() || me->IsNonMeleeSpellCasted(false))
        return;

    // Search spell
    SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(me->ToTotem()->GetSpell());
    if (!spellInfo)
        return;

    // Get spell range
    float max_range = spellInfo->GetMaxRange(false);

    // SPELLMOD_RANGE not applied in this place just because not existence range mods for attacking totems

    // Nel caso del searing totem, si cerca prima un target che abbia il dot di flame shock
    // in caso contrario, si cerca il target più vicino

    if (me->GetEntry() == 2523)
    {
        std::list<Unit*> targets;
        Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, max_range);
        Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
        me->VisitNearbyObject(max_range, searcher);

        for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
        {
            if ((*iter) && (*iter)->isTargetableForAttack()
                && me->IsWithinDistInMap((*iter), max_range)
                && !me->IsFriendlyTo((*iter))
                && me->canSeeOrDetect((*iter))
                && ((*iter)->HasAura(8050)|| (*iter)->HasAura(17364)))
            {
                i_victimGuid = (*iter)->GetGUID();
                break;
            }

            else if (!(*iter)->HasAura(8050) && !(*iter)->HasAura(17364))
            {
                Unit* victim = i_victimGuid ? ObjectAccessor::GetUnit(*me, i_victimGuid) : NULL;
                Trinity::NearestAttackableUnitInObjectRangeCheck u_check(me, me, max_range);
                Trinity::UnitLastSearcher<Trinity::NearestAttackableUnitInObjectRangeCheck> checker(me, victim, u_check);
                me->VisitNearbyObject(max_range, checker);

                if (victim)
                    i_victimGuid = victim->GetGUID();
            }
        }

        Unit* memtarget = i_victimGuid ? ObjectAccessor::GetUnit(*me, i_victimGuid) : NULL;

        if (memtarget)
        {
            me->CastSpell(memtarget, me->ToTotem()->GetSpell(), false);
        }
    }
    else
    {
        // pointer to appropriate target if found any
        Unit* victim = i_victimGuid ? ObjectAccessor::GetUnit(*me, i_victimGuid) : NULL;

        // Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
        if (!victim ||
            !victim->isTargetableForAttack() || !me->IsWithinDistInMap(victim, max_range) ||
            me->IsFriendlyTo(victim) || !me->canSeeOrDetect(victim))
        {
            victim = NULL;
            Trinity::NearestAttackableUnitInObjectRangeCheck u_check(me, me, max_range);
            Trinity::UnitLastSearcher<Trinity::NearestAttackableUnitInObjectRangeCheck> checker(me, victim, u_check);
            me->VisitNearbyObject(max_range, checker);
        }

        // If have target
        if (victim)
        {
            // remember
            i_victimGuid = victim->GetGUID();

            // attack
            me->SetInFront(victim);                         // client change orientation by self
            me->CastSpell(victim, me->ToTotem()->GetSpell(), false);
        }
        else
            i_victimGuid = 0;
    }
}
Example #12
0
        void UpdateAI(uint32 Diff)
        {
            if (!UpdateVictim())
                return;

            //Common to PHASE_START && PHASE_END
            if (Phase == PHASE_START || Phase == PHASE_END)
            {
                //Specific to PHASE_START || PHASE_END
                if (Phase == PHASE_START)
                {
                    if (HealthBelowPct(60))
                    {
                        SetCombatMovement(false);
                        Phase = PHASE_BREATH;
                        me->GetMotionMaster()->MovePoint(10, Phase2Location);
                        return;
                    }
                }
                else
                {
                    if (BellowingRoarTimer <= Diff)
                    {
                        DoCastVictim(SPELL_BELLOWING_ROAR);
                        // Eruption
                        GameObject* Floor = NULL;
                        Trinity::GameObjectInRangeCheck check(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ(), 15);
                        Trinity::GameObjectLastSearcher<Trinity::GameObjectInRangeCheck> searcher(me, Floor, check);
                        me->VisitNearbyGridObject(30, searcher);
                        if (instance && Floor)
                            instance->SetData64(DATA_FLOOR_ERUPTION_GUID, Floor->GetGUID());
                        BellowingRoarTimer = 30000;
                    }
                    else
                        BellowingRoarTimer -= Diff;
                }

                if (FlameBreathTimer <= Diff)
                {
                    DoCastVictim(SPELL_FLAME_BREATH);
                    FlameBreathTimer = urand(10000, 20000);
                }
                else
                    FlameBreathTimer -= Diff;

                if (TailSweepTimer <= Diff)
                {
                    DoCastAOE(SPELL_TAIL_SWEEP);
                    TailSweepTimer = urand(15000, 20000);
                }
                else
                    TailSweepTimer -= Diff;

                if (CleaveTimer <= Diff)
                {
                    DoCastVictim(SPELL_CLEAVE);
                    CleaveTimer = urand(2000, 5000);
                }
                else
                    CleaveTimer -= Diff;

                if (WingBuffetTimer <= Diff)
                {
                    DoCastVictim(SPELL_WING_BUFFET);
                    WingBuffetTimer = urand(15000, 30000);
                }
                else
                    WingBuffetTimer -= Diff;

                DoMeleeAttackIfReady();
            }
            else
            {
                if (HealthBelowPct(40))
                {
                    Phase = PHASE_END;
                    if (instance)
                        instance->SetData(DATA_ONYXIA_PHASE, Phase);
                    Talk(SAY_PHASE_3_TRANS);

                    SetCombatMovement(true);
                    me->SetCanFly(false);
                    IsMoving = false;
                    me->GetMotionMaster()->MovePoint(9, me->GetHomePosition());
                    return;
                }

                if (DeepBreathTimer <= Diff)
                {
                    if (!IsMoving)
                    {
                        if (me->IsNonMeleeSpellCasted(false))
                            me->InterruptNonMeleeSpells(false);

                        Talk(EMOTE_BREATH);
                        DoCast(me, PointData->SpellId);
                        DeepBreathTimer = 70000;
                    }
                }
                else
                    DeepBreathTimer -= Diff;

                if (MovementTimer <= Diff)
                {
                    if (!IsMoving)
                    {
                        SetNextRandomPoint();
                        PointData = GetMoveData();

                        if (!PointData)
                            return;

                        me->GetMotionMaster()->MovePoint(PointData->LocId, PointData->fX, PointData->fY, PointData->fZ);
                        IsMoving = true;
                        MovementTimer = 25000;
                    }
                }
                else
                    MovementTimer -= Diff;

                if (FireballTimer <= Diff)
                {
                    if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE)
                    {
                        if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0))
                            DoCast(target, SPELL_FIREBALL);

                        FireballTimer = 8000;
                    }
                }
                else
                    FireballTimer -= Diff;

                if (LairGuardTimer <= Diff)
                {
                    me->SummonCreature(NPC_LAIRGUARD, SpawnLocations[2], TEMPSUMMON_CORPSE_DESPAWN);
                    LairGuardTimer = 30000;
                }
                else
                    LairGuardTimer -= Diff;

                if (WhelpTimer <= Diff)
                {
                    me->SummonCreature(NPC_WHELP, SpawnLocations[0], TEMPSUMMON_CORPSE_DESPAWN);
                    me->SummonCreature(NPC_WHELP, SpawnLocations[1], TEMPSUMMON_CORPSE_DESPAWN);
                    if (SummonWhelpCount >= RAID_MODE(20, 40))
                    {
                        SummonWhelpCount = 0;
                        WhelpTimer = 90000;
                    }
                    else
                        WhelpTimer = 500;
                }
                else
                    WhelpTimer -= Diff;
            }
        }
Example #13
0
            void Init()
            {
                Unit* owner = me->GetCharmerOrOwner();

                std::list<Unit*> targets;
                Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
                Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
                me->VisitNearbyObject(40.0f, searcher);

                Unit* highestThreatUnit = nullptr;
                float highestThreat = 0.0f;
                Unit* nearestPlayer = nullptr;
                for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
                {
                    // Consider only units without CC
                    if (!(*iter)->HasBreakableByDamageCrowdControlAura((*iter)))
                    {
                        // Take first found unit
                        if (!highestThreatUnit && (*iter)->GetTypeId() != TYPEID_PLAYER)
                        {
                            highestThreatUnit = (*iter);
                            continue;
                        }
                        if (!nearestPlayer && ((*iter)->GetTypeId() == TYPEID_PLAYER))
                        {
                            nearestPlayer = (*iter);
                            continue;
                        }
                        // else compare best fit unit with current unit
                        ThreatContainer::StorageType triggers = (*iter)->getThreatManager().getThreatList();
                        for (ThreatContainer::StorageType::const_iterator trig_citr = triggers.begin(); trig_citr != triggers.end(); ++trig_citr)
                        {
                            // Try to find threat referenced to owner
                            if ((*trig_citr)->getTarget() == owner)
                            {
                                // Check if best fit hostile unit hs lower threat than this current unit
                                if (highestThreat < (*trig_citr)->getThreat())
                                {
                                    // If so, update best fit unit
                                    highestThreat = (*trig_citr)->getThreat();
                                    highestThreatUnit = (*iter);
                                    break;
                                }
                            }
                        }
                        // In case no unit with threat was found so far, always check for nearest unit (only for players)
                        if ((*iter)->GetTypeId() == TYPEID_PLAYER)
                        {
                            // If this player is closer than the previous one, update it
                            if (me->GetDistance((*iter)->GetPosition()) < me->GetDistance(nearestPlayer->GetPosition()))
                                nearestPlayer = (*iter);
                        }
                    }
                }
                // Prioritize units with threat referenced to owner
                if (highestThreat > 0.0f && highestThreatUnit)
                        me->Attack(highestThreatUnit, false);
                // If there is no such target, try to attack nearest hostile unit if such exists
                else if (nearestPlayer)
                        me->Attack(nearestPlayer, false);
            }
Example #14
0
            bool IsInThreatList(Unit* target)
            {
                Unit* owner = me->GetCharmerOrOwner();

                std::list<Unit*> targets;
                Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
                Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
                me->VisitNearbyObject(40.0f, searcher);

                for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
                {
                    if ((*iter) == target)
                    {
                        // Consider only units without CC
                        if (!(*iter)->HasBreakableByDamageCrowdControlAura((*iter)))
                        {
                            ThreatContainer::StorageType triggers = (*iter)->getThreatManager().getThreatList();
                            for (ThreatContainer::StorageType::const_iterator trig_citr = triggers.begin(); trig_citr != triggers.end(); ++trig_citr)
                            {
                                // Try to find threat referenced to owner
                                if ((*trig_citr)->getTarget() == owner)
                                    return true;
                            }
                        }
                    }
                }
                return false;
            }
        void HandleStormSequence(Unit* Cloud) // 1: begin, 2-9: tick, 10: end
        {
            if (StormCount < 10 && StormCount > 1)
            {
                // deal damage
                int32 bp0 = 800;
                for (uint8 i = 2; i < StormCount; ++i)
                    bp0 *= 2;

                CellCoord p(Darkcore::ComputeCellCoord(me->GetPositionX(), me->GetPositionY()));
                Cell cell(p);
                cell.SetNoCreate();

                std::list<Unit*> tempUnitMap;

                {
                    Darkcore::AnyAoETargetUnitInObjectRangeCheck u_check(me, me, SIZE_OF_GRIDS);
                    Darkcore::UnitListSearcher<Darkcore::AnyAoETargetUnitInObjectRangeCheck> searcher(me, tempUnitMap, u_check);

                    TypeContainerVisitor<Darkcore::UnitListSearcher<Darkcore::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
                    TypeContainerVisitor<Darkcore::UnitListSearcher<Darkcore::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer >  grid_unit_searcher(searcher);

                    cell.Visit(p, world_unit_searcher, *me->GetMap(), *me, SIZE_OF_GRIDS);
                    cell.Visit(p, grid_unit_searcher, *me->GetMap(), *me, SIZE_OF_GRIDS);
                }
                //dealdamege
                for (std::list<Unit*>::const_iterator i = tempUnitMap.begin(); i != tempUnitMap.end(); ++i)
                {
                    if (!Cloud->IsWithinDist(*i, 6, false))
                    {
                        Cloud->CastCustomSpell(*i, 43137, &bp0, NULL, NULL, true, 0, 0, me->GetGUID());
                    }
                }
                // visual
                float x, y, z;
                z = me->GetPositionZ();
                for (uint8 i = 0; i < 5+rand()%5; ++i)
                {
                    x = 343.0f+rand()%60;
                    y = 1380.0f+rand()%60;
                    if (Unit* trigger = me->SummonTrigger(x, y, z, 0, 2000))
                    {
                        trigger->setFaction(35);
                        trigger->SetMaxHealth(100000);
                        trigger->SetHealth(100000);
                        trigger->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
                        if (Cloud)
                            Cloud->CastCustomSpell(trigger, /*43661*/43137, &bp0, NULL, NULL, true, 0, 0, Cloud->GetGUID());
                    }
                }
            }
            ++StormCount;
            if (StormCount > 10)
            {
                StormCount = 0; // finish
                SummonEagles_Timer = 5000;
                me->InterruptNonMeleeSpells(false);
                CloudGUID = 0;
                if (Cloud)
                    Cloud->DealDamage(Cloud, Cloud->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
                SetWeather(WEATHER_STATE_FINE, 0.0f);
                isRaining = false;
            }
            StormSequenceTimer = 1000;
        }
Example #16
0
bool TerrainInfo::CheckPathAccurate(float srcX, float srcY, float srcZ, float& dstX, float& dstY, float& dstZ, Unit* mover ) const
{

    float tstX = dstX;
    float tstY = dstY;
    float tstZ = dstZ;
    // check by standart way. may be not need path checking?
    if (!mover && CheckPath(srcX, srcY, srcZ, tstX, tstY, tstZ) && IsNextZcoordOK(tstX, tstY, tstZ, 5.0f))
    {
        DEBUG_LOG("TerrainInfo::CheckPathAccurate vmaps hit! delta is %f %f %f",dstX - tstX,dstY - tstY,dstZ - tstZ);
        dstX = tstX;
        dstY = tstY;
        dstZ = tstZ + 0.1f;
        return true;
    }

    const float distance = sqrt((dstY - srcY)*(dstY - srcY) + (dstX - srcX)*(dstX - srcX));
    const float DELTA    = 0.5f;
    const uint8 numChecks = ceil(fabs(distance/DELTA));
    const float DELTA_X  = (dstX-srcX)/numChecks;
    const float DELTA_Y  = (dstY-srcY)/numChecks;

    float lastGoodX = srcX;
    float lastGoodY = srcY;
    float lastGoodZ = srcZ;

    uint32 errorsCount = 0;
    uint32 goodCount   = 0;
    uint32 vmaperrorsCount   = 0;

    //Going foward until max distance
    for (uint8 i = 1; i < numChecks; ++i)
    {
        float prevX = srcX + (float(i-1)*DELTA_X);
        float prevY = srcY + (float(i-1)*DELTA_Y);
        float prevZ = GetHeight(prevX, prevY, srcZ+5.0f);

        tstX = srcX + (float(i)*DELTA_X);
        tstY = srcY + (float(i)*DELTA_Y);
        tstZ = GetHeight(tstX, tstY, srcZ+5.0f);

        MaNGOS::NormalizeMapCoord(tstX);
        MaNGOS::NormalizeMapCoord(tstY);

        if (tstZ <= INVALID_HEIGHT)
            break;
        tstZ += 0.5f;

        if (!CheckPath(prevX, prevY, prevZ, tstX, tstY, tstZ))
        {
            ++vmaperrorsCount;
            ++errorsCount;
            goodCount = 0;
        }
        else if (!IsNextZcoordOK(tstX, tstY, tstZ, 5.0f))
        {
            ++errorsCount;
            goodCount = 0;
        }
        else if (mover)
        {
            std::list<GameObject*> tempTargetGOList;
            MaNGOS::GameObjectInRangeCheck check(mover, tstX, tstY, tstZ, 2*mover->GetObjectBoundingRadius());
            MaNGOS::GameObjectListSearcher<MaNGOS::GameObjectInRangeCheck> searcher(tempTargetGOList, check);
            Cell::VisitAllObjects(mover, searcher, 2*mover->GetObjectBoundingRadius());
            if (!tempTargetGOList.empty())
            {
                for(std::list<GameObject*>::iterator iter = tempTargetGOList.begin(); iter != tempTargetGOList.end(); ++iter)
                {
                    if (((*iter)->GetGoType() == GAMEOBJECT_TYPE_DOOR && (*iter)->GetGoState() == GO_STATE_READY)
                        || (*iter)->GetGoType() != GAMEOBJECT_TYPE_DOOR)
                    {
                        ++errorsCount;
                        goodCount = 0;
                    }
                }
            }
            else
                ++goodCount;
        }
        else
        {
            ++goodCount;
        }

        if (!errorsCount)
        {
            lastGoodX = prevX;
            lastGoodY = prevY;
            lastGoodZ = prevZ;
        }
//        DEBUG_LOG("TerrainInfo::CheckPathAccurate test data %f %f %f good=%u, errors=%u vmap=%u",tstX,tstY,tstZ, goodCount, errorsCount, vmaperrorsCount);

        if (errorsCount && goodCount > 10)
        {
            --errorsCount;
            goodCount -= 10;
        }
    }

    if (errorsCount)
    {
        dstX = lastGoodX;
        dstY = lastGoodY;
        dstZ = GetHeight(lastGoodX, lastGoodY, lastGoodZ+2.0f) + 0.5f;
    }
    else
    {
        dstX = tstX;
        dstY = tstY;
        dstZ = GetHeight(tstX, tstY, tstZ+2.0f) + 0.5f;
    }

    return (errorsCount == 0);
}
		void UpdateAI(uint32 const diff)
		{
			events.Update(diff);

			if (!UpdateVictim())
				return;

			if (phase1_timer)
			{
				if (phase1 <= diff)
				{
					phase1_timer = false;
					phase2_timer = true;
					deadvanced = true;

					me->CastSpell(me, ADVANCE);

					if (me->HasAura(ADVANCE))
					{
						AuraPtr Advance = me->GetAura(ADVANCE);

						if (Advance)
						{
							Advance->SetDuration(10000000);
						}
					}

					me->MonsterSay("Power.. I must have more power.. Guards, Protect your empress!", LANG_UNIVERSAL, me->GetGUID());
					DoPlaySoundToSet(me, 29270);

					events.ScheduleEvent(EVENT_SUMMON_MOBS, 500);
					events.ScheduleEvent(EVENT_ADVANCE, 500);
				}
				else
					phase1 -= diff;
			}
			if (phase2_timer)
			{
				if (phase2 <= diff)
				{
					phase2_timer = false;

					if (deadvanced)
					{
						deadvanced = false;

						me->RemoveAura(ADVANCE);
						events.ScheduleEvent(EVENT_DEADVANCE, 500);
					}
				}
				else
					phase2 -= diff;
			}

			if (thirdphase)
			{
				if (Unit* victim = me->getVictim())
				{
					if (!me->IsWithinDistInMap(victim, 2.0f))
					{
						events.ScheduleEvent(EVENT_MOVE_FIX, 1000);
					}
				}
			}

			if (SayCharmed)
			{
				SayCharmed = false;

				me->MonsterYell("You are mine now!", LANG_UNIVERSAL, me->GetGUID());
				DoPlaySoundToSet(me, 29282);
			}
			// Introduction RP	

			while (uint32 eventId = events.ExecuteEvent())
			{
				switch (eventId)
				{
				case EVENT_SUMMON_MOBS:
					// side a
					me->SummonCreature(MOB_REAVER, -2453.20f, 989.60f, 569.630f, 3.498173f, TEMPSUMMON_MANUAL_DESPAWN);
					me->SummonCreature(MOB_WIND, -2448.70f, 992.45f, 569.630f, 3.407852f, TEMPSUMMON_MANUAL_DESPAWN);
					me->SummonCreature(MOB_WIND, -2445.68f, 989.26f, 569.630f, 3.407852f, TEMPSUMMON_MANUAL_DESPAWN);
					// side b
					me->SummonCreature(MOB_REAVER, -2504.68f, 987.24f, 569.630f, 0.295318f, TEMPSUMMON_MANUAL_DESPAWN);
					me->SummonCreature(MOB_WIND, -2508.52f, 981.49f, 569.630f, 0.295318f, TEMPSUMMON_MANUAL_DESPAWN);
					me->SummonCreature(MOB_WIND, -2510.62f, 992.30f, 569.630f, 0.295318f, TEMPSUMMON_MANUAL_DESPAWN);
					break;
				case EVENT_ADVANCE:
					me->SetDisplayId(11686); // invis

					if (MotionMaster* motion = me->GetMotionMaster())
						motion->MovePoint(1, -2476.62f, 1035.45f, 572.818f);

					me->SetReactState(REACT_PASSIVE);
					me->AddUnitState(UNIT_STATE_CANNOT_AUTOATTACK);

					me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC);
					me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC);

					events.CancelEvent(EVENT_DEAD_SCREECH);
					events.CancelEvent(EVENT_CRY_TERROR);
					events.CancelEvent(EVENT_EYE_OF_THE_EMPRESS);
					events.CancelEvent(EVENT_DISSONANCE_SHIELD);

					me->DespawnCreaturesInArea(DISSONANCE_SHIELD_TRIGGER);
					me->SetSpeed(MOVE_RUN, 0.0f);
					break;
				case EVENT_DEADVANCE:
					me->SetDisplayId(42730); // originial dis

                    events.ScheduleEvent(EVENT_CRY_TERROR, 7500);
                    events.ScheduleEvent(EVENT_DEAD_SCREECH, 10000);
                    events.ScheduleEvent(EVENT_EYE_OF_THE_EMPRESS, 8000);
                    events.ScheduleEvent(EVENT_DISSONANCE_SHIELD, 30000);

					me->Attack(me->getVictim(), true);

					me->SetReactState(REACT_AGGRESSIVE);
					me->ClearUnitState(UNIT_STATE_CANNOT_AUTOATTACK);
					me->SetSpeed(MOVE_RUN, 1.13f);
					me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC);
					me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC);
					break;
				case EVENT_CRY_TERROR:
					if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
					{
						me->AddAura(123788, target);
					}
					events.ScheduleEvent(EVENT_CRY_TERROR, 7500);
					break;
				case EVENT_DEAD_SCREECH:
					for (int i = 0; i <= 1; i++)
					{
						if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
						{
							me->CastSpell(target, DEAD_SCREECH_DMG);
						}
					}
					events.ScheduleEvent(EVENT_DEAD_SCREECH, 10000);
					break;
				case EVENT_EYE_OF_THE_EMPRESS:
					if (!me->getVictim()->HasAura(EYE_OF_THE_EMPRESS))
					{
						me->getVictim()->CastSpell(me->getVictim(), EYE_OF_THE_EMPRESS);
					}
					else
					{
						AuraPtr aura_B = me->getVictim()->GetAura(EYE_OF_THE_EMPRESS);

						if (aura_B && aura_B->GetStackAmount() <= 5)
						{
							aura_B->SetStackAmount(aura_B->GetStackAmount() + 1);
						}
					}
					events.ScheduleEvent(EVENT_EYE_OF_THE_EMPRESS, 6000);
					break;
				case EVENT_DISSONANCE_SHIELD:

					if (!me->FindNearestCreature(DISSONANCE_SHIELD_TRIGGER, 100.0f, true))
					{
						me->SummonCreature(DISSONANCE_SHIELD_TRIGGER, dis_1, TEMPSUMMON_MANUAL_DESPAWN, 0);
						me->SummonCreature(DISSONANCE_SHIELD_TRIGGER, dis_2, TEMPSUMMON_MANUAL_DESPAWN, 0);
					}

					events.ScheduleEvent(EVENT_DISSONANCE_SHIELD, 65000);
					break;
					// phase 3
				case EVENT_SHA_ENERGY:

					int count;

					if (Is25ManRaid())
						count = 4;
					else
						count = 1;

					for (int i = 0; i <= count; i++)
					{
						if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
						{
							me->CastSpell(target, SHA_ENERGY);
						}
					}
					events.ScheduleEvent(EVENT_SHA_ENERGY, 10000);
					break;
				case EVENT_AMASSING_DARKNESS:
					if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
					{
						if (!target->HasAura(AMASSING_DARKNESS_AURA))
						{
							me->CastSpell(target, AMASSING_DARKNESS);
							me->AddAura(AMASSING_DARKNESS_AURA, target);
						}

						UnitList targets;
						JadeCore::AnyUnitHavingBuffInObjectRangeCheck u_check(target, target, 100, AMASSING_DARKNESS_AURA, true);
						JadeCore::UnitListSearcher<JadeCore::AnyUnitHavingBuffInObjectRangeCheck> searcher(target, targets, u_check);
						target->VisitNearbyObject(100, searcher);

						for (UnitList::const_iterator it = targets.begin(); it != targets.end(); ++it)
						{
							if (!(*it))
								return;

							if ((*it)->GetGUID() != target->GetGUID())
							me->CastSpell((*it), AMASSING_DARKNESS);
						}

						if (Is25ManRaid())
							events.ScheduleEvent(EVENT_AMASSING_DARKNESS, 2500);
						else
							events.ScheduleEvent(EVENT_AMASSING_DARKNESS, 6500);
					}
					break;
				case EVENT_CONSUMING_TERROR:
					if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
					{
						// cancel first phase abilities
						events.CancelEvent(EVENT_SHA_ENERGY);
						events.CancelEvent(EVENT_AMASSING_DARKNESS);;
						events.CancelEvent(EVENT_VISIONS_OF_DEMISE);
						events.CancelEvent(EVENT_CALAMITY);

						// scehdule new abilities third phase
						events.ScheduleEvent(EVENT_SHA_ENERGY, 10000);
						events.ScheduleEvent(EVENT_AMASSING_DARKNESS, 10000);
						events.ScheduleEvent(EVENT_CONSUMING_TERROR, 40000);
						events.ScheduleEvent(EVENT_VISIONS_OF_DEMISE, urand(29000, 35000));
						events.ScheduleEvent(EVENT_CALAMITY, urand(15000, 20000));

						me->CastSpell(target, CONSUMING_TERROR);
						events.ScheduleEvent(EVENT_CONSUMING_TERROR, 40000);
					}
					break;
				case EVENT_CALAMITY:
					DoCastAOE(CALAMITY);
					events.ScheduleEvent(EVENT_CALAMITY, 20000);
					break;
				case EVENT_VISIONS_OF_DEMISE:
					for (int i = 0; i <= 1; i++)
					{
						if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
						{
							me->AddAura(124862, target);
						}
					}
					events.ScheduleEvent(EVENT_VISIONS_OF_DEMISE, urand(29000, 35000));
					break;
				case EVENT_MOVE_FIX:
					if (Unit* victim = me->getVictim())
					{
						if (!me->IsWithinDistInMap(victim, 2.0f))
						{
							if (MotionMaster* motion = me->GetMotionMaster())
							{
								motion->MovePoint(1, victim->GetPositionX(), victim->GetPositionY(), victim->GetPositionZ());
							}
							events.ScheduleEvent(EVENT_MOVE_FIX, 2000);
						}
					}
					break;
				}
			}
			DoMeleeAttackIfReady();
		}
Example #18
0
            void InitializeAI() override
            {
                Initialize();

                CasterAI::InitializeAI();
                ObjectGuid ownerGuid = me->GetOwnerGUID();
                if (!ownerGuid)
                    return;

                // Find victim of Summon Gargoyle spell
                std::list<Unit*> targets;
                Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
                Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
                me->VisitNearbyObject(30.0f, searcher);
                for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
                    if ((*iter)->HasAura(SPELL_DK_SUMMON_GARGOYLE_1, ownerGuid))
                    {
                        me->Attack((*iter), false);
                        break;
                    }
            }
		void UpdateAI(const uint32 diff)
		{
			events.Update(diff);

			if (!UpdateVictim())
				return;

			// band of valor
			std::list<Creature*> Cr_list;

			JadeCore::AnyCreatureInObjectRangeCheck check(me, 8.0f);
			JadeCore::CreatureListSearcher<JadeCore::AnyCreatureInObjectRangeCheck> searcher(me, Cr_list, check);
			me->VisitNearbyObject(8.0f, searcher);

            for (std::list<Creature*>::const_iterator it = Cr_list.begin(); it != Cr_list.end(); ++it)
            {
                if (!(*it))
                    return;

                if ((*it)->GetEntry() == 63591 || (*it)->GetEntry() == 64453)
                {
                    if (me->HasAura(125422))
                    {
                        AuraPtr band_of_valor = me->GetAura(125422);

                        if (band_of_valor)
                        {
                            band_of_valor->SetStackAmount(Cr_list.size() - 1);
                        }
                    }
                    else
                    {
                        me->AddAura(125422, me);
                    }
                }
            }
			if (me->HasAura(AMBER_TRAP))
			{
				if (diffdmgtrap <= diff)
				{
					me->DealDamage(me, me->GetHealth() * 0.05, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
					diffdmgtrap = 2100;
				}
				else
					diffdmgtrap -= diff;
			}

			while (uint32 eventId = events.ExecuteEvent())
			{
				switch (eventId)
				{
				case EVENT_POISON_BOMB:
					if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
					{
						me->CastSpell(target, POISON_BOMB);
					}
					events.ScheduleEvent(EVENT_POISON_BOMB, urand(5000, 8000));
					break;
				case EVENT_POISON_DRENCHED_ARMOR:
					me->CastSpell(me->getVictim(), POISON_DRENCHED_ARMOR);
					events.ScheduleEvent(EVENT_POISON_DRENCHED_ARMOR, urand(18000, 35000));
					break;
				case EVENT_TOXIC_SLIME:
					me->CastSpell(me->getVictim(), TOXIC_SLIME);
					events.ScheduleEvent(EVENT_TOXIC_SLIME, urand(12000, 18000));
					break;
				}
			}

			DoMeleeAttackIfReady();
		}
void AreaTrigger::Update(uint32 p_time)
{
    if (GetDuration() > int32(p_time))
        _duration -= p_time;
    else
        Remove(); // expired

    WorldObject::Update(p_time);

    SpellInfo const* m_spellInfo = sSpellMgr->GetSpellInfo(GetUInt32Value(AREATRIGGER_SPELLID));
    if (!m_spellInfo)
        return;

    if (!GetCaster())
    {
        Remove();
        return;
    }

    Unit* caster = GetCaster();
    float radius = 0.0f;

    // Custom MoP Script
    switch (m_spellInfo->Id)
    {
        case 102793:// Ursol's Vortex
        {
            std::list<Unit*> targetList;
            radius = 8.0f;

            JadeCore::NearestAttackableUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::NearestAttackableUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
                for (auto itr : targetList)
                    if (!itr->HasAura(127797))
                        caster->CastSpell(itr, 127797, true);

            break;
        }
        case 115460:// Healing Sphere
        {
            std::list<Unit*> targetList;
            radius = 1.0f;

            JadeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
            {
                for (auto itr : targetList)
                {
                    caster->CastSpell(itr, 115464, true); // Healing Sphere heal
                    SetDuration(0);
                    return;
                }
            }

            break;
        }
        case 115817:// Cancel Barrier
        {
            std::list<Unit*> targetList;
            radius = 6.0f;

            JadeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
                for (auto itr : targetList)
                    itr->CastSpell(itr, 115856, true);

            break;
        }
        case 116011:// Rune of Power
        {
            std::list<Unit*> targetList;
            bool affected = false;
            radius = 2.25f;

            JadeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
            {
                for (auto itr : targetList)
                {
                    if (itr->GetGUID() == caster->GetGUID())
                    {
                        caster->CastSpell(itr, 116014, true); // Rune of Power
                        affected = true;

                        if (caster->ToPlayer())
                            caster->ToPlayer()->UpdateManaRegen();

                        return;
                    }
                }
            }

            if (!affected)
                caster->RemoveAura(116014);

            break;
        }
        case 116235:// Amethyst Pool
        {
            std::list<Unit*> targetList;
            radius = 10.0f;

            JadeCore::NearestAttackableUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::NearestAttackableUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
            {
                for (auto itr : targetList)
                {
                    // Amethyst Pool - Periodic Damage
                    if (itr->GetDistance(this) > 3.5f)
                        itr->RemoveAura(130774);
                    else if (!itr->HasAura(130774))
                        caster->CastSpell(itr, 130774, true);
                }
            }

            break;
        }
        case 116546:// Draw Power
        {
            std::list<Unit*> targetList;
            radius = 30.0f;

            JadeCore::NearestAttackableUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::NearestAttackableUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            for (auto itr : targetList)
            {
                if (itr->IsInAxe(caster, this, 2.0f))
                {
                    if (!itr->HasAura(116663))
                        caster->AddAura(116663, itr);
                }
                else
                    itr->RemoveAurasDueToSpell(116663);
            }

            break;
        }
        case 117032:// Healing Sphere (Afterlife)
        {
            std::list<Unit*> targetList;
            radius = 1.0f;

            JadeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
            {
                for (auto itr : targetList)
                {
                    if (itr->GetGUID() == caster->GetGUID())
                    {
                        caster->CastSpell(itr, 125355, true); // Heal for 15% of life
                        SetDuration(0);
                        return;
                    }
                }
            }

            break;
        }
        case 119031:// Gift of the Serpent (Mastery)
        {
            std::list<Unit*> targetList;
            radius = 1.0f;

            JadeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
            {
                for (auto itr : targetList)
                {
                    caster->CastSpell(itr, 124041, true); // Gift of the Serpent heal
                    SetDuration(0);
                    return;
                }
            }

            break;
        }
        case 121286:// Chi Sphere (Afterlife)
        {
            std::list<Unit*> targetList;
            radius = 1.0f;

            JadeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
            {
                for (auto itr : targetList)
                {
                    if (itr->GetGUID() == caster->GetGUID())
                    {
                        caster->CastSpell(itr, 121283, true); // Restore 1 Chi
                        SetDuration(0);
                        return;
                    }
                }
            }

            break;
        }
        case 121536:// Angelic Feather
        {
            std::list<Unit*> targetList;
            radius = 1.0f;

            JadeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
            {
                for (auto itr : targetList)
                {
                    caster->CastSpell(itr, 121557, true); // Angelic Feather increase speed
                    SetDuration(0);
                    return;
                }
            }

            break;
        }
        case 122035:// Path of Blossom
        {
            std::list<Unit*> targetList;
            radius = 1.0f;

            JadeCore::NearestAttackableUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::NearestAttackableUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            if (!targetList.empty())
            {
                for (auto itr : targetList)
                {
                    caster->CastSpell(itr, 122036, true); // Path of Blossom damage
                    SetDuration(0);
                    return;
                }
            }

            break;
        }
        case 124503:// Gift of the Ox
        case 124506:// Gift of the Ox²
        {
            std::list<Unit*> targetList;
            radius = 1.0f;

            JadeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius);
            JadeCore::UnitListSearcher<JadeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check);
            VisitNearbyObject(radius, searcher);

            for (auto itr : targetList)
            {
                if (itr->GetGUID() != caster->GetGUID())
                    continue;

                caster->CastSpell(itr, 124507, true); // Gift of the Ox - Heal
                SetDuration(0);
                return;
            }

            break;
        }
        default:
            break;
    }
}
Example #21
0
            void SendAttacker(Unit* target)
            {
                std::list<Creature*> templist;
                float x, y, z;
                me->GetPosition(x, y, z);

                {
                    CellCoord pair(Trinity::ComputeCellCoord(x, y));
                    Cell cell(pair);
                    cell.SetNoCreate();

                    Trinity::AllFriendlyCreaturesInGrid check(me);
                    Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid> searcher(me, templist, check);

                    TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid>, GridTypeMapContainer> cSearcher(searcher);

                    cell.Visit(pair, cSearcher, *(me->GetMap()), *me, me->GetGridActivationRange());
                }

                if (templist.empty())
                    return;

                for (std::list<Creature*>::const_iterator i = templist.begin(); i != templist.end(); ++i)
                {
                    if ((*i) && me->IsWithinDistInMap((*i), 25))
                    {
                        (*i)->SetNoCallAssistance(true);
                        (*i)->AI()->AttackStart(target);
                    }
                }
            }
Example #22
0
//return closest creature alive in grid, with range from pSource
Creature* GetClosestCreatureWithEntry(WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange)
{
    Creature* pCreature = NULL;

    MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*pSource, uiEntry, true, false, fMaxSearchRange);
    MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pCreature, creature_check);

    Cell::VisitGridObjects(pSource, searcher, fMaxSearchRange);

    return pCreature;
}
Example #23
0
int search(int * arr, int length, int key)
{
  return searcher(arr, 0, length - 1, key);
}
Example #24
0
bool BfCapturePoint::Update(uint32 diff)
{
    if (!m_capturePointGUID)
        return false;

    if (GameObject* capturePoint = m_Bf->GetGameObject(m_capturePointGUID))
    {
        float radius = capturePoint->GetGOInfo()->controlZone.radius;

        for (uint8 team = 0; team < BG_TEAMS_COUNT; ++team)
        {
            for (GuidSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();)
            {
                if (Player* player = ObjectAccessor::FindPlayer(*itr))
                {
                    if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
                        itr = HandlePlayerLeave(player);
                    else
                        ++itr;
                }
                else
                    ++itr;
            }
        }

        std::list<Player*> players;
        Trinity::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
        Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
        capturePoint->VisitNearbyWorldObject(radius, searcher);

        for (std::list<Player*>::iterator itr = players.begin(); itr != players.end(); ++itr)
            if ((*itr)->IsOutdoorPvPActive())
                if (m_activePlayers[(*itr)->GetTeamId()].insert((*itr)->GetGUID()).second)
                    HandlePlayerEnter(*itr);
    }

    // get the difference of numbers
    float fact_diff = ((float) m_activePlayers[TEAM_ALLIANCE].size() - (float) m_activePlayers[TEAM_HORDE].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
    if (G3D::fuzzyEq(fact_diff, 0.0f))
        return false;

    uint32 Challenger = 0;
    float maxDiff = m_maxSpeed * diff;

    if (fact_diff < 0)
    {
        // horde is in majority, but it's already horde-controlled -> no change
        if (m_State == BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE && m_value <= -m_maxValue)
            return false;

        if (fact_diff < -maxDiff)
            fact_diff = -maxDiff;

        Challenger = HORDE;
    }
    else
    {
        // ally is in majority, but it's already ally-controlled -> no change
        if (m_State == BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE && m_value >= m_maxValue)
            return false;

        if (fact_diff > maxDiff)
            fact_diff = maxDiff;

        Challenger = ALLIANCE;
    }

    float oldValue = m_value;
    TeamId oldTeam = m_team;

    m_OldState = m_State;

    m_value += fact_diff;

    if (m_value < -m_minValue)                              // red
    {
        if (m_value < -m_maxValue)
            m_value = -m_maxValue;
        m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE;
        m_team = TEAM_HORDE;
    }
    else if (m_value > m_minValue)                          // blue
    {
        if (m_value > m_maxValue)
            m_value = m_maxValue;
        m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE;
        m_team = TEAM_ALLIANCE;
    }
    else if (oldValue * m_value <= 0)                       // grey, go through mid point
    {
        // if challenger is ally, then n->a challenge
        if (Challenger == ALLIANCE)
            m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE;
        // if challenger is horde, then n->h challenge
        else if (Challenger == HORDE)
            m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE;
        m_team = TEAM_NEUTRAL;
    }
    else                                                    // grey, did not go through mid point
    {
        // old phase and current are on the same side, so one team challenges the other
        if (Challenger == ALLIANCE && (m_OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE || m_OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE))
            m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE;
        else if (Challenger == HORDE && (m_OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE || m_OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE))
            m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE;
        m_team = TEAM_NEUTRAL;
    }

    if (G3D::fuzzyNe(m_value, oldValue))
        SendChangePhase();

    if (m_OldState != m_State)
    {
        //TC_LOG_ERROR("bg.battlefield", "%u->%u", m_OldState, m_State);
        if (oldTeam != m_team)
            ChangeTeam(oldTeam);
        return true;
    }

    return false;
}
    Creature* SelectCreatureInGrid(uint32 entry, float range)
    {
        Creature* pCreature = NULL;

        CellPair pair(BlizzLike::ComputeCellPair(me->GetPositionX(), me->GetPositionY()));
        Cell cell(pair);
        cell.data.Part.reserved = ALL_DISTRICT;
        cell.SetNoCreate();

        BlizzLike::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*me, entry, true, range);
        BlizzLike::CreatureLastSearcher<BlizzLike::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pCreature, creature_check);
        TypeContainerVisitor<BlizzLike::CreatureLastSearcher<BlizzLike::NearestCreatureEntryWithLiveStateInObjectRangeCheck>, GridTypeMapContainer> creature_searcher(searcher);
        cell.Visit(pair, creature_searcher,*(me->GetMap()));

        return pCreature;
    }
Example #26
0
string checker(astree* root, SymbolTable* table){
   if(root == NULL) return NULL;
   string names = get_yytname(root->symbol);

   if(names == "TOK_INT" || names == "TOK_INTCON") return "int";
   if(names == "TOK_CHAR" || names == "TOK_CHARCON") return "char";
   if(names == "TOK_STRING" || names == "TOK_STRINGCON") return "string";
   if(names == "TOK_BOOL" || names == "TOK_TRUE" || names == "TOK_FALSE") return "bool";
   if(names == "TOK_NULL") return "null";

   if(names == "TOK_IDENT") return table->lookup(root->lexinfo->c_str());
   if(names == "constant") return checker(root->children[0], table);
   if(names == "type"){
      if(root->children.size() == 2){
         string type = checker(root->children[0],table);
         type = type + "[]";
         return type;
      }
    return checker(root->children[0], table);
   }
   if(names == "basetype"){
      string offSpr = get_yytname(root->children[0]->symbol);
      string ident = root->children[0]->lexinfo->c_str();
      if(offSpr == "TOK_IDENT"){
         if (strSym->lookup2(ident) != NULL) return ident;
      }
      return checker(root->children[0], table);

   }
   if(names == "variable") {
      if(root->children.size() == 1) return checker(root->children[0], table);
      if(root->children.size() == 2){
         string offSpr2 = get_yytname(root->children[1]->symbol);
         SymbolTable* curnt;
         if(offSpr2 == "TOK_IDENT"){
            string offSpr = checker(root->children[0],table);
            string ident = root->children[1]->lexinfo->c_str();
            if(strSym->lookup2(offSpr) != NULL){
               curnt = strSym->lookup2(offSpr);
               if (curnt == NULL){ 
                  errprintf("Not a variable of this struct!\n");
                  return "";
               }
               return curnt->lookup(ident);
            }
         }else{
            if(checker(root->children[1],table) == "int" && checker(root->children[0],table) == "string") return "char"; 
            if(checker(root->children[1],table) == "int" && checker(root->children[0],table) == "int[]") return "int";
            if(checker(root->children[1],table) == "int" && checker(root->children[0],table) == "bool[]") return "bool";
            if(checker(root->children[1],table) == "int" && checker(root->children[0],table) == "char[]") return "char";
            if(checker(root->children[1],table) == "int" && checker(root->children[0],table) == "struct[]") return "struct";
            if(checker(root->children[1],table) == "int" && checker(root->children[0],table) == "string[]") return "string";
         }
      }

   }

   if(names == "call"){
      string funcoper = "(";
      string funcname;
      string funcops;
      size_t check = -1;
      int begin;
      int comcounter = 0;
      int firstparen;
      for(size_t child = 0; child < root->children.size(); ++child){
         string currchild = get_yytname(root->children[child]->symbol);
         if(currchild != "TOK_IDENT"){
            if (comcounter != 0) funcoper = funcoper + ",";
            string currop = checker(root->children[child], table);
            funcoper = funcoper + currop;
            comcounter++;
         }
         if(currchild == "TOK_IDENT") funcname = root->children[child]->lexinfo->c_str();
      }
      funcoper = funcoper + ")";
      funcops = table->lookup(funcname);
      begin = funcops.length() - funcoper.length();
      if(funcops.find(funcoper) == check)
         errprintf("Incorrect arguments passed to function!\n");
      firstparen = funcops.find_first_of('(', 0);
      return funcops.substr(0,firstparen);
   }


   if(names == "vardecl"){
      string c0 = checker(root->children[0],table);
      string c1 = checker(root->children[2],table);
      if(c0 != c1) errprintf("Declaring incorrect type!\n");
      return "";
   }
   if(names == "program"){
      for(size_t child = 0; child < root->children.size(); ++ child){
         checker(root->children[child], table);
      }
   }
   if(names == "while_" || names == "if_"){
      if(checker(root->children[0],table) != "bool") errprintf("Expression does not return a bool!\n");
      checker(root->children[1], table);
      if(root->children[2] != NULL) checker(root->children[2], table);
      return "";
   }
   if(names == "function"){
      SymbolTable* currblock;
      astree* blockroot;
      string funcreturn;
      for(size_t child = 0; child < root->children.size(); ++child){
         string currchild = get_yytname(root->children[child]->symbol);
         if(currchild == "type"){
            funcreturn = checker(root->children[child], table);
         }
         if(currchild == "block"){
            currblock = root->children[child]->blockpt;
            blockroot = root->children[child];
         }
      }
      if(!searcher(blockroot, funcreturn, currblock)) errprintf("Incorrect return type!\n");
   }
   if(names == "block"){
      SymbolTable* currtable = root->blockpt;
      for(size_t child = 0; child < root->children.size(); ++child){
         checker(root->children[child], currtable);
      }
   }
   if(names == "allocator_"){
      if(root->children.size() < 3) return checker(root->children[1],table);
      else{
         string bracket = get_yytname(root->children[3]->symbol);
         string result = checker(root->children[1],table);
         if(bracket == "'['"){
            if(checker(root->children[2],table) == "int"){
               result = result + "[]";
               return result;
            }else errprintf("Need int in brackets!\n");
         }else return result;
      }
   }
   if(names == "binop"){
      string offSpr2 = get_yytname(root->children[1]->symbol);
      if(offSpr2 == "'+'" || offSpr2 == "'-'" || offSpr2 == "'*'" || offSpr2 == "'/'" || offSpr2 == "'%'"){
         if(checker(root->children[0],table) == "int" && checker(root->children[0], table) == checker(root->children[2],table))
            return "int";
         else errprintf("One or more inputs is not of type int\n");
      }
      if(offSpr2 == "TOK_LT" || offSpr2 == "TOK_LE" || offSpr2 == "TOK_GT" || offSpr2 == "TOK_GE"){
         string c0 = checker(root->children[0], table);
         string c1 = checker(root->children[2], table);
         if((c0 == "int" || c0 == "char" || c0 == "bool") && c0 == c1 )
            return "bool";
         else
            errprintf("Comparison of different or incorrect types!\n");
      }
      if(offSpr2 == "TOK_NE" || offSpr2 == "TOK_EQ"){
         string c0 = checker(root->children[0], table);
         string c1 = checker(root->children[2], table);
         if(c0 == c1 || (c0 != "bool" && c0 != "int" && c0 != "char" && c1 == "null"))
            return "bool";
         else
            errprintf("Comparison of different types!\n");
      }
      if(offSpr2 == "'='"){
         string c0 = checker(root->children[0], table);
         string c1 = checker(root->children[2], table);
         if(c0 == c1 || (c0 != "bool" && c0 != "int" && c0 != "char" && c1 == "null"))
            return c0;
         else
            errprintf("Trying to set variable to different type!\n");
      }
   }

   if(names == "unop"){
      string offSpr = get_yytname(root->children[0]->symbol);
      if(offSpr == "TOK_POS" || offSpr == "TOK_NEG"){
         if(checker(root->children[0]->children[0], table) == "int") return "int";
         else errprintf("Tried adding sign to non-int type!\n");
      }
      if(offSpr == "'!'"){
         if(checker(root->children[0]->children[0], table) == "bool") return "bool";
         else errprintf("Tried negating a non-bool!\n");
      }
      if(offSpr == "TOK_ORD"){
         if(checker(root->children[0]->children[0], table) == "char") return "int";
         else errprintf("Tried using ord on non-char type!\n");
      }
      if(offSpr == "TOK_CHR"){
         if(checker(root->children[0]->children[0], table) == "int") return "char";
         else errprintf("Tried using chr on non-int type!\n");
      }
   }
   return ""; 

}
Example #27
0
            void FlashFreeze()
            {
                std::list<Unit*> TargetList;
                Trinity::AnyUnfriendlyUnitInObjectRangeCheck checker(me, me, 100.0f);
                Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, TargetList, checker);
                me->VisitNearbyObject(100.0f, searcher);
                for (std::list<Unit*>::iterator itr = TargetList.begin(); itr != TargetList.end(); ++itr)
                {
                    Unit* target = *itr;
                    if (!target || !target->IsAlive() || GetClosestCreatureWithEntry(target, NPC_SNOWPACKED_ICICLE, 5.0f))
                        continue;

                    if (target->HasAura(SPELL_FLASH_FREEZE_HELPER) || target->HasAura(SPELL_BLOCK_OF_ICE))
                    {
                        me->CastSpell(target, SPELL_FLASH_FREEZE_KILL, true);
                        continue;
                    }

                    target->CastSpell(target, SPELL_SUMMON_BLOCK_OF_ICE, true);
                }
            }
 void GetCitizenGuids()
 {
     // if one GUID is empty it means all the others are empty as well so we should store them
     // otherwise do not call for grid search since someone else already activated event once before and guids are stored
     if (gryshkaGUID.IsEmpty())
     {
         std::list<Unit*> citizenList;
         Trinity::AnyFriendlyUnitInObjectRangeCheck checker(me, me, 25.0f);
         Trinity::UnitListSearcher<Trinity::AnyFriendlyUnitInObjectRangeCheck> searcher(me, citizenList, checker);
         me->VisitNearbyObject(20.0f, searcher);
         for (Unit* target : citizenList)
         {
             switch (target->GetEntry())
             {
             case NPC_GRYSHKA:
                 gryshkaGUID = target->GetGUID();
                 break;
             case NPC_OLVIA:
                 olviaGUID = target->GetGUID();
                 break;
             case NPC_SANA:
                 sanaGUID = target->GetGUID();
                 break;
             case NPC_FELIKA:
                 felikaGUID = target->GetGUID();
                 break;
             case NPC_THATHUNG:
                 thungGUID = target->GetGUID();
                 break;
             case NPC_KAJA:
                 kajaGUID = target->GetGUID();
                 break;
             default:
                 break;
             }
         }
     }
 }
            void OnPeriodic(constAuraEffectPtr /*aurEff*/)
            {
                // Every 5 seconds
                Unit* target = GetTarget();
                Unit* caster = GetCaster();

                // If our player is no longer sit, remove all auras
                if (target->getStandState() != UNIT_STAND_STATE_SIT)
                {
                    target->RemoveAura(SPELL_ROMANTIC_PICNIC_ACHIEV);
                    target->RemoveAura(GetAura());
                    return;
                }

                target->CastSpell(target, SPELL_BASKET_CHECK, false); // unknown use, it targets Romantic Basket
                target->CastSpell(target, RAND(SPELL_MEAL_EAT_VISUAL, SPELL_DRINK_VISUAL), false);

                bool foundSomeone = false;
                // For nearby players, check if they have the same aura. If so, cast Romantic Picnic (45123)
                // required by achievement and "hearts" visual
                std::list<Player*> playerList;
                SurgeCore::AnyPlayerInObjectRangeCheck checker(target, INTERACTION_DISTANCE*2);
                SurgeCore::PlayerListSearcher<SurgeCore::AnyPlayerInObjectRangeCheck> searcher(target, playerList, checker);
                target->VisitNearbyWorldObject(INTERACTION_DISTANCE*2, searcher);
                for (std::list<Player*>::const_iterator itr = playerList.begin(); itr != playerList.end(); ++itr)
                {
                    if ((*itr) != target && (*itr)->HasAura(GetId())) // && (*itr)->getStandState() == UNIT_STAND_STATE_SIT)
                    {
                        if (caster)
                        {
                            caster->CastSpell(*itr, SPELL_ROMANTIC_PICNIC_ACHIEV, true);
                            caster->CastSpell(target, SPELL_ROMANTIC_PICNIC_ACHIEV, true);
                        }
                        foundSomeone = true;
                        // break;
                    }
                }

                if (!foundSomeone && target->HasAura(SPELL_ROMANTIC_PICNIC_ACHIEV))
                    target->RemoveAura(SPELL_ROMANTIC_PICNIC_ACHIEV);
            }
int
searcher(char *path, int n_bytes)
{

	DIR *d;
	int ok;
	int n=0;
	char path_new[2048];

	char buffer[1024];
	//char* buffer  = (char*)malloc(1024);
	int fd, nr;

	ok = stat(path, &s); // busco el status del path
	if (ok < 0){
		exit(EXIT_FAILURE);
	}
	if((s.st_mode & S_IFMT) == S_IFDIR){ // compruebo si es un directorio
		d = opendir(path);
		if(d == NULL)
			exit(EXIT_FAILURE);
		for(;;)
		{
			reg_dir=readdir(d);
			if (reg_dir == NULL)
				break;
			if (reg_dir->d_name[0] == '.'){ // paso de los directorios raiz
				continue;
			}else{
				memset(path_new, 0, 2048);
				strcat(path_new, path);
				strcat(path_new, "/");
				strcat(path_new, reg_dir->d_name);

				ok=stat(path_new, &s); // compruebo el path construido
				if(ok<0)
					exit(EXIT_FAILURE);
				if((s.st_mode & S_IFMT) == S_IFDIR){ // si me encuentro otro directorio lo hago recursivo
					n = n + searcher(path_new, n_bytes);

				}else if((s.st_mode & S_IFMT) == S_IFREG){ // si es un fichero compruebo si es un txt
					if(ok_txt(path_new)){ // aqui miro para imprimir los bytes

						fd = open(path_new, O_RDONLY);
						if (fd < 0){
							fprintf(stderr, "%s %s\n", "Fallo al abrir el fichero:   ", path_new);
						}

						if (n_bytes != 0)
							lseek(fd, -n_bytes, SEEK_END);
						nr = read(fd, buffer, sizeof buffer);
						if(nr < 0){
							fprintf(stderr, "%s %s\n", "Fallo al leer el fichero:   ", path_new);
						}

						write(1, buffer, nr);
						printf("\n");
						close(fd);

						n++;


					}
				}
			}
		}
	}


	return n;
}