• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rand_chance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: rand_chance

uint32 PoolGroup<T>::RollOne(void)
{
    if (!ExplicitlyChanced.empty())                         // First explicitly chanced entries are checked
    {
        float roll = rand_chance();

        for (uint32 i=0; i<ExplicitlyChanced.size(); ++i)
        {
            roll -= ExplicitlyChanced[i].chance;
            if (roll < 0)
                return ExplicitlyChanced[i].guid;
        }
    }
    if (!EqualChanced.empty())
        return EqualChanced[irand(0, EqualChanced.size()-1)].guid;

    return 0;                                               // None found
}
开发者ID:Aemu,项目名称:mangos,代码行数:18,代码来源:PoolHandler.cpp


示例2: GetExplicitDiscoverySpell

uint32 GetExplicitDiscoverySpell(uint32 spellId, Player* player)
{
    // explicit discovery spell chances (always success if case exist)
    // in this case we have both skill and spell
    SkillDiscoveryMap::const_iterator tab = SkillDiscoveryStore.find(int32(spellId));
    if (tab == SkillDiscoveryStore.end())
        return 0;

    SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellId);
    uint32 skillvalue = bounds.first != bounds.second ? player->GetSkillValue(bounds.first->second->skillId) : uint32(0);

    float full_chance = 0;
    for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
        if (item_iter->reqSkillValue <= skillvalue)
            if (!player->HasSpell(item_iter->spellId))
                full_chance += item_iter->chance;

    float rate = full_chance / 100.0f;
    float roll = (float)rand_chance() * rate;                      // roll now in range 0..full_chance

    for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
    {
        if (item_iter->reqSkillValue > skillvalue)
            continue;

        if (player->HasSpell(item_iter->spellId))
            continue;

        if (item_iter->chance > roll)
        {
            // Update skill, not Book of Glyph Mastery
            if (spellId != 64323)
                player->UpdateGatherSkill(SKILL_INSCRIPTION, player->GetPureSkillValue(SKILL_INSCRIPTION), item_iter->reqSkillValue);
            return item_iter->spellId;
        }

        roll -= item_iter->chance;
    }

    return 0;
}
开发者ID:lineagedr,项目名称:azerothcore-wotlk,代码行数:41,代码来源:SkillDiscovery.cpp


示例3: GetItemEnchantMod

uint32 GetItemEnchantMod(uint32 entry)
{
    if (!entry) {
        return 0;
    }

    EnchantmentStore::const_iterator tab = RandomItemEnch.find(entry);

    if (tab == RandomItemEnch.end())
    {
        sLog.outErrorDb("Item RandomProperty id #%u used in `item_template` but it doesn't have records in `item_enchantment_template` table.", entry);
        return 0;
    }

    double dRoll = rand_chance();
    float fCount = 0;

    for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter)
    {
        fCount += ench_iter->chance;

        if (fCount > dRoll) {
            return ench_iter->ench;
        }
    }

    // we could get here only if sum of all enchantment chances is lower than 100%
    dRoll = (irand(0, (int)floor(fCount * 100) + 1)) / 100;
    fCount = 0;

    for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter)
    {
        fCount += ench_iter->chance;

        if (fCount > dRoll) {
            return ench_iter->ench;
        }
    }

    return 0;
}
开发者ID:43094361,项目名称:server,代码行数:41,代码来源:ItemEnchantmentMgr.cpp


示例4: HandleGMResponseResolve

void WorldSession::HandleGMResponseResolve(WorldPacket& /*recvPacket*/)
{
    // empty packet
    if (GmTicket* ticket = sTicketMgr->GetTicketByPlayer(GetPlayer()->GetGUID()))
    {
        uint8 getSurvey = 0;
        if (float(rand_chance()) < sWorld->getFloatConfig(CONFIG_CHANCE_OF_GM_SURVEY))
            getSurvey = 1;

        WorldPacket data(SMSG_GM_RESPONSE_STATUS_UPDATE, 4);
        data << uint8(getSurvey);
        SendPacket(&data);

        WorldPacket data2(SMSG_GM_TICKET_DELETE_TICKET, 4);
        data2 << uint32(GMTICKET_RESPONSE_TICKET_DELETED);
        SendPacket(&data2);

        sTicketMgr->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID());
        sTicketMgr->SendTicket(this, NULL);
    }
}
开发者ID:CATACLYSMDEV,项目名称:JadeCore-5.4.8-18291--dev-,代码行数:21,代码来源:TicketHandler.cpp


示例5: GetItemEnchantMod

uint32 GetItemEnchantMod(int32 entry, uint32 type)
{
    if (!entry)
        return 0;

    if (entry == -1)
        return 0;

    EnchantmentStore::const_iterator tab = type == ENCHANTMENT_RANDOM_PROPERTY ? RandomPropertyItemEnch.find(entry) : RandomSuffixItemEnch.find(entry) ;
    if (tab == (type == ENCHANTMENT_RANDOM_PROPERTY ? RandomPropertyItemEnch.end() : RandomSuffixItemEnch.end()))
    {
        sLog->outError(LOG_FILTER_SQL, "Item RandomProperty / RandomSuffix id #%u used in `item_template` but it does not have records in `item_enchantment_template` table.", entry);
        return 0;
    }

    double dRoll = rand_chance();
    float fCount = 0;

    for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter)
    {
        fCount += ench_iter->chance;

        if (fCount > dRoll)
            return ench_iter->ench;
    }

    //we could get here only if sum of all enchantment chances is lower than 100%
    dRoll = (irand(0, (int)floor(fCount * 100) + 1)) / 100;
    fCount = 0;

    for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter)
    {
        fCount += ench_iter->chance;

        if (fCount > dRoll)
            return ench_iter->ench;
    }

    return 0;
}
开发者ID:AwkwardDev,项目名称:MistCore,代码行数:40,代码来源:ItemEnchantmentMgr.cpp


示例6: HandleGMResponseResolve

void WorldSession::HandleGMResponseResolve(WorldPacket& /*recvPacket*/)
{
    // empty packet
    GM_Ticket* ticket = sTicketMgr->GetGMTicketByPlayer(GetPlayer()->GetGUID());

    if (ticket)
    {
        uint8 getSurvey = 0;
        if ((float)rand_chance() < sWorld->getFloatConfig(CONFIG_CHANCE_OF_GM_SURVEY))
            getSurvey = 1;

        WorldPacket data(SMSG_GMRESPONSE_STATUS_UPDATE, 4);
        data << uint8(getSurvey);
        SendPacket(&data);

        WorldPacket data2(SMSG_GMTICKET_DELETETICKET, 4);
        data2 << uint32(GMTICKET_RESPONSE_TICKET_DELETED);
        SendPacket(&data2);
        sTicketMgr->RemoveGMTicket(ticket, GetPlayer()->GetGUID(), true);
        SendGMTicketGetTicket(GMTICKET_STATUS_DEFAULT, NULL);
    }
}
开发者ID:OoRyseoO,项目名称:StarGateEmu,代码行数:22,代码来源:TicketHandler.cpp


示例7: GetExplicitDiscoverySpell

uint32 GetExplicitDiscoverySpell(uint32 spellId, Player* player)
{
    // explicit discovery spell chances (always success if case exist)
    // in this case we have both skill and spell
    SkillDiscoveryMap::const_iterator tab = SkillDiscoveryStore.find(spellId);
    if (tab == SkillDiscoveryStore.end())
        return 0;

    SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spellId);
    SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spellId);
    uint32 skillvalue = lower != upper ? player->GetSkillValue(lower->second->skillId) : 0;

    float full_chance = 0;
    for(SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
        if (item_iter->reqSkillValue <= skillvalue)
            if (!player->HasSpell(item_iter->spellId))
                full_chance += item_iter->chance;

    float rate = full_chance / 100.0f;
    float roll = rand_chance() * rate;                      // roll now in range 0..full_chance

    for(SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
    {
        if (item_iter->reqSkillValue > skillvalue)
            continue;

        if (player->HasSpell(item_iter->spellId))
            continue;

        if (item_iter->chance > roll)
            return item_iter->spellId;

        roll -= item_iter->chance;
    }

    return 0;
}
开发者ID:Attractivee,项目名称:dfteam,代码行数:37,代码来源:SkillDiscovery.cpp


示例8: data

void WardenMgr::SendCheatCheck(WorldSession* const session)
{
    sLog->outStaticDebug("Wardend::BuildCheatCheck(%u, *pkt)", session->GetAccountId());

    std::string md5 = session->m_WardenModule;
    if (!session->m_WardenClientChecks)
    {
        session->m_WardenClientChecks = new WardenClientCheckList;
    }
    // Type cast and get a shorter name
    WardenClientCheckList* checkList = (WardenClientCheckList*)session->m_WardenClientChecks;

    checkList->clear();
    // Get the Seed 1st byte for the xoring
    uint8 m_seed1 = session->m_wardenSeed[0];
    sLog->outStaticDebug("Seed byte: 0x%02X, end byte: 0x%02X", m_seed1, m_WardenModuleMap[md5][WARD_CHECK_END]);

    WorldPacket data( SMSG_WARDEN_DATA, 300 ); // Guess size
    data << uint8(WARDS_CHEAT_CHECK);

    // Rand a number of checks between 4 and 8 checks + the first time check + end packet
    uint8 nbChecks = urand(4, 8);
    checkList->resize(nbChecks);

    for (uint8 i=0; i<nbChecks; ++i)
    {
        // We select one based on the ratio
        float mRand = (float)rand_chance();
        if (mRand < WCHECK_PAGE2_RATIO)                 // size 29, no string both page1 and page2 tests
        {
            (*checkList)[i].check = urand(0, 1) ? WARD_CHECK_PAGE1 : WARD_CHECK_PAGE2;
            (*checkList)[i].page = GetRandPageCheck();
        }
        else if (mRand < WCHECK_MEMORY_RATIO)           // size 6, possible string
        {
            (*checkList)[i].check = WARD_CHECK_MEMORY;
            (*checkList)[i].mem = GetRandMemCheck();
            if ((*checkList)[i].mem->String.length())   // add 1 for the uint8 str length
            {
                data << uint8((*checkList)[i].mem->String.length());
                data.append((*checkList)[i].mem->String.c_str(), (*checkList)[i].mem->String.length());
                sLog->outStaticDebug("Mem str %s, len %u", (*checkList)[i].mem->String.c_str(), (*checkList)[i].mem->String.length());
            }
        }
        else if (mRand < WCHECK_DRIVER_RATIO)
        {
            (*checkList)[i].check = WARD_CHECK_DRIVER;  // size 25 + string
            (*checkList)[i].driver = GetRandDriverCheck();
            data << uint8((*checkList)[i].driver->String.length());
            data.append((*checkList)[i].driver->String.c_str(), (*checkList)[i].driver->String.length());
            sLog->outStaticDebug("Driver str %s, len %u", (*checkList)[i].driver->String.c_str(), (*checkList)[i].driver->String.length());
        }
        else if (mRand < WCHECK_FILE_RATIO)
        {
            (*checkList)[i].check = WARD_CHECK_FILE;    // size 1 + string
            (*checkList)[i].file = GetRandFileCheck();
            data << uint8((*checkList)[i].file->String.length());
            data.append((*checkList)[i].file->String.c_str(), (*checkList)[i].file->String.length());
            sLog->outStaticDebug("File str %s, len %u", (*checkList)[i].file->String.c_str(), (*checkList)[i].file->String.length());
        }
        else
        {
            (*checkList)[i].check = WARD_CHECK_LUA;     // size 1 + string
            (*checkList)[i].lua = GetRandLuaCheck();
            data << uint8((*checkList)[i].lua->String.length());
            data.append((*checkList)[i].lua->String.c_str(), (*checkList)[i].lua->String.length());
            sLog->outStaticDebug("Lua str %s, len %u", (*checkList)[i].lua->String.c_str(), (*checkList)[i].lua->String.length());
        }
    }
    // strings terminator
    data << uint8(0);
    // We first add a timing check
    data << uint8(m_WardenModuleMap[md5][WARD_CHECK_TIMING] ^ m_seed1);
    // Finaly put the other checks
    uint8 m_strIndex = 1;
    sLog->outStaticDebug("Preparing %u checks", nbChecks);
    for (uint8 i=0; i<nbChecks; ++i)
    {
        data << uint8(m_WardenModuleMap[md5][(*checkList)[i].check] ^ m_seed1);
        switch ((*checkList)[i].check)
        {
            case WARD_CHECK_PAGE1:
            case WARD_CHECK_PAGE2:
                sLog->outStaticDebug("%u : %s", i, (*checkList)[i].check == WARD_CHECK_PAGE1 ? "WARD_CHECK_PAGE1" : "WARD_CHECK_PAGE2");
                data << uint32((*checkList)[i].page->Seed);
                data.append(&(*checkList)[i].page->SHA[0], 20);
                data << uint32((*checkList)[i].page->Offset);
                data << uint8((*checkList)[i].page->Length);
                break;
            case WARD_CHECK_MEMORY:
                sLog->outStaticDebug("%u : WARD_CHECK_MEMORY", i);
                if ((*checkList)[i].mem->String.length())
                    data << uint8(m_strIndex++);
                else
                    data << uint8(0);
                data << uint32((*checkList)[i].mem->Offset);
                data << uint8((*checkList)[i].mem->Length);
                break;
            case WARD_CHECK_DRIVER:
                sLog->outStaticDebug("%u : WARD_CHECK_DRIVER", i);
//.........这里部分代码省略.........
开发者ID:Demonid,项目名称:shadowhack3-public,代码行数:101,代码来源:WardenMgr.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rand_int函数代码示例发布时间:2022-05-30
下一篇:
C++ rand_bytes函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap