本文整理汇总了C++中RandomUInt函数的典型用法代码示例。如果您正苦于以下问题:C++ RandomUInt函数的具体用法?C++ RandomUInt怎么用?C++ RandomUInt使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RandomUInt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Rand
bool Rand(float chance)
{
int32 val = RandomUInt(10000);
int32 p = int32(chance * 100.0f);
return p >= val;
}
示例2: RandomUInt
void StrandOfTheAncient::PrepareRound()
{
roundprogress = SOTA_ROUND_PREPARATION;
if (BattleRound == 1)
{
Attackers = RandomUInt(1);
if (Attackers == TEAM_ALLIANCE)
Defenders = TEAM_HORDE;
else
Defenders = TEAM_ALLIANCE;
}
else
{
std::swap(Attackers, Defenders);
}
for (uint32 i = 0; i < GATE_COUNT; i++)
{
m_gates[i]->Rebuild();
m_gates[i]->SetFaction(TeamFactions[Defenders]);
}
m_endgate->Rebuild();
m_endgate->SetFaction(TeamFactions[Defenders]);
m_relic->SetFaction(TeamFactions[Attackers]);
for (uint32 i = 0; i < GATE_COUNT; i++)
m_gateTransporters[i]->SetFaction(TeamFactions[Defenders]);
for (uint32 i = 0; i < SOTA_NUM_CANONS; i++)
{
if (canon[i] != NULL)
canon[i]->Despawn(0, 0);
canon[i] = SpawnCreature(27894, CanonLocations[i], TeamFactions[Defenders]);
}
for (uint32 i = 0; i < SOTA_NUM_DOCK_DEMOLISHERS; i++)
{
Creature *c = demolisher[i];
demolisher[i] = SpawnCreature(28781, DemolisherLocations[i], TeamFactions[Attackers]);
if (c != NULL)
c->Despawn(0, 0);
}
for (uint32 i = SOTA_WEST_WS_DEMOLISHER_INDEX; i < SOTA_NUM_DEMOLISHERS; i++)
{
if (demolisher[i] != NULL)
{
demolisher[i]->Despawn(0, 0);
demolisher[i] = NULL;
}
}
SOTACPStates state;
if (Attackers == TEAM_ALLIANCE)
{
state = SOTA_CP_STATE_HORDE_CONTROL;
SetWorldState(WORLDSTATE_SOTA_HORDE_ATTACKER, 0);
SetWorldState(WORLDSTATE_SOTA_ALLIANCE_ATTACKER, 1);
SetWorldState(WORLDSTATE_SOTA_SHOW_ALLY_ROUND, 1);
SetWorldState(WORLDSTATE_SOTA_SHOW_HORDE_ROUND, 0);
SetWorldState(WORLDSTATE_SOTA_SHOW_ALLY_DEFENSE, 0);
SetWorldState(WORLDSTATE_SOTA_SHOW_HORDE_DEFENSE, 1);
SetWorldState(WORLDSTATE_SOTA_SHOW_ALLY_BEACHHEAD1, 1);
SetWorldState(WORLDSTATE_SOTA_SHOW_ALLY_BEACHHEAD2, 1);
SetWorldState(WORLDSTATE_SOTA_SHOW_HORDE_BEACHHEAD1, 0);
SetWorldState(WORLDSTATE_SOTA_SHOW_HORDE_BEACHHEAD2, 0);
}
else
{
state = SOTA_CP_STATE_ALLY_CONTROL;
SetWorldState(WORLDSTATE_SOTA_HORDE_ATTACKER, 1);
SetWorldState(WORLDSTATE_SOTA_ALLIANCE_ATTACKER, 0);
SetWorldState(WORLDSTATE_SOTA_SHOW_ALLY_ROUND, 0);
SetWorldState(WORLDSTATE_SOTA_SHOW_HORDE_ROUND, 1);
SetWorldState(WORLDSTATE_SOTA_SHOW_ALLY_DEFENSE, 1);
SetWorldState(WORLDSTATE_SOTA_SHOW_HORDE_DEFENSE, 0);
SetWorldState(WORLDSTATE_SOTA_SHOW_ALLY_BEACHHEAD1, 0);
SetWorldState(WORLDSTATE_SOTA_SHOW_ALLY_BEACHHEAD2, 0);
SetWorldState(WORLDSTATE_SOTA_SHOW_HORDE_BEACHHEAD1, 1);
SetWorldState(WORLDSTATE_SOTA_SHOW_HORDE_BEACHHEAD2, 1);
}
SpawnControlPoint(SOTA_CONTROL_POINT_EAST_GY, state);
SpawnControlPoint(SOTA_CONTROL_POINT_WEST_GY, state);
SpawnControlPoint(SOTA_CONTROL_POINT_SOUTH_GY, state);
SpawnGraveyard(SOTA_GY_ATTACKER_BEACH, Attackers);
SpawnGraveyard(SOTA_GY_DEFENDER, Defenders);
if (BattleRound == 2)
{
std::lock_guard<std::recursive_mutex> lock(m_mutex);
// Teleport players to their place and cast preparation on them
for (std::set< Player* >::iterator itr = m_players[Attackers].begin(); itr != m_players[Attackers].end(); ++itr)
//.........这里部分代码省略.........
示例3: while
//.........这里部分代码省略.........
if(!tGrp || !tGrp->m_isqueued || !tGrp->GetLeader() || tGrp->GetLeader()->arenaTeam[i - 4] == NULL)
{
itp = m_queuedGroups[i].erase(itp);
continue;
}
++itp;
if( pGroup == tGrp )
continue;
uint32 tRating = tGrp->GetLeader()->arenaTeam[i - 4]->m_stat_rating;
int32 diff = (int32)tRating - (int32)rating;
if(diff < 0)
diff = -diff;
if(diff > (int32)maxRange)
continue;
//Log.Notice("Debug", "EventQueueUpdate added 1 in range arena");
inRangeGroups.push_back(tGrp->GetID());
}
// K, we have a giant list of groups that we could group with, hopefully!
// or not, we can't go on :(
if(!inRangeGroups.size())
continue;
// But if we're here, we can :D
uint32 r = 0;
if( inRangeGroups.size() > 1 )
r = RandomUInt((uint32)inRangeGroups.size() - 1);
Group * pairGroup = objmgr.GetGroupById(inRangeGroups[r]);
if(!pairGroup) continue;
// Now, let's create this rated Arena Match :)
//Log.Notice("Debug", "EventQueueUpdate creating arena");
Arena * arena = (Arena*)CreateInstance(i, LEVEL_GROUP_70);
ArenaTeam *pTeamPair[2];
if(arena)
{
//Log.Notice("Debug", "EventQueueUpdate arena created");
removegroups.push_back(pGroup->GetID());
removegroups.push_back(pairGroup->GetID());
pGroup->m_isqueued = false;
pairGroup->m_isqueued = false;
arena->rated_match = true;
if( pGroup->GetLeader()->arenaTeam[i - 4] != NULL )
{
arena->m_ratedTeams[0] = pGroup->GetLeader()->arenaTeam[i - 4]->m_id;
pTeamPair[0] = pGroup->GetLeader()->arenaTeam[i - 4];
}
else
pTeamPair[0] = NULL;
if( pairGroup->GetLeader()->arenaTeam[i - 4] != NULL )
{
arena->m_ratedTeams[1] = pairGroup->GetLeader()->arenaTeam[i - 4]->m_id;
pTeamPair[1] = pairGroup->GetLeader()->arenaTeam[i - 4];
}
else
示例4: Herald
void WintergraspScript::SpawnWarZones(bool apply)
{
return; // Needs work and more base implementation before it's safe to enable it.
// This one is simple.
if(apply)
{
Herald("Multiple Battle groups have engaged!");
uint32 Entry = 0, percent = 100;
CreatureProto* ctrp = NULL;
for(uint32 i = 0; i < MAX_BATTLE_ZONES; i++)
{
for(uint32 t = 0; t < MAX_UNITS_PER_ZONE/2; t++)
{
float x = Wintergrasp_WarZones[i][t].mX, y = Wintergrasp_WarZones[i][t].mY, z = Wintergrasp_WarZones[i][t].mZ, o = Wintergrasp_WarZones[i][t].mO;
if(x == 0.0f || y == 0.0f || z == 0.0f)
continue;
if(RandomUInt(percent) > (percent/2))
Entry = 00000;
else
Entry = 00000;
percent += 1;
ctrp = CreatureProtoStorage.LookupEntry(Entry);
if(ctrp == NULL)
continue;
Creature* ctr = mgr->CreateCreature(Entry);
if(ctr == NULL)
continue;
ctr->SetMapId(mgr->GetMapId());
ctr->SetInstanceID(mgr->GetInstanceID());
if(ctr->Load(ctrp, mgr->iInstanceMode, x, y, z, o))
{
if(!ctr->CanAddToWorld())
{
ctr->Destruct();
continue;
}
ctr->PushToWorld(mgr);
SpawnInfo* spI = new SpawnInfo();
spI->CreatureEntry = Entry;
spI->RespawnTime = 0;
spI->locationId = i;
spI->SpawnId = t;
spI->m_Spawn = ctr;
m_WarriorPool.insert(spI);
}
else ctr->Destruct();
}
for(uint32 t = MAX_UNITS_PER_ZONE/2; t < MAX_UNITS_PER_ZONE; t++)
{
float x = Wintergrasp_WarZones[i][t].mX, y = Wintergrasp_WarZones[i][t].mY, z = Wintergrasp_WarZones[i][t].mZ, o = Wintergrasp_WarZones[i][t].mO;
if(x == 0.0f || y == 0.0f || z == 0.0f)
continue;
if(RandomUInt(percent) > (percent/2))
Entry = 00000;
else
Entry = 00000;
percent += 1;
ctrp = CreatureProtoStorage.LookupEntry(Entry);
if(ctrp == NULL)
continue;
Creature* ctr = mgr->CreateCreature(Entry);
if(ctr == NULL)
continue;
ctr->SetMapId(mgr->GetMapId());
ctr->SetInstanceID(mgr->GetInstanceID());
if(ctr->Load(ctrp, mgr->iInstanceMode, x, y, z, o))
{
if(!ctr->CanAddToWorld())
{
ctr->Destruct();
continue;
}
ctr->PushToWorld(mgr);
SpawnInfo* spI = new SpawnInfo();
spI->CreatureEntry = Entry;
spI->RespawnTime = 0;
spI->locationId = i;
spI->SpawnId = t;
spI->m_Spawn = ctr;
m_WarriorPool.insert(spI);
}
else ctr->Destruct();
}
//.........这里部分代码省略.........
示例5: if
void LootMgr::PushLoot(StoreLootList *list,Loot * loot, uint32 instance_difficulty)
{
uint32 i;
uint32 count;
for( uint32 x = 0; x < list->count; x++ )
{
if( list->items[x].item.itemproto )// this check is needed until loot DB is fixed
{
float chance;
if( instance_difficulty == INSTANCE_MODE_RAID_25_MAN_HEROIC )
chance = list->items[x].chance2 ;
else if( instance_difficulty == INSTANCE_MODE_RAID_10_MAN_HEROIC )
chance = list->items[x].chance2 / 2.5f;
else if( instance_difficulty == INSTANCE_MODE_RAID_10_MAN )
chance = list->items[x].chance / 2.5f;
// else if( instance_difficulty == INSTANCE_MODE_DUNGEON_HEROIC )
// chance = list->items[x].chance * 2;
else
chance = list->items[x].chance;
if(chance == 0.0f)
continue;
ItemPrototype *itemproto = list->items[x].item.itemproto;
if( RandChance( chance * sWorld.getRate( RATE_DROP0 + itemproto->Quality ) ) )//|| itemproto->Class == ITEM_CLASS_QUEST)
{
if( list->items[x].mincount == list->items[x].maxcount )
count = list->items[x].maxcount;
else
count = RandomUInt(list->items[x].maxcount - list->items[x].mincount) + list->items[x].mincount;
for( i = 0; i < loot->items.size(); ++i )
{
//itemid rand match a already placed item, if item is stackable and unique(stack), increment it, otherwise skips
if((loot->items[i].item.itemproto == list->items[x].item.itemproto) && itemproto->MaxCount && ((loot->items[i].iItemsCount + count) < itemproto->MaxCount))
{
if(itemproto->Unique && ((loot->items[i].iItemsCount+count) < itemproto->Unique))
{
loot->items[i].iItemsCount += count;
break;
}
else if (!itemproto->Unique)
{
loot->items[i].iItemsCount += count;
break;
}
}
}
if( i != loot->items.size() )
continue;
__LootItem itm;
itm.item =list->items[x].item;
itm.iItemsCount = count;
itm.roll = NULL;
itm.passed = false;
itm.ffa_loot = list->items[x].ffa_loot;
itm.has_looted.clear();
if( itemproto->Quality > 1 && itemproto->ContainerSlots == 0 )
{
itm.iRandomProperty=GetRandomProperties( itemproto );
itm.iRandomSuffix=GetRandomSuffix( itemproto );
}
else
{
// save some calls :P
itm.iRandomProperty = NULL;
itm.iRandomSuffix = NULL;
}
loot->items.push_back(itm);
}
}
}
if( loot->items.size() > sWorld.MaxLootListSize )
{
std::vector<__LootItem>::iterator item_to_remove;
std::vector<__LootItem>::iterator itr;
uint32 item_quality;
bool quest_item;
while( loot->items.size() > sWorld.MaxLootListSize )
{
item_to_remove = loot->items.begin();
item_quality = 0;
quest_item = false;
for( itr = loot->items.begin(); itr != loot->items.end(); ++itr )
{
item_quality = (*itr).item.itemproto->Quality;
quest_item = (*itr).item.itemproto->Class == ITEM_CLASS_QUEST;
if( (*item_to_remove).item.itemproto->Quality > item_quality && !quest_item )
{
item_to_remove = itr;
break;
}
}
loot->items.erase( item_to_remove );
//.........这里部分代码省略.........
示例6: RandomUInt
void LootRoll::PlayerRolled(Player *player, uint8 choice)
{
if(m_NeedRolls.find(player->GetLowGUID()) != m_NeedRolls.end() || m_GreedRolls.find(player->GetLowGUID()) != m_GreedRolls.end())
return; // dont allow cheaters
/*
0C BA 0E D0 0E 00 30 F1 Guid
00 00 00 00 slot
CB 26 4B 02 00 00 00 07 guid
7A 16 00 00 item
00 26 81 8E random factor
00 00 00 00 F9 random id
02 roll
00 roll type
4C 2A 05 0F 09 00 30 F1
01 00 00 00
F0 BB 3E 02 00 00 00 07
C8 1C 00 00
60 7B 01 3D
08 04 00 00 F9
02
00
9B 29 05 C9 37 00 30 F1
02 00 00 00
F0 BB 3E 02 00 00 00 07
B2 19 00 00
80 B4 AD 9D
A8 03 00 00 F9
02
00
*/
int roll = RandomUInt(99)+1;
// create packet
WorldPacket data(34);
data.SetOpcode(SMSG_LOOT_ROLL);
data << _guid << _slotid << player->GetGUID();
data << _itemid << random_suffix_factor << random_suffix_id;
//anti ninja - don't need on things you cannot wear
if(choice == LOOT_ROLL_TYPE_NEED)
{
ItemPrototype *ip = ItemPrototypeStorage.LookupEntry( _itemid );
if( player->GetItemInterface()->CanEquipItem( ip, player ) != 0 )
{
choice = LOOT_ROLL_TYPE_GREED;
player->BroadcastMessage("You cannot need on this item.Changing to greed roll");
}
}
if(choice == LOOT_ROLL_TYPE_NEED)
{
player->Event_AchiementCriteria_Received( ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED_ON_LOOT,roll,ACHIEVEMENT_UNUSED_FIELD_VALUE,1,ACHIEVEMENT_EVENT_ACTION_SET);
player->Event_AchiementCriteria_Received( ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED,ACHIEVEMENT_UNUSED_FIELD_VALUE,ACHIEVEMENT_UNUSED_FIELD_VALUE,1,ACHIEVEMENT_EVENT_ACTION_ADD);
m_NeedRolls.insert( std::make_pair(player->GetLowGUID(), roll) );
data << uint8(roll) << uint8(LOOT_ROLL_TYPE_NEED);
}
else if(choice == LOOT_ROLL_TYPE_GREED || choice == LOOT_ROLL_TYPE_DISENCHANT)
{
if( choice == LOOT_ROLL_TYPE_GREED )
{
player->Event_AchiementCriteria_Received( ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED_ON_LOOT,roll,ACHIEVEMENT_UNUSED_FIELD_VALUE,1,ACHIEVEMENT_EVENT_ACTION_SET);
player->Event_AchiementCriteria_Received( ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED,ACHIEVEMENT_UNUSED_FIELD_VALUE,ACHIEVEMENT_UNUSED_FIELD_VALUE,1,ACHIEVEMENT_EVENT_ACTION_ADD);
}
else
{
player->Event_AchiementCriteria_Received( ACHIEVEMENT_CRITERIA_TYPE_ROLL_DISENCHANT,ACHIEVEMENT_UNUSED_FIELD_VALUE,ACHIEVEMENT_UNUSED_FIELD_VALUE,1,ACHIEVEMENT_EVENT_ACTION_ADD);
}
m_GreedRolls.insert( std::make_pair(player->GetLowGUID(), roll) );
data << uint8(roll) << uint8(choice);
}
else
{
m_passRolls.insert( player->GetLowGUID() );
data << uint8(128) << uint8(128);
}
data << uint8(unk_33_1);
if(player->InGroup())
player->GetGroup()->SendPacketToAll(&data);
else
player->GetSession()->SendPacket(&data);
// check for early completion
if(!--_remaining)
{
// kill event early
//sEventMgr.RemoveEvents(this);
Finalize();
}
}
示例7: LOG_ERROR
CBattleground* CBattlegroundManager::CreateInstance(uint32 Type, uint32 LevelGroup)
{
if (bgMaps.find(Type) == bgMaps.end())
{
if (!IS_ARENA(Type))
{
LOG_ERROR("BattlegroundManager", "No map Id is registered for Battleground type %u", Type);
return NULL;
}
}
BattlegroundFactoryMethod cfunc = NULL;
if (!IS_ARENA(Type))
if (bgFactories.find(bgMaps[Type]) != bgFactories.end())
cfunc = bgFactories[bgMaps[Type]];
MapMgr* mgr = NULL;
CBattleground* bg;
bool isWeekend = false;
struct tm tm;
uint32 iid;
time_t t;
int n;
if (IS_ARENA(Type))
{
/* arenas follow a different procedure. */
uint32 arenaMapCount = arenaMaps.size();
if (arenaMapCount == 0)
{
LOG_ERROR("BattlegroundManager", "There are no Arenas registered. Cannot create Arena.");
return NULL;
}
uint32 index = RandomUInt(arenaMapCount - 1);
uint32 mapid = arenaMaps[index];
ArenaFactoryMethod arenaFactory = arenaFactories[index];
uint32 players_per_side;
mgr = sInstanceMgr.CreateBattlegroundInstance(mapid);
if (mgr == NULL)
{
sLog.Error("BattlegroundManager", "Arena CreateInstance() call failed for map %u, type %u, level group %u", mapid, Type, LevelGroup);
return NULL; // Shouldn't happen
}
players_per_side = GetMaximumPlayers(Type);
iid = ++m_maxBattlegroundId[Type];
bg = arenaFactory(mgr, iid, LevelGroup, Type, players_per_side);
mgr->m_battleground = bg;
Log.Notice("BattlegroundManager", "Created arena battleground type %u for level group %u on map %u.", Type, LevelGroup, mapid);
sEventMgr.AddEvent(bg, &CBattleground::EventCreate, EVENT_BATTLEGROUND_QUEUE_UPDATE, 1, 1, 0);
m_instanceLock.Acquire();
m_instances[Type].insert(make_pair(iid, bg));
m_instanceLock.Release();
return bg;
}
if (cfunc == NULL)
{
sLog.Error("BattlegroundManager", "Could not find CreateBattlegroundFunc pointer for type %u level group %u", Type, LevelGroup);
return NULL;
}
t = time(NULL);
#ifdef WIN32
// localtime_s(&tm, &t);
//zack : some luv for vs2k3 compiler
tm = *localtime(&t);
#else
localtime_r(&t, &tm);
#endif
switch (Type)
{
case BATTLEGROUND_WARSONG_GULCH:
n = 0;
break;
case BATTLEGROUND_ARATHI_BASIN:
n = 1;
break;
case BATTLEGROUND_EYE_OF_THE_STORM:
n = 2;
break;
case BATTLEGROUND_STRAND_OF_THE_ANCIENT:
n = 3;
break;
default:
n = 0;
break;
}
if (((tm.tm_yday / 7) % 4) == n)
{
/* Set weekend from Thursday night at midnight until Tuesday morning */
isWeekend = tm.tm_wday >= 5 || tm.tm_wday < 2;
}
/* Create Map Manager */
//.........这里部分代码省略.........
示例8: SpellCast
void SpellCast(float val)
{
if(_unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget())
{
float comulativeperc = 0;
Unit* target = NULL;
for(int i=0;i<nrspells;i++)
{
spells[i].casttime--;
if (m_spellcheck[i])
{
spells[i].casttime = spells[i].cooldown;
target = _unit->GetAIInterface()->GetNextTarget();
switch(spells[i].targettype)
{
case TARGET_SELF:
case TARGET_VARIOUS:
_unit->CastSpell(_unit, spells[i].info, spells[i].instant); break;
case TARGET_ATTACKING:
_unit->CastSpell(target, spells[i].info, spells[i].instant); break;
case TARGET_DESTINATION:
_unit->CastSpellAoF(target->GetPositionX(),target->GetPositionY(),target->GetPositionZ(), spells[i].info, spells[i].instant); break;
}
if (spells[i].info->Id == SAND_BREATH) //Sand Breath has 2 speeches, maybe there is an easier way to do it
{
switch(RandomUInt(1))
{
case 0:
_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Not so fast!");
_unit->PlaySoundToSet(spells[i].soundid);
break;
case 1:
_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Struggle as much as you like!");
_unit->PlaySoundToSet(spells[i].soundid);
break;
}
}
else
{
if (spells[i].speech != "")
{
_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, spells[i].speech.c_str());
_unit->PlaySoundToSet(spells[i].soundid);
}
}
m_spellcheck[i] = false;
return;
}
if ((val > comulativeperc && val <= (comulativeperc + spells[i].perctrigger)) || !spells[i].casttime)
{
_unit->setAttackTimer(spells[i].attackstoptimer, false);
m_spellcheck[i] = true;
}
comulativeperc += spells[i].perctrigger;
}
}
}
示例9: RandomUInt
void LootRoll::PlayerRolled(PlayerInfo* pInfo, uint8 choice)
{
if(m_NeedRolls.find(pInfo->guid) != m_NeedRolls.end() || m_GreedRolls.find(pInfo->guid) != m_GreedRolls.end() || m_DisenchantRolls.find(pInfo->guid) != m_DisenchantRolls.end())
return; // dont allow cheaters
ItemPrototype* proto = ItemPrototypeStorage.LookupEntry(_itemid);
if(proto == NULL)
return; // Shouldn't happen.
mLootLock.Acquire();
int roll = RandomUInt(99)+1;
// create packet
WorldPacket data(SMSG_LOOT_ROLL, 34);
data << _guid << _slotid << uint64(pInfo->guid);
data << _itemid << _randomsuffixid << _randompropertyid;
if(!pInfo->m_loggedInPlayer)
choice = PASS;
bool acceptableroll = true;
switch(choice)
{
case NEED:
{
if(pInfo->m_loggedInPlayer->CanNeedItem(proto))
{
m_NeedRolls.insert( std::make_pair(pInfo->guid, roll) );
data << uint8(roll) << uint8(NEED);
}
else
{
m_passRolls.insert( pInfo->guid );
data << uint8(128) << uint8(128);
}
}break;
case GREED:
{
m_GreedRolls.insert( std::make_pair(pInfo->guid, roll) );
data << uint8(roll) << uint8(GREED);
}break;
case DISENCHANT:
{
if(acceptableroll)
{
if(proto->DisenchantReqSkill < 0)
acceptableroll = false;
else if(pInfo->m_Group)
acceptableroll = pInfo->m_Group->HasAcceptableDisenchanters(proto->DisenchantReqSkill);
else
acceptableroll = (pInfo->m_loggedInPlayer->_HasSkillLine(333) && (pInfo->m_loggedInPlayer->_GetSkillLineCurrent(333) > uint32(proto->DisenchantReqSkill)));
}
if(acceptableroll)
{
m_DisenchantRolls.insert( std::make_pair(pInfo->guid, roll) );
data << uint8(roll) << uint8(DISENCHANT);
}
else
{
m_passRolls.insert( pInfo->guid );
data << uint8(128) << uint8(128);
}
}break;
default: //pass
{
m_passRolls.insert( pInfo->guid );
data << uint8(128) << uint8(128);
}break;
}
data << uint8(0);
if(pInfo->m_Group)
pInfo->m_Group->SendPacketToAll(&data);
else if(pInfo->m_loggedInPlayer)
pInfo->m_loggedInPlayer->GetSession()->SendPacket(&data);
// check for early completion
if(!--_remaining)
{
mLootLock.Release(); // so we can call the other lock in a sec.
// kill event early
//sEventMgr.RemoveEvents(this);
Finalize();
return;
}
mLootLock.Release();
}
示例10: if
//.........这里部分代码省略.........
}
}
else
{
int size = (int)min(tempPlayerVec[0].size(), tempPlayerVec[1].size());
for (int counter = 0; (counter < size) && (bg->IsFull() == false); counter++)
{
AddPlayerToBgTeam(bg, &tempPlayerVec[0], i, j, 0);
AddPlayerToBgTeam(bg, &tempPlayerVec[1], i, j, 1);
}
}
}
}
}
}
}
/* Handle paired arena team joining */
Group* group1, *group2;
uint32 teamids[2] = { 0, 0 };
uint32 avgRating[2] = { 0, 0 };
uint32 n;
list<uint32>::iterator itz;
for (i = BATTLEGROUND_ARENA_2V2; i <= BATTLEGROUND_ARENA_5V5; ++i)
{
if (!forceStart && m_queuedGroups[i].size() < 2) /* got enough to have an arena battle ;P */
{
continue;
}
for (j = 0; j < (uint32)m_queuedGroups[i].size(); j++)
{
group1 = group2 = NULL;
n = RandomUInt((uint32)m_queuedGroups[i].size()) - 1;
for (itz = m_queuedGroups[i].begin(); itz != m_queuedGroups[i].end() && n > 0; ++itz)
--n;
if (itz == m_queuedGroups[i].end())
itz = m_queuedGroups[i].begin();
if (itz == m_queuedGroups[i].end())
{
sLog.Error("BattlegroundMgr", "Internal error at %s:%u", __FILE__, __LINE__);
m_queueLock.Release();
m_instanceLock.Release();
return;
}
group1 = objmgr.GetGroupById(*itz);
if (group1 == NULL)
{
continue;
}
if (forceStart && m_queuedGroups[i].size() == 1)
{
if (CreateArenaType(i, group1, NULL) == -1) return;
m_queuedGroups[i].remove(group1->GetID());
continue;
}
teamids[0] = GetArenaGroupQInfo(group1, i, &avgRating[0]);
list<uint32> possibleGroups;
for (itz = m_queuedGroups[i].begin(); itz != m_queuedGroups[i].end(); ++itz)
{
示例11: assert
void LootMgr::PushLoot(StoreLootList *list,Loot * loot, uint8 difficulty, uint8 team, bool disenchant)
{
uint32 i;
uint32 count;
float nrand = 0;
float ncount = 0;
assert(difficulty < 4);
if (disenchant)
{
nrand = RandomUInt(10000) / 100.0f;
ncount = 0;
}
for( uint32 x = 0; x < list->count; x++ )
{
if( list->items[x].item.itemproto )// this check is needed until loot DB is fixed
{
float chance = list->items[x].chance[difficulty];
if(chance == 0.0f)
continue;
ItemPrototype *itemproto = list->items[x].item.itemproto;
if(!CheckItemFaction(itemproto->Faction, team))
continue;
int lucky;
if (disenchant)
{
lucky = nrand >= ncount && nrand <= (ncount+chance);
ncount+= chance;
}
else
lucky = Rand( chance * sWorld.getRate( RATE_DROP0 + itemproto->Quality ) );
if( lucky )
{
if( list->items[x].mincount == list->items[x].maxcount )
count = list->items[x].maxcount;
else
count = RandomUInt(list->items[x].maxcount - list->items[x].mincount) + list->items[x].mincount;
for( i = 0; i < loot->items.size(); i++ )
{
//itemid rand match a already placed item, if item is stackable and unique(stack), increment it, otherwise skips
if((loot->items[i].item.itemproto == list->items[x].item.itemproto) && itemproto->MaxCount && ((loot->items[i].StackSize + count) < itemproto->MaxCount))
{
if(itemproto->Unique && ((loot->items[i].StackSize+count) < itemproto->Unique))
{
loot->items[i].StackSize += count;
break;
}
else if (!itemproto->Unique)
{
loot->items[i].StackSize += count;
break;
}
}
}
if( i != loot->items.size() )
continue;
__LootItem itm;
itm.item =list->items[x].item;
itm.StackSize = count;
itm.roll = NULLROLL;
itm.passed = false;
itm.ffa_loot = list->items[x].ffa_loot;
itm.has_looted.clear();
if( itemproto->Quality > 1 && itemproto->ContainerSlots == 0 )
{
itm.iRandomProperty=GetRandomProperties( itemproto );
itm.iRandomSuffix=GetRandomSuffix( itemproto );
}
else
{
// save some calls :P
itm.iRandomProperty = NULL;
itm.iRandomSuffix = NULL;
}
loot->items.push_back(itm);
}
}
}
if( loot->items.size() > 16 )
{
std::vector<__LootItem>::iterator item_to_remove;
std::vector<__LootItem>::iterator itr;
uint32 item_quality;
bool quest_item;
while( loot->items.size() > 16 )
{
item_to_remove = loot->items.begin();
item_quality = 0;
quest_item = false;
for( itr = loot->items.begin(); itr != loot->items.end(); itr++ )
//.........这里部分代码省略.........
示例12: CBattleground
StrandOfTheAncients::StrandOfTheAncients(MapMgr* mgr, uint32 id, uint32 lgroup, uint32 t) : CBattleground(mgr,id,lgroup,t)
{
Attackers = RandomUInt(2)-1;
BattleRound = 1;
}
示例13: DoCalculateEffect
int32 DoCalculateEffect(uint32 i, Unit* target, int32 value)
{
return 2 + RandomUInt(2);
}
示例14: switch
void LootMgr::PushLoot(StoreLootList* list, Loot* loot, uint32 type)
{
uint32 i;
uint32 count;
if(type >= NUM_LOOT_TYPES)
return;
for(uint32 x = 0; x < list->count; x++)
{
if(list->items[x].item.itemproto) // this check is needed until loot DB is fixed
{
float chance = 0.0f;
switch(type)
{
case LOOT_NORMAL10:
chance = list->items[x].chance;
break;
case LOOT_NORMAL25:
chance = list->items[x].chance2;
break;
case LOOT_HEROIC10:
chance = list->items[x].chance3;
break;
case LOOT_HEROIC25:
chance = list->items[x].chance4;
break;
}
// drop chance cannot be larger than 100% or smaller than 0%
if(chance <= 0.0f || chance > 100.0f)
continue;
ItemPrototype* itemproto = list->items[x].item.itemproto;
if(Rand(chance * sWorld.getRate(RATE_DROP0 + itemproto->Quality))) //|| itemproto->Class == ITEM_CLASS_QUEST)
{
if(list->items[x].mincount == list->items[x].maxcount)
count = list->items[x].maxcount;
else
count = RandomUInt(list->items[x].maxcount - list->items[x].mincount) + list->items[x].mincount;
for(i = 0; i < loot->items.size(); ++i)
{
//itemid rand match a already placed item, if item is stackable and unique(stack), increment it, otherwise skips
if((loot->items[i].item.itemproto == list->items[x].item.itemproto) && itemproto->MaxCount && ((loot->items[i].iItemsCount + count) < itemproto->MaxCount))
{
if(itemproto->Unique && ((loot->items[i].iItemsCount + count) < itemproto->Unique))
{
loot->items[i].iItemsCount += count;
break;
}
else if(!itemproto->Unique)
{
loot->items[i].iItemsCount += count;
break;
}
}
}
if(i != loot->items.size())
continue;
__LootItem itm;
itm.item = list->items[x].item;
itm.iItemsCount = count;
itm.roll = NULL;
itm.passed = false;
itm.ffa_loot = list->items[x].ffa_loot;
itm.has_looted.clear();
if(itemproto->Quality > 1 && itemproto->ContainerSlots == 0)
{
itm.iRandomProperty = GetRandomProperties(itemproto);
itm.iRandomSuffix = GetRandomSuffix(itemproto);
}
else
{
// save some calls :P
itm.iRandomProperty = NULL;
itm.iRandomSuffix = NULL;
}
loot->items.push_back(itm);
}
}
}
if(loot->items.size() > 16)
{
std::vector<__LootItem>::iterator item_to_remove;
std::vector<__LootItem>::iterator itr;
uint32 item_quality;
bool quest_item;
while(loot->items.size() > 16)
{
item_to_remove = loot->items.begin();
item_quality = 0;
//.........这里部分代码省略.........
示例15: AIUpdate
void AIUpdate()
{
uint32 val = RandomUInt(1000);
SpellCast(val);
}