Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. //Doomfire Targeting
  2. class DoomfireTargetingAI : MoonScriptCreatureAI
  3. {
  4.     MOONSCRIPT_FACTORY_FUNCTION(DoomfireTargetingAI, MoonScriptCreatureAI);
  5.     DoomfireTargetingAI(Creature* pCreature) : MoonScriptCreatureAI(pCreature)
  6.     {
  7.         _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
  8.         _unit->GetAIInterface()->SetAllowedToEnterCombat(false);
  9.         _unit->m_noRespawn = true;
  10.  
  11.         RegisterAIUpdateEvent(1000);
  12.  
  13.         DespawnTimer = 0;
  14.         DirChange = 0;
  15.         lastx = _unit->GetPositionX();
  16.         lasty = _unit->GetPositionY();
  17.         _unit->GetAIInterface()->getUnitToFollow();
  18.         _unit->CastSpell(_unit, DOOMFIRE_VISUAL, true);
  19.     }
  20.  
  21.     void AIUpdate()
  22.     {
  23.         _unit->CastSpell(_unit, DOOMFIRE_VISUAL, true);
  24.         DespawnTimer++;
  25.         if(DespawnTimer >= 28)
  26.         {
  27.             _unit->SafeDelete();
  28.             return;
  29.         }
  30.         //Check se si รจ spostato almeno di 4, altrimenti rispawna un doomfire sopra l'altro
  31.         if(fabs(_unit->GetPositionX()-lastx)>3 || fabs(_unit->GetPositionY()-lasty)>3)
  32.         {
  33.             SpawnCreature(CN_DOOMFIRE);
  34.             lastx = _unit->GetPositionX();
  35.             lasty = _unit->GetPositionY();
  36.         }
  37.  
  38.         // After 4 sec of last direction change, doomfire has 33% chance to change direction
  39.         DirChange++;
  40.         if ((DirChange == 4 && RandomUInt(3) == 1) || DirChange >= 6)
  41.         {
  42.             if (_unit->GetAIInterface()->getUnitToFollow())
  43.             {
  44.                 if (RandomUInt(3) == 1 || _unit->GetDistance2dSq(_unit->GetAIInterface()->getUnitToFollow()) <= 2.0f)
  45.                 {
  46.                     _unit->GetAIInterface()->SetUnitToFollow(NULL);
  47.                     _unit->GetAIInterface()->SetUnitToFollowAngle(0.0f);
  48.                 }
  49.             }
  50.  
  51.             if (!_unit->GetAIInterface()->getUnitToFollow())
  52.             {
  53.                 if (RandomUInt(3) == 1)
  54.                 {
  55.                     Unit *NewTarget = NULL;
  56.                     NewTarget = GetBestPlayerTarget(TargetFilter_None,0,15);
  57.                     if(NewTarget)
  58.                     {
  59.                         _unit->GetAIInterface()->SetUnitToFollow(NewTarget);
  60.                         _unit->GetAIInterface()->SetUnitToFollowAngle(2.0f);
  61.                     }
  62.                 }
  63.  
  64.                 if (!_unit->GetAIInterface()->getUnitToFollow())
  65.                 {
  66.                     float movedist = 10.0f;
  67.                     float x = 0.0f;
  68.                     float y = 0.0f;
  69.  
  70.                     float xchange = (float)RandomFloat(movedist);
  71.                     float ychange = sqrt(movedist*movedist - xchange*xchange);
  72.  
  73.                     if (RandomUInt(2) == 1)
  74.                         xchange *= -1;
  75.                     if (RandomUInt(2) == 1)
  76.                         ychange *= -1;
  77.  
  78.                     x = _unit->GetPositionX() + xchange;
  79.                     y = _unit->GetPositionY() + ychange;
  80.  
  81.                     float z = _unit->GetMapMgr()->GetLandHeight(x, y); //_unit->GetPositionZ()
  82.                     _unit->GetAIInterface()->MoveTo(x, y, z, _unit->GetOrientation());
  83.                 }
  84.             }
  85.  
  86.             DirChange = 0;
  87.         }
  88.     }
  89.  
  90. protected:
  91.     uint32 DespawnTimer;
  92.     uint32 DirChange;
  93.     float lastx;
  94.     float lasty;
  95. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement