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 }
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; }
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; }
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); } }
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; }
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); } }
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; }
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); data << uint32((*checkList)[i].driver->Seed); data.append(&(*checkList)[i].driver->SHA[0], 20); data << uint8(m_strIndex++); break; case WARD_CHECK_FILE: sLog->outStaticDebug("%u : WARD_CHECK_FILE", i); data << uint8(m_strIndex++); break; case WARD_CHECK_LUA: sLog->outStaticDebug("%u : WARD_CHECK_LUA", i); data << uint8(m_strIndex++); break; } } data << uint8(m_WardenModuleMap[md5][WARD_CHECK_END] ^ m_seed1); data.hexlike(); data.crypt(&session->m_rc4ServerKey[0], &rc4_crypt); session->SendPacket(&data); }