Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Doomfire Targeting
- class DoomfireTargetingAI : MoonScriptCreatureAI
- {
- MOONSCRIPT_FACTORY_FUNCTION(DoomfireTargetingAI, MoonScriptCreatureAI);
- DoomfireTargetingAI(Creature* pCreature) : MoonScriptCreatureAI(pCreature)
- {
- _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
- _unit->GetAIInterface()->SetAllowedToEnterCombat(false);
- _unit->m_noRespawn = true;
- RegisterAIUpdateEvent(1000);
- DespawnTimer = 0;
- DirChange = 0;
- lastx = _unit->GetPositionX();
- lasty = _unit->GetPositionY();
- _unit->GetAIInterface()->getUnitToFollow();
- _unit->CastSpell(_unit, DOOMFIRE_VISUAL, true);
- }
- void AIUpdate()
- {
- _unit->CastSpell(_unit, DOOMFIRE_VISUAL, true);
- DespawnTimer++;
- if(DespawnTimer >= 28)
- {
- _unit->SafeDelete();
- return;
- }
- //Check se si รจ spostato almeno di 4, altrimenti rispawna un doomfire sopra l'altro
- if(fabs(_unit->GetPositionX()-lastx)>3 || fabs(_unit->GetPositionY()-lasty)>3)
- {
- SpawnCreature(CN_DOOMFIRE);
- lastx = _unit->GetPositionX();
- lasty = _unit->GetPositionY();
- }
- // After 4 sec of last direction change, doomfire has 33% chance to change direction
- DirChange++;
- if ((DirChange == 4 && RandomUInt(3) == 1) || DirChange >= 6)
- {
- if (_unit->GetAIInterface()->getUnitToFollow())
- {
- if (RandomUInt(3) == 1 || _unit->GetDistance2dSq(_unit->GetAIInterface()->getUnitToFollow()) <= 2.0f)
- {
- _unit->GetAIInterface()->SetUnitToFollow(NULL);
- _unit->GetAIInterface()->SetUnitToFollowAngle(0.0f);
- }
- }
- if (!_unit->GetAIInterface()->getUnitToFollow())
- {
- if (RandomUInt(3) == 1)
- {
- Unit *NewTarget = NULL;
- NewTarget = GetBestPlayerTarget(TargetFilter_None,0,15);
- if(NewTarget)
- {
- _unit->GetAIInterface()->SetUnitToFollow(NewTarget);
- _unit->GetAIInterface()->SetUnitToFollowAngle(2.0f);
- }
- }
- if (!_unit->GetAIInterface()->getUnitToFollow())
- {
- float movedist = 10.0f;
- float x = 0.0f;
- float y = 0.0f;
- float xchange = (float)RandomFloat(movedist);
- float ychange = sqrt(movedist*movedist - xchange*xchange);
- if (RandomUInt(2) == 1)
- xchange *= -1;
- if (RandomUInt(2) == 1)
- ychange *= -1;
- x = _unit->GetPositionX() + xchange;
- y = _unit->GetPositionY() + ychange;
- float z = _unit->GetMapMgr()->GetLandHeight(x, y); //_unit->GetPositionZ()
- _unit->GetAIInterface()->MoveTo(x, y, z, _unit->GetOrientation());
- }
- }
- DirChange = 0;
- }
- }
- protected:
- uint32 DespawnTimer;
- uint32 DirChange;
- float lastx;
- float lasty;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement