Exemplo n.º 1
0
void ArathiBasin::EventUpdateResources(uint32 Team)
{
	static uint32 resource_fields[2] = { WORLDSTATE_AB_ALLIANCE_RESOURCES, WORLDSTATE_AB_HORDE_RESOURCES };

	uint32 current_resources = m_resources[Team];
	uint32 current_bases = m_capturedBases[Team];

	if(current_bases>5)
		current_bases=5;

	// figure out how much resources we have to add to that team based on the number of captured bases.
	current_resources += (PointBonusPerUpdate[current_bases]);

	// did it change?
	if(current_resources == m_resources[Team])
		return;

	m_mainLock.Acquire();

	// check for overflow
	if(current_resources > RESOURCES_WINVAL)
		current_resources = RESOURCES_WINVAL;

	m_resources[Team] = current_resources;
	if((current_resources - m_lastHonorGainResources[Team]) >= m_resToGainBH)
	{
		m_lastHonorGainResources[Team] += m_resToGainBH;
		for(set< Player* >::iterator itr = m_players[Team].begin(); itr != m_players[Team].end(); itr++)
		{
			(*itr)->m_bgScore.BonusHonor += m_bonusHonor;
			HonorHandler::AddHonorPointsToPlayer((*itr), m_bonusHonor);
		}
	}

	// update the world states
	m_mapMgr->GetStateManager().UpdateWorldState(resource_fields[Team], current_resources);

	if(current_resources >= RESOURCES_WARNING_THRESHOLD && !m_nearingVictory[Team])
	{
		m_nearingVictory[Team] = true;
		SendChatMessage(Team ? CHAT_MSG_BG_SYSTEM_HORDE : CHAT_MSG_BG_SYSTEM_ALLIANCE, (uint64)0, "The %s has gathered %u resources and is nearing victory!", Team ? "Horde" : "Alliance", current_resources);
		uint32 sound = SOUND_ALLIANCE_BGALMOSTEND - Team;
		PlaySoundToAll(sound);
	}

	// check for winning condition
	if(current_resources == RESOURCES_WINVAL)
	{
		m_ended = true;
		m_losingteam = (Team) ? 0 : 1;
		m_nextPvPUpdateTime = 0;

		sEventMgr.RemoveEvents(this);
		sEventMgr.AddEvent(TO_CBATTLEGROUND(this), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0);
		SendChatMessage( CHAT_MSG_BG_SYSTEM_NEUTRAL, 0, "|cffffff00This battleground will close in 2 minutes.");

		for(uint32 i = 0; i < 2; i++)
		{
			for(set<Player*  >::iterator itr = m_players[i].begin(); itr != m_players[i].end(); itr++)
			{
				(*itr)->Root();

				if( (*itr)->HasFlag(PLAYER_FLAGS, PLAYER_FLAG_AFK) )
					continue;

				if(i == m_losingteam)
				{
					(*itr)->m_bgScore.BonusHonor += m_bonusHonor;
					HonorHandler::AddHonorPointsToPlayer((*itr), m_bonusHonor);
					if((*itr)->fromrandombg)
					{
						(*itr)->m_honorToday += (*itr)->GenerateRBGReward((*itr)->getLevel(),5);
						HonorHandler::RecalculateHonorFields((*itr));
						(*itr)->fromrandombg = false;
					}
				}
				else
				{
					(*itr)->m_bgScore.BonusHonor += 2*m_bonusHonor;
					HonorHandler::AddHonorPointsToPlayer((*itr), 2*m_bonusHonor);
					uint32 diff = abs((int32)(m_resources[i] - m_resources[i ? 0 : 1]));
					(*itr)->GetAchievementInterface()->HandleAchievementCriteriaWinBattleground( m_mapMgr->GetMapId(), diff, ((uint32)UNIXTIME - m_startTime) / 1000, TO_CBATTLEGROUND(this));
					if((*itr)->fromrandombg)
					{
						Player * p = (*itr);
						p->AddArenaPoints(p->randombgwinner == false ? p->GenerateRBGReward(p->getLevel(),25) : p->GenerateRBGReward(p->getLevel(),0));
						p->m_honorToday += p->randombgwinner == false ? p->GenerateRBGReward(p->getLevel(),30) : p->GenerateRBGReward(p->getLevel(),15);
						HonorHandler::RecalculateHonorFields(p);
						p->randombgwinner = true;
						p->fromrandombg = false;
					}
				}
			}
		}
	}

	UpdatePvPData();
	m_mainLock.Release();
}
Exemplo n.º 2
0
bool EyeOfTheStorm::GivePoints(uint32 team, uint32 points)
{
    if(m_ended || !m_started)
        return false;

    //printf("EOTS: Give team %u %u points.\n", team, points);

    m_points[team] += points;

    if( m_points[team] >= m_resourceRewards[team] )
    {
        m_resourceRewards[team] += m_resToGainBH;

        for(set<Player*  >::iterator itx = m_players[team].begin(); itx != m_players[team].end(); itx++)
        {
            Player* plr = (*itx);
            if(!plr) continue;
            (*itx)->m_bgScore.BonusHonor += m_bonusHonor;
            HonorHandler::AddHonorPointsToPlayer( plr, m_bonusHonor );
        }
    }

    if( m_points[team] >= 1600 )
    {
        m_points[team] = 1600;
        m_mapMgr->GetStateManager().UpdateWorldState( WORLDSTATE_EOTS_ALLIANCE_VICTORYPOINTS + team, m_points[team] );

        m_ended = true;
        m_losingteam = (team) ? 0 : 1;
        m_nextPvPUpdateTime = 0;

        sEventMgr.RemoveEvents(this);
        sEventMgr.AddEvent(TO_CBATTLEGROUND(this), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0);
        SendChatMessage( CHAT_MSG_BG_SYSTEM_NEUTRAL, 0, "|cffffff00This battleground will close in 2 minutes.");

        /* add the marks of honor to all players */
        m_mainLock.Acquire();

        for(uint32 i = 0; i < 2; i++)
        {
            for(set<Player*  >::iterator itr = m_players[i].begin(); itr != m_players[i].end(); itr++)
            {
                (*itr)->Root();

                if( (*itr)->HasFlag(PLAYER_FLAGS, PLAYER_FLAG_AFK) )
                    continue;

                // create eye of the storm mark of honor
                uint32 item_count = (i == m_losingteam) ? 1 : 3;

                if( i != m_losingteam )
                {
                    (*itr)->m_bgScore.BonusHonor += 2*m_bonusHonor;
                    HonorHandler::AddHonorPointsToPlayer( (*itr), 2*m_bonusHonor );
                    if((*itr)->fromrandombg)
                    {
                        (*itr)->m_honorToday += (*itr)->GenerateRBGReward((*itr)->getLevel(),5);
                        HonorHandler::RecalculateHonorFields((*itr));
                        (*itr)->fromrandombg = false;
                    }
                }
                else
                {
                    (*itr)->m_bgScore.BonusHonor += m_bonusHonor;
                    HonorHandler::AddHonorPointsToPlayer( (*itr), m_bonusHonor );
                    uint32 diff = abs((int32)(m_points[i] - m_points[i ? 0 : 1]));
                    (*itr)->GetAchievementInterface()->HandleAchievementCriteriaWinBattleground( m_mapMgr->GetMapId(), diff, ((uint32)UNIXTIME - m_startTime) / 1000, TO_CBATTLEGROUND(this));
                    if((*itr)->fromrandombg)
                    {
                        Player * p = (*itr);
                        p->AddArenaPoints(p->randombgwinner == false ? p->GenerateRBGReward(p->getLevel(),25) : p->GenerateRBGReward(p->getLevel(),0));
                        p->m_honorToday += p->randombgwinner == false ? p->GenerateRBGReward(p->getLevel(),30) : p->GenerateRBGReward(p->getLevel(),15);
                        HonorHandler::RecalculateHonorFields(p);
                        p->randombgwinner = true;
                        p->fromrandombg = false;
                    }
                }

                Item* pReward;
                SlotResult res;
                if( ( pReward = (*itr)->GetItemInterface()->FindItemLessMax(EOTS_MARK_ID, item_count, false) ) == NULL )
                {
                    res = (*itr)->GetItemInterface()->FindFreeInventorySlot( ItemPrototypeStorage.LookupEntry(EOTS_MARK_ID) );
                    if( !res.Result )
                    {
                        (*itr)->BroadcastMessage("Could not add EOTS mark. Make sure you have room in your inventory.");
                        continue;
                    }

                    pReward = objmgr.CreateItem(EOTS_MARK_ID, (*itr));
                    pReward->SetUInt32Value(ITEM_FIELD_STACK_COUNT, item_count);
                    pReward->m_isDirty = true;
                    if( !(*itr)->GetItemInterface()->SafeAddItem(pReward, res.ContainerSlot, res.Slot) )
                    {
                        if( !(*itr)->GetItemInterface()->AddItemToFreeSlot(pReward) )
                        {
                            pReward->DeleteMe();
                            pReward = NULLGOB;
                        }
                    }
                    (*itr)->GetSession()->SendItemPushResult(pReward,true,false,true,false,res.ContainerSlot,res.Slot, item_count);
                }
                else
                {
                    pReward->m_isDirty = true;
                    pReward->ModUnsigned32Value(ITEM_FIELD_STACK_COUNT, item_count);

                    res.ContainerSlot = (*itr)->GetItemInterface()->GetBagSlotByGuid(pReward->GetGUID());
                    res.Slot = -1;
                    (*itr)->GetSession()->SendItemPushResult(pReward,true,false,true,true,res.ContainerSlot,res.Slot, item_count);
                }
            }
        }
        UpdatePvPData();
        m_mainLock.Release();
        return true;
    }

    m_mapMgr->GetStateManager().UpdateWorldState( WORLDSTATE_EOTS_ALLIANCE_VICTORYPOINTS + team, m_points[team] );
    return false;
}
Exemplo n.º 3
0
void DayWatcherThread::update_arena()
{
    LogNotice("DayWatcherThread : Running Weekly Arena Point Maintenance...");
    QueryResult* result = CharacterDatabase.Query("SELECT guid, arenaPoints FROM characters");  // this one is a little more intensive
    Player* plr;
    uint32 guid, arenapoints, orig_arenapoints;
    ArenaTeam* team;
    uint32 arenapointsPerTeam[3] = { 0 };
    double X, Y;
    if (result)
    {
        do
        {
            Field* f = result->Fetch();
            guid = f[0].GetUInt32();
            arenapoints = f[1].GetUInt32();
            orig_arenapoints = arenapoints;

            for (uint8 i = 0; i < 3; ++i)
                arenapointsPerTeam[i] = 0;

            // are we in any arena teams?
            for (uint8 i = 0; i < 3; ++i)            // 3 arena team types
            {
                team = objmgr.GetArenaTeamByGuid(guid, i);
                if (team)
                {
                    ArenaTeamMember* member = team->GetMemberByGuid(guid);
                    if (member == NULL || team->m_stat_gamesplayedweek < 10 || ((member->Played_ThisWeek * 100) / team->m_stat_gamesplayedweek < 30))
                        continue;

                    // we're in an arena team of this type!
                    // Source: http://www.wowwiki.com/Arena_point
                    X = (double)team->m_stat_rating;
                    if (X <= 510.0)    // "if X<=510"
                        continue;        // no change
                    else if (X > 510.0 && X <= 1500.0)        // "if 510 < X <= 1500"
                    {
                        Y = (0.22 * X) + 14.0;
                    }
                    else            // "if X > 1500"
                    {
                        // http://eu.wowarmory.com/arena-calculator.xml
                        //              1511.26
                        //   ---------------------------
                        //                   -0.00412*X
                        //    1+1639.28*2.71828

                        double power = ((-0.00412) * X);
                        //if (power < 1.0)
                        //    power = 1.0;

                        double divisor = pow(((double)(2.71828)), power);
                        divisor *= 1639.28;
                        divisor += 1.0;
                        //if (divisor < 1.0)
                        //    divisor = 1.0;

                        Y = 1511.26 / divisor;
                    }

                    // 2v2 teams only earn 70% (Was 60% until 13th March 07) of the arena points, 3v3 teams get 80%, while 5v5 teams get 100% of the arena points.
                    // 2v2 - 76%, 3v3 - 88% as of patch 2.2
                    if (team->m_type == ARENA_TEAM_TYPE_2V2)
                    {
                        Y *= 0.76;
                        Y *= worldConfig.getFloatRate(RATE_ARENAPOINTMULTIPLIER2X);
                    }
                    else if (team->m_type == ARENA_TEAM_TYPE_3V3)
                    {
                        Y *= 0.88;
                        Y *= worldConfig.getFloatRate(RATE_ARENAPOINTMULTIPLIER3X);
                    }
                    else
                    {
                        Y *= worldConfig.getFloatRate(RATE_ARENAPOINTMULTIPLIER5X);
                    }

                    if (Y > 1.0)
                        arenapointsPerTeam[i] += long2int32(double(ceil(Y)));
                }
            }

            arenapointsPerTeam[0] = (uint32)std::max(arenapointsPerTeam[0], arenapointsPerTeam[1]);
            arenapoints += (uint32)std::max(arenapointsPerTeam[0], arenapointsPerTeam[2]);
            if (arenapoints > 5000) arenapoints = 5000;

            if (orig_arenapoints != arenapoints)
            {
                plr = objmgr.GetPlayer(guid);
                if (plr)
                {
                    plr->AddArenaPoints(arenapoints, false);

                    // update visible fields (must be done through an event because of no uint lock
                    sEventMgr.AddEvent(plr, &Player::UpdateArenaPoints, EVENT_PLAYER_UPDATE, 100, 1, 0);

                    sChatHandler.SystemMessage(plr->GetSession(), "Your arena points have been updated! Check your PvP tab!");
                }

                // update in sql
                CharacterDatabase.Execute("UPDATE characters SET arenaPoints = %u WHERE guid = %u", arenapoints, guid);
            }
        }
        while (result->NextRow());
        delete result;
    }

    objmgr.UpdateArenaTeamWeekly();

    last_arena_time = UNIXTIME;
    dupe_tm_pointer(localtime(&last_arena_time), &local_last_arena_time);
    m_dirty = true;
}