void UpdateAI(uint32 diff)
            {
                if (killtimer>=diff)
                    killtimer -= diff;
                if (steertimer>=diff)
                    steertimer -= diff;

                if (!UpdateVictim() || me->HasUnitState(UNIT_STATE_CASTING))
                    return;

                events.Update(diff);

                while (uint32 eventid = events.ExecuteEvent())
                {
                    switch (eventid)
                    {
                    case EVENT_STOMP:
                        if (!me->HasUnitState(UNIT_STATE_CASTING))
                            DoCast(SPELL_CONCUSSIVE_STOMP);
                        me->GetMotionMaster()->Clear();
                        events.CancelEvent(EVENT_UPDATE_PATH);
                        events.ScheduleEvent(EVENT_STOMP, urand(25000,45000));
                        events.ScheduleEvent(EVENT_SPAWN_VOLCANO, 3000);
                        events.ScheduleEvent(EVENT_UPDATE_PATH, 3000);
                        break;
                    case EVENT_SPAWN_VOLCANO:
                        for (uint32 i = urand(0,1); i<3; i++)
                        {//the pattern is elliptical
                            float dir  = float(rand_norm())*static_cast<float>(2*M_PI);
                            float dist = 25.0f * (float)rand_norm() + 15.0f;
                            me->SummonCreature(NPC_VOLCANO, 
                                               centerPosition.GetPositionX() + dist*cos(dir),
                                               centerPosition.GetPositionY() + 1.2f * dist*sin(dir),
                                               centerPosition.GetPositionZ(),
                                               me->GetOrientation());

                        }
                        break;
                    case EVENT_UPDATE_PATH:
                        {
                            me->MonsterSay("update path", LANG_UNIVERSAL, 0);
                            DoAction(ACTION_CHECK_HEALTH);
                            float ori = me->GetOrientation();
                            ori += M_PI*2 + float((direction - 25) * 0.001f) * 20.0f; //steer by 8.4 degrees per second at max
                            if (ori > M_PI*2) ori-= M_PI*2;
                            if (ori > M_PI*2) ori-= M_PI*2; // double check, it could be greater than 12.56
                            float x = me->GetPositionX() + cos(ori)*5;
                            float y = me->GetPositionX() + sin(ori)*5;
                            me->SetOrientation(ori);
                            me->GetMotionMaster()->MovePoint(0, x, y, me->GetPositionZ());
                            if (direction >25)
                                direction --;
                            else if (direction <25)
                                direction ++;
                             
                            //DoAction(ACTION_UPDATE_FOOT_PATHING);
                            if (instance)
                            {
                                instance->DoSetPowerOnPlayers(POWER_ALTERNATE_POWER, direction);
                            }
                            events.ScheduleEvent(EVENT_UPDATE_PATH, 1000, 0, 0);
                        }
                        break;
                    default:
                        break;
                    }
                }

                if(!phase1)
                    DoMeleeAttackIfReady();
            }
 void DoAction(int32 actionId)
 {
     switch (actionId)
     {
         case ACTION_UPDATE_FOOT_PATHING:
             if (false)
             {// left foot!
                 float oril = me->GetOrientation() + 4.71f;
                     if (oril > 6.28f) oril-= 6.28f;
                 //foot coordinates according to rhyolith position after 30y, then offstet of the foot by 60° on the left
                 float lx = me->GetPositionX() + /*cos(me->GetOrientation())*30 + */cos(oril)*8;
                 float ly = me->GetPositionX() + /*sin(me->GetOrientation())*30 + */sin(oril)*8;
                 if (leftfoot)
                     leftfoot->GetMotionMaster()->MovePoint(0, lx, ly, me->GetPositionZ() + 12.0f);
                 // right foot here!
                 float orir = me->GetOrientation() + 1.57f;
                     if (orir > 6.28f) orir-= 6.28f;
                 //foot coordinates according to rhyolith position after 30y, then offstet of the foot by 60° on the right
                 float rx = me->GetPositionX() + /*cos(me->GetOrientation())*30 + */cos(orir)*8;
                 float ry = me->GetPositionX() + /*(me->GetOrientation())*30 + */sin(orir)*8;
                 if (rightfoot)
                     rightfoot->GetMotionMaster()->MovePoint(0, rx, ry, me->GetPositionZ() + 12.0f);
             }
             break;
         case ACTION_STEER_LEFT:
             {
                 if (direction < 50)
                 {
                     me->MonsterSay("steer left", LANG_UNIVERSAL, 0);
                     direction++;
                 }
                 if (instance)
                 {
                     instance->DoSetPowerOnPlayers(POWER_ALTERNATE_POWER, direction);
                 }
             }
             break;
         case ACTION_STEER_RIGHT:
             {
                 if (direction > 0)
                 {
                     me->MonsterSay("steer right", LANG_UNIVERSAL, 0);
                     direction--;
                 }
                 if (instance)
                 {
                     instance->DoSetPowerOnPlayers(POWER_ALTERNATE_POWER, direction);
                 }
             }
             break;
         case ACTION_CHECK_HEALTH:
             if (rightfoot && leftfoot)
             {
                 if (rightfoot->GetHealth()+ leftfoot->GetHealth() <= me->GetMaxHealth()* 0.255f && phase1)
                 {//trigger phase 2 at 40% health
                     rightfoot->DespawnOrUnsummon();
                     leftfoot->DespawnOrUnsummon();
                     phase1= false;
                     //me->SetDisplayId(0);
                 }
                 if (rightfoot->GetHealth()* 1.2f < leftfoot->GetHealth()  || leftfoot->GetHealth()* 1.2f < rightfoot->GetHealth())
                 {//if the difference in health of the two legs is more than 20% of the lowest, redistribute hp
                     uint32 newhealth = (rightfoot->GetHealth() + leftfoot->GetHealth())/2;
                     rightfoot->SetHealth(newhealth);
                     leftfoot->SetHealth(newhealth);
                 }
             }
             break;
         default:
             break;
     }
 }