您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ urand函数代码示例

51自学网 2021-06-03 09:16:46
  C++
这篇教程C++ urand函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中urand函数的典型用法代码示例。如果您正苦于以下问题:C++ urand函数的具体用法?C++ urand怎么用?C++ urand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了urand函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: KilledUnit

 void KilledUnit(Unit* pVictim) {     DoScriptText(urand(0, 1) ? SAY_SLAY_1 : SAY_SLAY_2, m_creature); }
开发者ID:Atari007,项目名称:master,代码行数:4,


示例2: UpdateAI

            void UpdateAI(const uint32 diff)            {                if (!UpdateVictim())                    return;                if (Fireball_Timer <= diff)                {                    if (Unit* victim = SelectTarget(SELECT_TARGET_RANDOM, 0))                        DoCast(victim, DUNGEON_MODE(SPELL_FIREBALL, SPELL_FIREBALL_H), true);                    Fireball_Timer = urand(4000, 7000);                }                else                    Fireball_Timer -= diff;                if (flight) // phase 1 - the flight                {                    Creature* Vazruden = Unit::GetCreature(*me, VazrudenGUID);                    if (Fly_Timer < diff || !(Vazruden && Vazruden->isAlive() && Vazruden->HealthAbovePct(20)))                    {                        flight = false;                        BellowingRoar_Timer = 6000;                        ConeOfFire_Timer = 12000;                        me->RemoveUnitMovementFlag(MOVEMENTFLAG_LEVITATING);                        me->AddUnitMovementFlag(MOVEMENTFLAG_WALKING);                        me->GetMotionMaster()->Clear();                        if (Unit* victim = SelectTarget(SELECT_TARGET_NEAREST, 0))                            me->AI()->AttackStart(victim);                        DoStartMovement(me->getVictim());                        DoScriptText(EMOTE, me);                        return;                    }                    else                        Fly_Timer -= diff;                    if (Turn_Timer <= diff)                    {                        uint32 waypoint = (Fly_Timer/10000)%2;                        if (!me->IsWithinDist3d(VazrudenRing[waypoint][0], VazrudenRing[waypoint][1], VazrudenRing[waypoint][2], 5))                            me->GetMotionMaster()->MovePoint(0, VazrudenRing[waypoint][0], VazrudenRing[waypoint][1], VazrudenRing[waypoint][2]);                        Turn_Timer = 10000;                    }                    else                        Turn_Timer -= diff;                }                else // phase 2 - land fight                {                    if (ConeOfFire_Timer <= diff)                    {                        DoCast(me, DUNGEON_MODE(SPELL_CONE_OF_FIRE, SPELL_CONE_OF_FIRE_H));                        ConeOfFire_Timer = 12000;                        Fireball_Timer = 4000;                    }                    else                        ConeOfFire_Timer -= diff;                    if (IsHeroic())                    {                        if (BellowingRoar_Timer <= diff)                        {                            DoCast(me, SPELL_BELLOWING_ROAR);                            BellowingRoar_Timer = 45000;                        }                        else                            BellowingRoar_Timer -= diff;                    }                    DoMeleeAttackIfReady();                }            }
开发者ID:Fuggi,项目名称:SkyFireEMU,代码行数:69,


示例3: UpdateAI

   void UpdateAI(const uint32 uiDiff)   {        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim() && m_creature->IsTemporarySummon())        {          if(MoveTimer < uiDiff)          {                if(m_pInstance->GetData(TYPE_WING) == RIGHT)             {                switch(WaypointId)                {                  case 1:                     MoveToPoint(2356.659f, 1185.501f, 130.636f);                     JumpNextStep(10000);                     break;                  case 2:                     MoveToPoint(2301.735f, 1179.265f, 136.944f);                     JumpNextStep(8000);                     break;                  case 3:                     MoveToPoint(2234.787f, 1180.638f, 136.344f);                     JumpNextStep(9000);                     break;                  case 4:                     MoveToPoint(2178.313f, 1244.350f, 136.107f);                     JumpNextStep(12000);                     break;                   case 5:                     MoveToPoint(2163.553f, 1277.814f, 133.444f);                     JumpNextStep(5000);                     break;                   case 6:                     MoveToPoint(2083.952f, 1287.716f, 141.146f);                     JumpNextStep(5000);                     break;                 }             }             if(m_pInstance->GetData(TYPE_WING) == LEFT)             {                switch(WaypointId)                {                  case 1:                     MoveToPoint(2188.318f, 1331.410f, 130.003f);                     JumpNextStep(10000);                     break;                   case 2:                     MoveToPoint(2165.351f, 1279.156f, 133.388f);                         JumpNextStep(8000);                     break;                    case 3:                     MoveToPoint(2083.952f, 1287.716f, 141.146f);                         JumpNextStep(9000);                     break;                 }             }           } else MoveTimer -= uiDiff;        }        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())            return;        if(m_uiFleshTimer < uiDiff)        {           DoCast(m_creature->getVictim(), SPELL_FLESH);           m_uiFleshTimer = (urand(3000, 10000));        }        else m_uiFleshTimer -= uiDiff;        DoMeleeAttackIfReady();        return;   }
开发者ID:Agustinls,项目名称:scriptdev2,代码行数:73,


示例4: switch

//.........这里部分代码省略.........                break;            case 3:                angle = i_cur_angle + static_cast<float>(M_PI/4);                break;            case 4:                angle = i_cur_angle - static_cast<float>(M_PI/4);                break;            case 5:                angle = i_cur_angle + static_cast<float>(M_PI/4);                distance /= 2;                break;            case 6:                angle = i_cur_angle - static_cast<float>(M_PI/4);                distance /= 2;                break;            case 7:                angle = i_cur_angle + static_cast<float>(M_PI/2);                break;            case 8:                angle = i_cur_angle - static_cast<float>(M_PI/2);                break;            case 9:                angle = i_cur_angle + static_cast<float>(M_PI/2);                distance /= 2;                break;            case 10:                angle = i_cur_angle - static_cast<float>(M_PI/2);                distance /= 2;                break;            case 11:                angle = i_cur_angle + static_cast<float>(M_PI/4);                distance /= 4;                break;            case 12:                angle = i_cur_angle - static_cast<float>(M_PI/4);                distance /= 4;                break;            case 13:                angle = i_cur_angle + static_cast<float>(M_PI/2);                distance /= 4;                break;            case 14:                angle = i_cur_angle - static_cast<float>(M_PI/2);                distance /= 4;                break;            case 15:                angle = i_cur_angle + static_cast<float>(M_PI*3/4);                distance /= 2;                break;            case 16:                angle = i_cur_angle - static_cast<float>(M_PI*3/4);                distance /= 2;                break;            case 17:                angle = i_cur_angle + static_cast<float>(M_PI);                distance /= 2;                break;        }        temp_x = x + distance * cos(angle);        temp_y = y + distance * sin(angle);        Strawberry::NormalizeMapCoord(temp_x);        Strawberry::NormalizeMapCoord(temp_y);        if (owner.IsWithinLOS(temp_x,temp_y,z))        {            bool is_water_now = _map->IsInWater(x,y,z);            if (is_water_now && _map->IsInWater(temp_x,temp_y,z))            {                x = temp_x;                y = temp_y;                return true;            }            float new_z = _map->GetHeight(temp_x,temp_y,z,true);            if (new_z <= INVALID_HEIGHT)                continue;            bool is_water_next = _map->IsInWater(temp_x,temp_y,new_z);            if ((is_water_now && !is_water_next && !is_land_ok) || (!is_water_now && is_water_next && !is_water_ok))                continue;            if (!(new_z - z) || distance / fabs(new_z - z) > 1.0f)            {                float new_z_left = _map->GetHeight(temp_x + (float)(cos(angle+M_PI/2)),temp_y + (float)(sin(angle+M_PI/2)),z,true);                float new_z_right = _map->GetHeight(temp_x + (float)(cos(angle-M_PI/2)),temp_y + (float)(sin(angle-M_PI/2)),z,true);                if (fabs(new_z_left - new_z) < 1.2f && fabs(new_z_right - new_z) < 1.2f)                {                    x = temp_x;                    y = temp_y;                    z = new_z;                    return true;                }            }        }    }    i_to_distance_from_caster = 0.0f;    i_nextCheckTime.Reset(urand(500,1000));    return false;}
开发者ID:sacel,项目名称:StrawberryEMU,代码行数:101,


示例5: UpdateAI

        void UpdateAI(const uint32 uiDiff) override        {            // Return since we have no target            if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())            {                return;            }            // BlastWave            if (m_uiBlastWaveTimer < uiDiff)            {                DoCastSpellIfCan(m_creature, SPELL_BLASTWAVE);                m_uiBlastWaveTimer = 20000;            }            else            {                m_uiBlastWaveTimer -= uiDiff;            }            // Shout            if (m_uiShoutTimer < uiDiff)            {                DoCastSpellIfCan(m_creature, SPELL_SHOUT);                m_uiShoutTimer = 10000;            }            else            {                m_uiShoutTimer -= uiDiff;            }            // Cleave            if (m_uiCleaveTimer < uiDiff)            {                DoCastSpellIfCan(m_creature->getVictim(), SPELL_CLEAVE);                m_uiCleaveTimer = 7000;            }            else            {                m_uiCleaveTimer -= uiDiff;            }            // Knockaway            if (m_uiKnockawayTimer < uiDiff)            {                DoCastSpellIfCan(m_creature, SPELL_KNOCKAWAY);                m_uiKnockawayTimer = 14000;            }            else            {                m_uiKnockawayTimer -= uiDiff;            }            // Summon two Beserks            if (!m_bSummoned && m_creature->GetHealthPercent() < 51.0f)            {                Creature* pGuard1 = m_creature->SummonCreature(uSummons[urand(0,2)], afLocations[0][0], afLocations[0][1], afLocations[0][2], afLocations[0][3], TEMPSUMMON_TIMED_DESPAWN, 300000);                Creature* pGuard2 = m_creature->SummonCreature(uSummons[urand(0,2)], afLocations[1][0], afLocations[1][1], afLocations[1][2], afLocations[1][3], TEMPSUMMON_TIMED_DESPAWN, 300000);                if (pGuard1)                {                    pGuard1->SetWalk(false);                    pGuard1->GetMotionMaster()->MovePoint(0, afLocations[2][0], afLocations[2][1], afLocations[2][2]);                }                if (pGuard2)                {                    pGuard1->SetWalk(false);                    pGuard1->GetMotionMaster()->MovePoint(0, afLocations[3][0], afLocations[3][1], afLocations[3][2]);                }                m_bSummoned = true;            }            DoMeleeAttackIfReady();        }
开发者ID:Chuck5ta,项目名称:ScriptDev3,代码行数:73,


示例6: UpdateAI

        void UpdateAI(uint32 uiDiff) override        {            if (bDone && uiResetTimer <= uiDiff)            {                me->GetMotionMaster()->MovePoint(0, 746.87f, 665.87f, 411.75f);                bDone = false;            } else uiResetTimer -= uiDiff;            if (!UpdateVictim())                return;            if (uiHolyFireTimer <= uiDiff)            {                if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 250, true))                {                    if (target && target->IsAlive())                        DoCast(target, SPELL_HOLY_FIRE);                }                 if (me->HasAura(SPELL_SHIELD))                    uiHolyFireTimer = 13000;                else                    uiHolyFireTimer = urand(9000, 12000);            } else uiHolyFireTimer -= uiDiff;            if (uiHolySmiteTimer <= uiDiff)            {                if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 250, true))                {                    if (target && target->IsAlive())                        DoCast(target, SPELL_SMITE);                }                if (me->HasAura(SPELL_SHIELD))                    uiHolySmiteTimer = 9000;                else                    uiHolySmiteTimer = urand(5000, 7000);            } else uiHolySmiteTimer -= uiDiff;            if (me->HasAura(SPELL_SHIELD))            {                if (uiRenewTimer <= uiDiff)                {                    me->InterruptNonMeleeSpells(true);                    uint8 uiTarget = urand(0, 1);                    switch (uiTarget)                    {                        case 0:                            DoCast(me, SPELL_RENEW);                            break;                        case 1:                            if (Creature* pMemory = ObjectAccessor::GetCreature(*me, MemoryGUID))                                if (pMemory->IsAlive())                                    DoCast(pMemory, SPELL_RENEW);                            break;                    }                    uiRenewTimer = urand(15000, 17000);                } else uiRenewTimer -= uiDiff;            }            if (!bHealth && !HealthAbovePct(25))            {                me->InterruptNonMeleeSpells(true);                DoCastAOE(SPELL_HOLY_NOVA, false);                DoCast(me, SPELL_SHIELD);                DoCastAOE(SPELL_SUMMON_MEMORY, false);                DoCastAOE(SPELL_CONFESS, false);                bHealth = true;            }            DoMeleeAttackIfReady();        }
开发者ID:AvariusProject,项目名称:AvariusCore,代码行数:71,


示例7: HandleScript

 void HandleScript(SpellEffIndex /*effIndex*/) {     GetHitUnit()->CastSpell(GetHitUnit(), memorySpellId[urand(0, 24)], true, NULL, NULL, GetCaster()->GetGUID()); }
开发者ID:AvariusProject,项目名称:AvariusCore,代码行数:4,


示例8: IsSummonedBy

 void IsSummonedBy(Unit* owner) {     if(Player* player = owner->ToPlayer())     {         me->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE + M_PI/urand(1, 6));         me->RemoveUnitMovementFlag(MOVEMENTFLAG_WALKING);     } }
开发者ID:StarCore,项目名称:MythCore,代码行数:8,


示例9: UpdateFollowerAI

    void UpdateFollowerAI(const uint32 uiDiff)    {        if (!UpdateVictim())        {            //we are doing the post-event, or...            if (HasFollowState(STATE_FOLLOW_POSTEVENT))            {                if (m_uiPostEventTimer <= uiDiff)                {                    m_uiPostEventTimer = 5000;                    Unit *pTorta = Unit::GetUnit(*me, TortaGUID);                    if (!pTorta || !pTorta->isAlive())                    {                        //something happened, so just complete                        SetFollowComplete();                        return;                    }                    switch(m_uiPhasePostEvent)                    {                        case 1:                            DoScriptText(SAY_TOOG_POST_1, me);                            break;                        case 2:                            DoScriptText(SAY_TORT_POST_2, pTorta);                            break;                        case 3:                            DoScriptText(SAY_TOOG_POST_3, me);                            break;                        case 4:                            DoScriptText(SAY_TORT_POST_4, pTorta);                            break;                        case 5:                            DoScriptText(SAY_TOOG_POST_5, me);                            break;                        case 6:                            DoScriptText(SAY_TORT_POST_6, pTorta);                            me->GetMotionMaster()->MovePoint(POINT_ID_TO_WATER, m_afToWaterLoc[0], m_afToWaterLoc[1], m_afToWaterLoc[2]);                            break;                    }                    ++m_uiPhasePostEvent;                }                else                    m_uiPostEventTimer -= uiDiff;            }            //...we are doing regular speech check            else if (HasFollowState(STATE_FOLLOW_INPROGRESS))            {                if (m_uiCheckSpeechTimer <= uiDiff)                {                    m_uiCheckSpeechTimer = 5000;                    if (urand(0,9) > 8)                        DoScriptText(RAND(SAY_TOOG_THIRST,SAY_TOOG_WORRIED), me);                }                else                    m_uiCheckSpeechTimer -= uiDiff;            }            return;        }        DoMeleeAttackIfReady();    }
开发者ID:Blumfield,项目名称:ptc2,代码行数:66,


示例10: npc_gnome_volunteerAI

 npc_gnome_volunteerAI(Creature* creature) : ScriptedAI(creature) {     _mountModel = RAND(14377, 14374, 14376, 9474, 9476, 6569, 10661, 10666, 9473);     creature->SetDisplayId(gnomemodel[urand(0, 12)]); }
开发者ID:StarCore,项目名称:MythCore,代码行数:5,


示例11: UpdateAI

            void UpdateAI(uint32 diff)            {                if (!UpdateVictim())                    return;                if (ResetTimer <= diff)                {                    if (me->IsWithinDist3d(119.223f, 1035.45f, 29.4481f, 10))                    {                        EnterEvadeMode();                        return;                    }                    ResetTimer = 5000;                } else ResetTimer -= diff;                if (CheckAddState_Timer <= diff)                {                    for (uint8 i = 0; i < 4; ++i)                        if (Creature* temp = Unit::GetCreature(*me, AddGUID[i]))                            if (temp->IsAlive() && !temp->GetVictim())                                temp->AI()->AttackStart(me->GetVictim());                    CheckAddState_Timer = 5000;                } else CheckAddState_Timer -= diff;                if (DrainPower_Timer <= diff)                {                    DoCast(me, SPELL_DRAIN_POWER, true);                    me->MonsterYell(YELL_DRAIN_POWER, LANG_UNIVERSAL, 0);                    DoPlaySoundToSet(me, SOUND_YELL_DRAIN_POWER);                    DrainPower_Timer = urand(40000, 55000);    // must cast in 60 sec, or buff/debuff will disappear                } else DrainPower_Timer -= diff;                if (SpiritBolts_Timer <= diff)                {                    if (DrainPower_Timer < 12000)    // channel 10 sec                        SpiritBolts_Timer = 13000;   // cast drain power first                    else                    {                        DoCast(me, SPELL_SPIRIT_BOLTS, false);                        me->MonsterYell(YELL_SPIRIT_BOLTS, LANG_UNIVERSAL, 0);                        DoPlaySoundToSet(me, SOUND_YELL_SPIRIT_BOLTS);                        SpiritBolts_Timer = 40000;                        SiphonSoul_Timer = 10000;    // ready to drain                        PlayerAbility_Timer = 99999;                    }                } else SpiritBolts_Timer -= diff;                if (SiphonSoul_Timer <= diff)                {                    Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 70, true);                    Unit* trigger = DoSpawnCreature(MOB_TEMP_TRIGGER, 0, 0, 0, 0, TEMPSUMMON_TIMED_DESPAWN, 30000);                    if (!target || !trigger)                    {                        EnterEvadeMode();                        return;                    }                    else                    {                        trigger->SetDisplayId(11686);                        trigger->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);                        trigger->CastSpell(target, SPELL_SIPHON_SOUL, true);                        trigger->GetMotionMaster()->MoveChase(me);                        //DoCast(target, SPELL_SIPHON_SOUL, true);                        //me->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, target->GetGUID());                        //me->SetUInt32Value(UNIT_CHANNEL_SPELL, SPELL_SIPHON_SOUL);                        PlayerGUID = target->GetGUID();                        PlayerAbility_Timer = urand(8000, 10000);                        PlayerClass = target->getClass() - 1;                        if (PlayerClass == CLASS_DRUID-1)                            PlayerClass = CLASS_DRUID;                        else if (PlayerClass == CLASS_PRIEST-1 && target->HasSpell(15473))                            PlayerClass = CLASS_PRIEST; // shadow priest                        SiphonSoul_Timer = 99999;   // buff lasts 30 sec                    }                } else SiphonSoul_Timer -= diff;                if (PlayerAbility_Timer <= diff)                {                    //Unit* target = Unit::GetUnit(*me, PlayerGUID);                    //if (target && target->IsAlive())                    //{                        UseAbility();                        PlayerAbility_Timer = urand(8000, 10000);                    //}                } else PlayerAbility_Timer -= diff;                DoMeleeAttackIfReady();            }
开发者ID:Angmon,项目名称:TrinityCore,代码行数:93,


示例12: mob_scarlet_traineeAI

		mob_scarlet_traineeAI(Creature *c) :				npc_escortAI(c) {			Start_Timer = urand(1000, 6000);		}
开发者ID:Bootz,项目名称:DeepshjirRepack,代码行数:4,


示例13: UpdateAI

    void UpdateAI(const uint32 uiDiff) override    {        // Return since we have no target        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())            return;        // he shatters only one time, at 25%        if (m_creature->GetHealthPercent() <= 25.0f && !m_bHasShattered)        {            // should he stomp even if he has no brittle golem to shatter? <-yes!            if (DoCastSpellIfCan(m_creature, m_bIsRegularMode ? SPELL_SHATTERING_STOMP : SPELL_SHATTERING_STOMP_H) == CAST_OK)            {                DoScriptText(urand(0, 1) ? SAY_STOMP_1 : SAY_STOMP_2, m_creature);                DoScriptText(EMOTE_SHATTER, m_creature);                m_uiShatterTimer = 3000;                m_bHasShattered = true;            }        }        // Shatter Golems 3 seconds after Shattering Stomp        if (m_uiShatterTimer)        {            if (m_uiShatterTimer <= uiDiff)            {                ShatterGolems();                m_uiShatterTimer = 0;            }            else                m_uiShatterTimer -= uiDiff;        }        // Summon Golems only when over 25% hp        if (m_creature->GetHealthPercent() > 25.0f)        {            if (m_uiTemperTimer < uiDiff)            {                DoScriptText(EMOTE_TO_ANVIL, m_creature);                DoScriptText(urand(0, 1) ? SAY_FORGE_1 : SAY_FORGE_2, m_creature);                SetCombatMovement(false);                if (m_pInstance)                {                    if (Creature* pAnvil = m_pInstance->GetSingleCreatureFromStorage(NPC_VOLKHAN_ANVIL))                    {                        float fX, fY, fZ;                        pAnvil->GetContactPoint(m_creature, fX, fY, fZ, INTERACTION_DISTANCE);                        m_creature->GetMotionMaster()->MovePoint(1, fX, fY, fZ);                    }                    else                        script_error_log("Npc %u couldn't be found or something really bad happened.", NPC_VOLKHAN_ANVIL);                }                m_uiTemperTimer = 30000;            }            else                m_uiTemperTimer -= uiDiff;        }        if (m_uiHeatTimer < uiDiff)        {            if (DoCastSpellIfCan(m_creature, m_bIsRegularMode ? SPELL_HEAT : SPELL_HEAT_H) == CAST_OK)                m_uiHeatTimer = urand(10000, 15000);        }        else            m_uiHeatTimer -= uiDiff;        DoMeleeAttackIfReady();    }
开发者ID:jviljoen82,项目名称:ScriptDev3,代码行数:67,


示例14: KilledUnit

 void KilledUnit(Unit* pVictim) {     if (urand(0, 1))         DoScriptText(SAY_KILL, m_creature); }
开发者ID:Area52,项目名称:scriptdev2,代码行数:5,


示例15: if

boolFleeingMovementGenerator<T>::_setMoveData(T &owner){    float cur_dist_xyz = owner.GetDistance(i_caster_x, i_caster_y, i_caster_z);    if (i_to_distance_from_caster > 0.0f)    {        if ((i_last_distance_from_caster > i_to_distance_from_caster && cur_dist_xyz < i_to_distance_from_caster)   ||                                                            // if we reach lower distance           (i_last_distance_from_caster > i_to_distance_from_caster && cur_dist_xyz > i_last_distance_from_caster) ||                                                            // if we can't be close           (i_last_distance_from_caster < i_to_distance_from_caster && cur_dist_xyz > i_to_distance_from_caster)   ||                                                            // if we reach bigger distance           (cur_dist_xyz > MAX_QUIET_DISTANCE) ||           // if we are too far           (i_last_distance_from_caster > MIN_QUIET_DISTANCE && cur_dist_xyz < MIN_QUIET_DISTANCE))                                                            // if we leave 'quiet zone'        {            // we are very far or too close, stopping            i_to_distance_from_caster = 0.0f;            i_nextCheckTime.Reset(urand(500,1000));            return false;        }        else        {            // now we are running, continue            i_last_distance_from_caster = cur_dist_xyz;            return true;        }    }    float cur_dist;    float angle_to_caster;    Unit * fright = ObjectAccessor::GetUnit(owner, i_frightGUID);    if (fright)    {        cur_dist = fright->GetDistance(&owner);        if (cur_dist < cur_dist_xyz)        {            i_caster_x = fright->GetPositionX();            i_caster_y = fright->GetPositionY();            i_caster_z = fright->GetPositionZ();            angle_to_caster = fright->GetAngle(&owner);        }        else        {            cur_dist = cur_dist_xyz;            angle_to_caster = owner.GetAngle(i_caster_x, i_caster_y) + static_cast<float>(M_PI);        }    }    else    {        cur_dist = cur_dist_xyz;        angle_to_caster = owner.GetAngle(i_caster_x, i_caster_y) + static_cast<float>(M_PI);    }    // if we too close may use 'path-finding' else just stop    i_only_forward = cur_dist >= MIN_QUIET_DISTANCE/3;    //get angle and 'distance from caster' to run    float angle;    if (i_cur_angle == 0.0f && i_last_distance_from_caster == 0.0f) //just started, first time    {        angle = (float)rand_norm()*(1.0f - cur_dist/MIN_QUIET_DISTANCE) * static_cast<float>(M_PI/3) + (float)rand_norm()*static_cast<float>(M_PI*2/3);        i_to_distance_from_caster = MIN_QUIET_DISTANCE;        i_only_forward = true;    }    else if (cur_dist < MIN_QUIET_DISTANCE)    {        angle = static_cast<float>(M_PI/6) + (float)rand_norm()*static_cast<float>(M_PI*2/3);        i_to_distance_from_caster = cur_dist*2/3 + (float)rand_norm()*(MIN_QUIET_DISTANCE - cur_dist*2/3);    }    else if (cur_dist > MAX_QUIET_DISTANCE)    {        angle = (float)rand_norm()*static_cast<float>(M_PI/3) + static_cast<float>(M_PI*2/3);        i_to_distance_from_caster = MIN_QUIET_DISTANCE + 2.5f + (float)rand_norm()*(MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE - 2.5f);    }    else    {        angle = (float)rand_norm()*static_cast<float>(M_PI);        i_to_distance_from_caster = MIN_QUIET_DISTANCE + 2.5f + (float)rand_norm()*(MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE - 2.5f);    }    int8 sign = rand_norm() > 0.5f ? 1 : -1;    i_cur_angle = sign*angle + angle_to_caster;    // current distance    i_last_distance_from_caster = cur_dist;    return true;}
开发者ID:sacel,项目名称:StrawberryEMU,代码行数:93,


示例16: UpdateAI

    void UpdateAI(const uint32 uiDiff)    {        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())            return;        if (!m_bIsEnraged && m_creature->GetHealthPercent() < 25.0f)        {            if (!m_creature->IsNonMeleeSpellCasted(false))            {                m_bIsEnraged = true;                DoScriptText(SAY_ENRAGE, m_creature);                DoCastSpellIfCan(m_creature, SPELL_ENRAGE);            }        }        if (uiCrystalChainTimer < uiDiff)        {            if (!m_creature->IsNonMeleeSpellCasted(false))            {                if (m_bIsRegularMode)                {                    if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 1))                    {                        if (Player* pPlayer = pTarget->GetCharmerOrOwnerPlayerOrPlayerItself())                            DoCastSpellIfCan(pPlayer, SPELL_CRYSTAL_CHAINS);                        uiCrystalChainTimer = 30000;                    }                }                else                {                    if (Unit* pSource = m_creature->getVictim())                    {                        uiCrystalChainTimer = 15000;                        Player* pPlayer = pSource->GetCharmerOrOwnerPlayerOrPlayerItself();                        if (!pPlayer)                            return;                        if (Group* pGroup = pPlayer->GetGroup())                        {                            for(GroupReference* pRef = pGroup->GetFirstMember(); pRef != NULL; pRef = pRef->next())                            {                                if (Player* pMember = pRef->getSource())                                {                                    if (pMember->isAlive() && pMember->IsWithinDistInMap(m_creature, 50.0f))                                        m_creature->CastSpell(pMember, SPELL_CRYSTAL_CHAINS, true);                                }                            }                        }                        else                            m_creature->CastSpell(pPlayer, SPELL_CRYSTAL_CHAINS, false);                    }                }            }        }        else            uiCrystalChainTimer -= uiDiff;        if (uiTailSweepTimer < uiDiff)        {            if (DoCastSpellIfCan(m_creature, SPELL_TAIL_SWEEP) == CAST_OK)                uiTailSweepTimer = urand(2500, 7500);        }        else            uiCrystalChainTimer -= uiDiff;        if (uiCrystalfireBreathTimer < uiDiff)        {            if (DoCastSpellIfCan(m_creature, m_bIsRegularMode ? SPELL_CRYSTALFIRE_BREATH : SPELL_CRYSTALFIRE_BREATH_H) == CAST_OK)                uiCrystalfireBreathTimer = urand(15000, 20000);        }        else            uiCrystalfireBreathTimer -= uiDiff;        if (!m_bIsRegularMode)        {            if (uiCrystallizeTimer < uiDiff)            {                if (DoCastSpellIfCan(m_creature, SPELL_CRYSTALLIZE) == CAST_OK)                {                    uiCrystallizeTimer = urand(15000, 25000);                    DoScriptText(SAY_CRYSTAL_NOVA, m_creature);                }            }            else                uiCrystallizeTimer -= uiDiff;        }        DoMeleeAttackIfReady();    }
开发者ID:Area52,项目名称:scriptdev2,代码行数:92,


示例17: KilledUnit

 void KilledUnit(Unit* /*victim*/) {     DoScriptText(urand(0, 1) ? SAY_SLAY1 : SAY_SLAY2, me);     events.DelayEvents(5000, GCD_YELL); }
开发者ID:Arsalan0098,项目名称:TrinityCore,代码行数:5,


示例18: Initialize

 void Initialize() {     UpperCut_Timer = urand(14000, 29000);     UnbalancingStrike_Timer = urand(8000, 18000);     Scarabs_Timer = urand(7000, 14000); }
开发者ID:AwkwardDev,项目名称:TinyCore,代码行数:6,


示例19: UpdateAI

        void UpdateAI(const uint32 diff)        {            if (IsIntro)            {                if (IntroPhaseTimer <= diff)                    DoIntro();                else IntroPhaseTimer -= diff;                if (IntroPhase == 3 + 1)                {                    if (IntroFrostBoltTimer <= diff)                    {                        if (Creature *Madrigosa = Unit::GetCreature(*me, pInstance ? pInstance->GetData64(DATA_MADRIGOSA) : 0))                        {                            Madrigosa->CastSpell(me, SPELL_INTRO_FROSTBOLT, true);                            IntroFrostBoltTimer = 2000;                        }                    } else IntroFrostBoltTimer -= diff;                }                if (!UpdateVictim())                    return;                DoMeleeAttackIfReady();            }            if (!UpdateVictim() || IsIntro)                return;            if (SlashTimer <= diff)            {                DoCast(me->getVictim(), SPELL_METEOR_SLASH);                SlashTimer = 11000;            } else SlashTimer -= diff;            if (StompTimer <= diff)            {                DoScriptText(RAND(YELL_LOVE1, YELL_LOVE2, YELL_LOVE3), me);                DoCast(me->getVictim(), SPELL_STOMP);                StompTimer = 30000;            } else StompTimer -= diff;            if (BurnTimer <= diff)            {                std::list<Unit*> pTargets;                SelectTargetList(pTargets, 10, SELECT_TARGET_RANDOM, 100, true);                for (std::list<Unit*>::const_iterator i = pTargets.begin(); i != pTargets.end(); ++i)                    if (!(*i)->HasAura(SPELL_BURN))                    {                        (*i)->CastSpell((*i), SPELL_BURN, true);                        break;                    }                BurnTimer = urand(60000, 180000);            } else BurnTimer -= diff;            if (BerserkTimer < diff && !Enraged)            {                DoScriptText(YELL_BERSERK, me);                DoCast(me, SPELL_BERSERK);                Enraged = true;            } else BerserkTimer -= diff;            DoMeleeAttackIfReady();        }
开发者ID:antiker,项目名称:StarGateEmu-Projekt,代码行数:62,


示例20: KilledUnit

 void KilledUnit(Unit* /*victim*/) {     if (!urand(0, 4))         DoScriptText(RAND(SAY_SLAY_1, SAY_SLAY_2), me); }
开发者ID:Bootz,项目名称:TrilliumEMU,代码行数:5,


示例21: Reset

 void Reset() {     KidneyShot_Timer = urand(3000, 7000); }
开发者ID:Fuggi,项目名称:SkyFireEMU,代码行数:4,


示例22: UpdateAI

            void UpdateAI(const uint32 diff)            {                if (!UpdateVictim())                    return;                events.Update(diff);                if (me->HasUnitState(UNIT_STAT_CASTING))                    return;                while (uint32 eventId = events.ExecuteEvent())                {                    switch (eventId)                    {                        case EVENT_JET:                            me->MonsterTextEmote(EMOTE_JETS, 0, true);                            DoCast(me, SPELL_FLAME_JETS);                            events.ScheduleEvent(EVENT_JET, urand(35000, 40000));                            break;                        case EVENT_SLAG_POT:                            if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true))                            {                                DoScriptText(SAY_SLAG_POT, me);                                _slagPotGUID = target->GetGUID();                                DoCast(target, SPELL_GRAB);                                events.DelayEvents(3000);                                events.ScheduleEvent(EVENT_GRAB_POT, 500);                            }                            events.ScheduleEvent(EVENT_SLAG_POT, RAID_MODE(30000, 15000));                            break;                        case EVENT_GRAB_POT:                            if (Unit* slagPotTarget = ObjectAccessor::GetUnit(*me, _slagPotGUID))                            {                                slagPotTarget->EnterVehicle(me, 0);                                events.CancelEvent(EVENT_GRAB_POT);                                events.ScheduleEvent(EVENT_CHANGE_POT, 1000);                            }                            break;                        case EVENT_CHANGE_POT:                            if (Unit* slagPotTarget = ObjectAccessor::GetUnit(*me, _slagPotGUID))                            {                                slagPotTarget->AddAura(SPELL_SLAG_POT, slagPotTarget);                                slagPotTarget->EnterVehicle(me, 1);                                events.CancelEvent(EVENT_CHANGE_POT);                                events.ScheduleEvent(EVENT_END_POT, 10000);                            }                            break;                        case EVENT_END_POT:                            if (Unit* slagPotTarget = ObjectAccessor::GetUnit(*me, _slagPotGUID))                            {                                slagPotTarget->ExitVehicle();                                slagPotTarget = NULL;                                _slagPotGUID = 0;                                events.CancelEvent(EVENT_END_POT);                            }                            break;                        case EVENT_SCORCH:                            DoScriptText(RAND(SAY_SCORCH_1, SAY_SCORCH_2), me);                            if (Unit* target = me->getVictim())                                me->SummonCreature(NPC_GROUND_SCORCH, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 45000);                            DoCast(SPELL_SCORCH);                            events.ScheduleEvent(EVENT_SCORCH, 25000);                            break;                        case EVENT_CONSTRUCT:                            DoScriptText(SAY_SUMMON, me);                            DoSummon(NPC_IRON_CONSTRUCT, ConstructSpawnPosition[urand(0, CONSTRUCT_SPAWN_POINTS - 1)], 30000, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT);                            DoCast(SPELL_STRENGHT);                            DoCast(me, SPELL_ACTIVATE_CONSTRUCT);                            events.ScheduleEvent(EVENT_CONSTRUCT, RAID_MODE(40000, 30000));                            break;                        case EVENT_BERSERK:                            DoCast(me, SPELL_BERSERK, true);                            DoScriptText(SAY_BERSERK, me);                            break;                    }                }                DoMeleeAttackIfReady();            }
开发者ID:Bootz,项目名称:TrilliumEMU,代码行数:79,


示例23: UpdateAI

    void UpdateAI(const uint32 uiDiff)    {        //Return since we have no target        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())            return;        if (m_uiSummonTimer < uiDiff && m_creature->GetHealthPercent() > 21.0f)        {            uint8 uiMaxWraith = urand(3, 4);            for (uint8 i = 0; i < uiMaxWraith; ++i)                m_creature->SummonCreature(NPC_NETHER_WRAITH, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_DEAD_DESPAWN, 0);            DoScriptText(SAY_SUMMON, m_creature);            m_uiSummonTimer = urand(30000, 45000);        }        else            m_uiSummonTimer -= uiDiff;        if (m_uiManaTapTimer < uiDiff)        {            if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0, SPELL_MANA_TAP, SELECT_FLAG_POWER_MANA))            {                if (DoCastSpellIfCan(pTarget, SPELL_MANA_TAP) == CAST_OK)                    m_uiManaTapTimer = urand(14000, 22000);            }        }        else            m_uiManaTapTimer -= uiDiff;        if (m_uiArcaneTorrentTimer < uiDiff)        {            if (DoCastSpellIfCan(m_creature, SPELL_ARCANE_TORRENT) == CAST_OK)                m_uiArcaneTorrentTimer = urand(12000, 18000);        }        else            m_uiArcaneTorrentTimer -= uiDiff;        if (m_uiDominationTimer < uiDiff)        {            if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 1))            {                if (DoCastSpellIfCan(pTarget, SPELL_DOMINATION) == CAST_OK)                {                    DoScriptText(urand(0, 1) ? SAY_DOMINATION_1 : SAY_DOMINATION_2, m_creature);                    m_uiDominationTimer = urand(25000, 30000);                }            }        }        else            m_uiDominationTimer -= uiDiff;        // Only casting if Heroic Mode is used        if (!m_bIsRegularMode)        {            if (m_uiArcaneExplosionTimer < uiDiff)            {                if (DoCastSpellIfCan(m_creature, SPELL_ARCANE_EXPLOSION_H) == CAST_OK)                    m_uiArcaneExplosionTimer = urand(10000, 14000);            }            else                m_uiArcaneExplosionTimer -= uiDiff;        }        if (!m_bIsEnraged && m_creature->GetHealthPercent() < 21.0f)        {            if (DoCastSpellIfCan(m_creature, SPELL_FRENZY) == CAST_OK)            {		        for (GuidList::const_iterator itr = m_lNWraithGUIDList.begin(); itr != m_lNWraithGUIDList.end(); ++itr)                {                    if (Creature* pCreature = m_creature->GetMap()->GetCreature(*itr))                    {                        if (pCreature->isAlive())                        pCreature->ForcedDespawn();                    }                }                m_lNWraithGUIDList.clear();                DoScriptText(SAY_ENRAGE, m_creature);                m_bIsEnraged = true;            }        }        DoMeleeAttackIfReady();    }
开发者ID:Atari007,项目名称:master,代码行数:84,


示例24: UpdateAI

    void UpdateAI(const uint32 uiDiff)    {        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())            return;        if(m_pInstance->m_bSummonAurius == true)        {                        if (m_uiSumAuriusTimer <= uiDiff)            {                // Spawn Aurius in the Slaughter House to engage Baron                if (Creature* pAurius = m_creature->SummonCreature(NPC_AURIUS, 4032.63f, -3362.61f, 115.05f, 1.64f, TEMPSUMMON_DEAD_DESPAWN, 0))                {                                            pAurius->MonsterYell("Rivendare! I come for you!", LANG_UNIVERSAL, nullptr);                    pAurius->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER);                    pAurius->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);                    pAurius->RemoveSplineFlag(SPLINEFLAG_WALKMODE);                    pAurius->AI()->AttackStart(m_creature);                }                                    m_uiSumAuriusTimer = 0;                            m_pInstance->m_bSummonAurius = false;            }            else                m_uiSumAuriusTimer -= uiDiff;                    }                DoCastSpellIfCan(m_creature, SPELL_UNHOLY_AURA, CAST_AURA_NOT_PRESENT);        // Cleave        if (m_uiCleaveTimer <= uiDiff)        {            DoCastSpellIfCan(m_creature->getVictim(), SPELL_CLEAVE);            m_uiCleaveTimer = urand(6000,9000);        }        else            m_uiCleaveTimer -= uiDiff;        // Death Pact        if (m_uiDeathPactTimer)	{            if (m_uiDeathPactTimer <= uiDiff)            {                if (!m_uiSkeletonGUID.empty())                    for(GUIDList::iterator itr = m_uiSkeletonGUID.begin(); itr != m_uiSkeletonGUID.end(); ++itr)                    {                        if (Creature* pSkeleton = m_creature->GetMap()->GetCreature(*itr))                            if (pSkeleton->isAlive() && m_creature->GetHealth() < m_creature->GetMaxHealth())                                m_creature->SetHealth(m_creature->GetHealth()+2000);                    }                m_uiSkeletonGUID.clear();                m_uiDeathPactTimer = 0;            }            else                m_uiDeathPactTimer -= uiDiff;	}        // Mortal Strike        if (m_uiMortalStrikeTimer <= uiDiff)        {            DoCastSpellIfCan(m_creature->getVictim(), SPELL_MORTAL_STRIKE);            m_uiMortalStrikeTimer = urand(5000,10000);        }        else            m_uiMortalStrikeTimer -= uiDiff;        // Shadow Bolt        if (m_uiShadowBoltTimer <= uiDiff)        {            Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0);            DoCastSpellIfCan(pTarget ? pTarget : m_creature->getVictim(), SPELL_SHADOW_BOLT);            m_uiShadowBoltTimer = urand(7000,12000);        }        else            m_uiShadowBoltTimer -= uiDiff;        // Summon Skeletons        if (m_uiSummonSkeletonsTimer <= uiDiff)        {            for(uint32 i = 0; i < sizeof(Skeleton)/sizeof(Locations); ++i)                m_creature->SummonCreature(NPC_MINDLESS_SKELETON, Skeleton[i].x , Skeleton[i].y, Skeleton[i].z, 0, TEMPSUMMON_TIMED_DESPAWN, 14000);            m_uiDeathPactTimer = 12000;            m_uiSummonSkeletonsTimer = urand(25000,35000);        }        else            m_uiSummonSkeletonsTimer -= uiDiff;        DoMeleeAttackIfReady();    }
开发者ID:Phatcat,项目名称:mangos,代码行数:91,


示例25: Initialize

 void Initialize() {     uiDarkOffering = urand(200, 1000); }
开发者ID:Diyvol,项目名称:TrinityCore,代码行数:4,


示例26: JustReachedHome

 void JustReachedHome() {     if (m_instance)         m_instance->SetData(TYPE_ANUBARAK, FAIL);     //Summon Scarab Swarms neutral at random places     for (int i=0; i < 10; i++)         if (Creature* temp = me->SummonCreature(NPC_SCARAB, AnubarakLoc[1].GetPositionX()+urand(0, 50)-25, AnubarakLoc[1].GetPositionY()+urand(0, 50)-25, AnubarakLoc[1].GetPositionZ()))             temp->setFaction(31); }
开发者ID:Jason01ex,项目名称:ZoneLimit,代码行数:9,



注:本文中的urand函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ urandom函数代码示例
C++ uptime函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。