Beispiel #1
0
uint32 Item::RepairItemCost()
{
    uint32 ilevel = m_itemProto->ItemLevel;
    if(ilevel <= 0)
        ilevel = 1;
    DurabilityCostsEntry* dcosts = dbcDurabilityCosts.LookupEntryForced(ilevel);
    if(dcosts == NULL)
    {
        //dcosts->itemlevel = 1;
        LOG_ERROR("Repair: Unknown item level (%u)", dcosts);
        return 0;
    }

    DurabilityQualityEntry* dquality = dbcDurabilityQuality.LookupEntryForced((m_itemProto->Quality + 1) * 2);
    if(dquality == NULL)
    {
        //dquality->quality_modifier = 4;
        LOG_ERROR("Repair: Unknown item quality (%u)", dquality);
        return 0;
    }

    uint32 dmodifier = dcosts->modifier[ m_itemProto->Class == ITEM_CLASS_WEAPON ? m_itemProto->SubClass : m_itemProto->SubClass + 21 ];
    uint32 cost = long2int32((GetDurabilityMax() - GetDurability()) * dmodifier * double(dquality->quality_modifier));
    return cost * 4;
}
Beispiel #2
0
uint32 c_GetNanoSeconds(uint64 t1, uint64 t2)
{
	LARGE_INTEGER li;
	double val;
	QueryPerformanceFrequency( &li );
	val = double( t1 - t2 ) * 1000000;
	val /= li.QuadPart;
    return long2int32( val );	
}
Beispiel #3
0
uint32 Item::GenerateRandomSuffixFactor( ItemPrototype* m_itemProto )
{
	double value;

	if( m_itemProto->Class == ITEM_CLASS_ARMOR && m_itemProto->Quality > ITEM_QUALITY_UNCOMMON_GREEN )
		value = SuffixMods[m_itemProto->InventoryType] * 1.24;
	else
		value = SuffixMods[m_itemProto->InventoryType];

	value = ( value * double( m_itemProto->ItemLevel ) ) + 0.5;
	return long2int32( value );
}
Beispiel #4
0
uint32 Item::RepairItemCost()
{
	DurabilityCostsEntry * dcosts = dbcDurabilityCosts.LookupEntry( m_itemProto->ItemLevel );
	if( dcosts == NULL )
	{
		sLog.outError("Repair: Unknown item level (%u)", dcosts);
		return 0;
	}

	DurabilityQualityEntry * dquality = dbcDurabilityQuality.LookupEntry( ( m_itemProto->Quality + 1 ) * 2);
	if( dquality == NULL )
	{
		sLog.outError("Repair: Unknown item quality (%u)", dquality);
		return 0;
	}

	uint32 dmodifier = dcosts->modifier[ m_itemProto->Class == ITEM_CLASS_WEAPON ? m_itemProto->SubClass : m_itemProto->SubClass + 21 ];
	uint32 cost = long2int32( ( GetDurabilityMax() - GetDurability() ) * dmodifier * double( dquality->quality_modifier ) );
	return cost;
}
Beispiel #5
0
uint32 Arena::CalcDeltaRating(uint32 oldRating, uint32 opponentRating, bool outcome)
{
	// ---- Elo Rating System ----
	// Expected Chance to Win for Team A vs Team B
	//                     1
	// -------------------------------------------
	//                   (PB - PA)/400
	//              1 + 10

	double power = (int)(opponentRating - oldRating) / 400.0f;
	double divisor = pow(((double)(10.0)), power);
	divisor += 1.0;

	double winChance = 1.0 / divisor;

	// New Rating Calculation via Elo
	// New Rating = Old Rating + K * (outcome - Expected Win Chance)
	// outcome = 1 for a win and 0 for a loss (0.5 for a draw ... but we cant have that)
	// K is the maximum possible change
	// Through investigation, K was estimated to be 32 (same as chess)
	double multiplier = (outcome ? 1.0 : 0.0) - winChance;
	return long2int32(32.0 * multiplier);
}
Beispiel #6
0
void DayWatcherThread::update_arena()
{
    Log.Notice("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 (uint32 i = 0; i < 3; ++i)
                arenapointsPerTeam[i] = 0;

            /* are we in any arena teams? */
            for (uint32 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 *= sWorld.getRate(RATE_ARENAPOINTMULTIPLIER2X);
                    }
                    else if (team->m_type == ARENA_TEAM_TYPE_3V3)
                    {
                        Y *= 0.88;
                        Y *= sWorld.getRate(RATE_ARENAPOINTMULTIPLIER3X);
                    }
                    else
                    {
                        Y *= sWorld.getRate(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);

                    /* send a little message :> */
                    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;
}
Beispiel #7
0
bool Creature::Load(CreatureSpawn *spawn, uint32 mode, MapInfo *info)
{
	m_spawn = spawn;
	proto = CreatureProtoStorage.LookupEntry(spawn->entry);
	if(!proto)
		return false;
	creature_info = CreatureNameStorage.LookupEntry(spawn->entry);
	if(!creature_info)
		return false;
	
	spawnid = spawn->id;

	m_walkSpeed = m_base_walkSpeed = proto->walk_speed; //set speeds
	m_runSpeed = m_base_runSpeed = proto->run_speed; //set speeds
	m_flySpeed = proto->fly_speed;

	//Set fields
	SetUInt32Value(OBJECT_FIELD_ENTRY,proto->Id);
	SetFloatValue(OBJECT_FIELD_SCALE_X,proto->Scale);
	
	//SetUInt32Value(UNIT_FIELD_HEALTH, (mode ? long2int32(proto->Health * 1.5)  : proto->Health));
	//SetUInt32Value(UNIT_FIELD_BASE_HEALTH, (mode ? long2int32(proto->Health * 1.5)  : proto->Health));
	//SetUInt32Value(UNIT_FIELD_MAXHEALTH, (mode ? long2int32(proto->Health * 1.5)  : proto->Health));
	uint32 health = proto->MinHealth + RandomUInt(proto->MaxHealth - proto->MinHealth);
	if(mode)
		health = long2int32(double(health) * 1.5);
	SetUInt32Value(UNIT_FIELD_HEALTH, health);
	SetUInt32Value(UNIT_FIELD_MAXHEALTH, health);
	SetUInt32Value(UNIT_FIELD_BASE_HEALTH, health);

	SetUInt32Value(UNIT_FIELD_POWER1,proto->Mana);
	SetUInt32Value(UNIT_FIELD_MAXPOWER1,proto->Mana);
	SetUInt32Value(UNIT_FIELD_BASE_MANA,proto->Mana);
	
	// Whee, thank you blizz, I love patch 2.2! Later on, we can randomize male/female mobs! xD
	// Determine gender (for voices)
	//if(spawn->displayid != creature_info->Male_DisplayID)
	//	setGender(1);   // Female
	
	uint32 model;
	uint32 gender = creature_info->GenerateModelId(&model);
	setGender(gender);

	SetUInt32Value(UNIT_FIELD_DISPLAYID,model);
	SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID,model);
	SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,proto->MountedDisplayID);

    //SetUInt32Value(UNIT_FIELD_LEVEL, (mode ? proto->Level + (info ? info->lvl_mod_a : 0) : proto->Level));
	SetUInt32Value(UNIT_FIELD_LEVEL, proto->MinLevel + (RandomUInt(proto->MaxLevel - proto->MinLevel)));
	if(mode && info)
		ModUnsigned32Value(UNIT_FIELD_LEVEL, info->lvl_mod_a);

	for(uint32 i = 0; i < 7; ++i)
		SetUInt32Value(UNIT_FIELD_RESISTANCES+i,proto->Resistances[i]);

	SetUInt32Value(UNIT_FIELD_BASEATTACKTIME,proto->AttackTime);
	SetFloatValue(UNIT_FIELD_MINDAMAGE, (mode ? proto->MinDamage * 1.5f  : proto->MinDamage));
	SetFloatValue(UNIT_FIELD_MAXDAMAGE, (mode ? proto->MaxDamage * 1.5f  : proto->MaxDamage));

	SetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME,proto->RangedAttackTime);
	SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE,proto->RangedMinDamage);
	SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE,proto->RangedMaxDamage);

	SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, proto->Item1SlotDisplay);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, proto->Item2SlotDisplay);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, proto->Item3SlotDisplay);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO, proto->Item1Info1);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_01, proto->Item1Info2);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_02, proto->Item2Info1);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_03, proto->Item2Info2);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_04, proto->Item3Info1);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_05, proto->Item3Info2);

	SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, spawn->factionid);
	SetUInt32Value(UNIT_FIELD_FLAGS, spawn->flags);
	SetUInt32Value(UNIT_NPC_EMOTESTATE, spawn->emote_state);
	SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, proto->BoundingRadius);
	SetFloatValue(UNIT_FIELD_COMBATREACH, proto->CombatReach);
	original_emotestate = spawn->emote_state;
	// set position
	m_position.ChangeCoords( spawn->x, spawn->y, spawn->z, spawn->o );
	m_spawnLocation.ChangeCoords(spawn->x, spawn->y, spawn->z, spawn->o);
	m_aiInterface->setMoveType(spawn->movetype);	
	m_aiInterface->m_waypoints = objmgr.GetWayPointMap(spawn->id);

	m_faction = dbcFactionTemplate.LookupEntry(spawn->factionid);
	if(m_faction)
	{
		m_factionDBC = dbcFaction.LookupEntry(m_faction->Faction);
		// not a neutral creature
		if(!(m_factionDBC->RepListId == -1 && m_faction->HostileMask == 0 && m_faction->FriendlyMask == 0))
		{
			GetAIInterface()->m_canCallForHelp = true;
		}
	}


//SETUP NPC FLAGS
	SetUInt32Value(UNIT_NPC_FLAGS,proto->NPCFLags);

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR ) )
		m_SellItems = objmgr.GetVendorList(GetEntry());

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER ) )
		_LoadQuests();

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TAXIVENDOR) )
		m_TaxiNode = sTaxiMgr.GetNearestTaxiNode( m_position.x, m_position.y, m_position.z, GetMapId() );

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER) || HasFlag(UNIT_NPC_FLAGS,UNIT_NPC_FLAG_TRAINER_PROF))
		mTrainer = objmgr.GetTrainer(GetEntry());

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER ) )
		auctionHouse = sAuctionMgr.GetAuctionHouse(GetEntry());

//NPC FLAGS
	 m_aiInterface->m_waypoints=objmgr.GetWayPointMap(spawn->id);

	//load resistances
	for(uint32 x=0;x<7;x++)
		BaseResistance[x]=GetUInt32Value(UNIT_FIELD_RESISTANCES+x);
	for(uint32 x=0;x<5;x++)
		BaseStats[x]=GetUInt32Value(UNIT_FIELD_STAT0+x);

	BaseDamage[0]=GetFloatValue(UNIT_FIELD_MINDAMAGE);
	BaseDamage[1]=GetFloatValue(UNIT_FIELD_MAXDAMAGE);
	BaseOffhandDamage[0]=GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE);
	BaseOffhandDamage[1]=GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE);
	BaseRangedDamage[0]=GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE);
	BaseRangedDamage[1]=GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE);
	BaseAttackType=proto->AttackType;

	SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f);   // better set this one
	SetUInt32Value(UNIT_FIELD_BYTES_0, spawn->bytes);
	SetUInt32Value(UNIT_FIELD_BYTES_2, spawn->bytes2);

////////////AI
	
	// kek
	for(list<AI_Spell*>::iterator itr = proto->spells.begin(); itr != proto->spells.end(); ++itr)
	{
		m_aiInterface->addSpellToList(*itr);
	}
	//m_aiInterface->m_canCallForHelp = proto->m_canCallForHelp;
	//m_aiInterface->m_CallForHelpHealth = proto->m_callForHelpHealth;
	m_aiInterface->m_canFlee = proto->m_canFlee;
	m_aiInterface->m_FleeHealth = proto->m_fleeHealth;
	m_aiInterface->m_FleeDuration = proto->m_fleeDuration;

	//these fields are always 0 in db
	GetAIInterface()->setMoveType(0);
	GetAIInterface()->setMoveRunFlag(0);
	
	// load formation data
	if( spawn->form != NULL )
	{
		m_aiInterface->m_formationLinkSqlId = spawn->form->fol;
		m_aiInterface->m_formationFollowDistance = spawn->form->dist;
		m_aiInterface->m_formationFollowAngle = spawn->form->ang;
	}
	else
	{
		m_aiInterface->m_formationLinkSqlId = 0;
		m_aiInterface->m_formationFollowDistance = 0;
		m_aiInterface->m_formationFollowAngle = 0;
	}

//////////////AI

	myFamily = dbcCreatureFamily.LookupEntry(creature_info->Family);

	
// PLACE FOR DIRTY FIX BASTARDS
	// HACK! set call for help on civ health @ 100%
	if(creature_info->Civilian >= 1)
		m_aiInterface->m_CallForHelpHealth = 100;
 
 //HACK!
	if(m_uint32Values[UNIT_FIELD_DISPLAYID] == 17743 ||
		m_uint32Values[UNIT_FIELD_DISPLAYID] == 20242 ||
		m_uint32Values[UNIT_FIELD_DISPLAYID] == 15435 ||
		(creature_info->Family == UNIT_TYPE_MISC))
	{
		m_useAI = false;
	}

	/* more hacks! */
	if(proto->Mana != 0)
		SetPowerType(POWER_TYPE_MANA);
	else
		SetPowerType(0);

	has_combat_text = objmgr.HasMonsterSay(GetEntry(), MONSTER_SAY_EVENT_ENTER_COMBAT);
	has_waypoint_text = objmgr.HasMonsterSay(GetEntry(), MONSTER_SAY_EVENT_RANDOM_WAYPOINT);
	m_aiInterface->m_isGuard = isGuard(GetEntry());

	m_aiInterface->getMoveFlags();

	/* creature death state */
	if(proto->death_state == 1)
	{
		uint32 newhealth = m_uint32Values[UNIT_FIELD_HEALTH] / 100;
		if(!newhealth)
			newhealth = 1;
		SetUInt32Value(UNIT_FIELD_HEALTH, 1);
		m_limbostate = true;
		bInvincible = true;
		SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_STATE_DEAD);
	}
	m_invisFlag = proto->invisibility_type;
	if( spawn->stand_state )
		SetStandState( (uint8)spawn->stand_state );

	return true;
}
void DayWatcherThread::update_arena()
{
	Log.Notice("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;
	PlayerInfo * inf;
	uint32 arenapointsPerTeam[3] = {0};
	uint32 best_arenateams[3] = {0};
	uint32 best_arenateam_rating[3] = {0};
	double X, Y;
	if(result)
	{
		do
		{
			Field * f = result->Fetch();
			guid = f[0].GetUInt32();

			inf = objmgr.GetPlayerInfo(guid);
			if( inf == NULL )
				continue;

			arenapoints = f[1].GetUInt32();
			orig_arenapoints = arenapoints;

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

			/* are we in any arena teams? */
			for(uint32 i = 0; i < 3; ++i)			// 3 arena team types
			{
				team = objmgr.GetArenaTeamByGuid(guid, i);
				if(team)
				{
					//required for achievements
					if( team->m_type < 3 && team->m_stat_rating > best_arenateam_rating[ team->m_type ] )
					{
						best_arenateam_rating[ team->m_type ] = team->m_stat_rating;
						best_arenateams[ team->m_type ] = guid;
					}
					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 *= sWorld.getRate(RATE_ARENAPOINTMULTIPLIER2X);
					}
					else if(team->m_type == ARENA_TEAM_TYPE_3V3)
					{
						Y *= 0.88;
						Y *= sWorld.getRate(RATE_ARENAPOINTMULTIPLIER3X);
					}
					else
					{
						Y *= sWorld.getRate(RATE_ARENAPOINTMULTIPLIER5X);
					}
					
					if(Y > 1.0)
						arenapointsPerTeam[i] += long2int32(double(ceil(Y)));
				}
			}

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

			if(orig_arenapoints != arenapoints)
			{
				plr = objmgr.GetPlayer(guid);
				if(plr && plr->deleted == OBJ_AVAILABLE )
				{
					plr->m_arenaPoints = arenapoints;
					
					/* update visible fields (must be done through an event because of no uint lock */
					sEventMgr.AddEvent(plr, &Player::RecalculateHonor, EVENT_PLAYER_UPDATE, 100, 1, 0);
	
					/* send a little message :> */
					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;
		result = NULL;
	}

	objmgr.UpdateArenaTeamWeekly();

	for(uint32 i = 0; i < 3; ++i)			// 3 arena team types
	{
		team = objmgr.GetArenaTeamByGuid(best_arenateams[ i ], i);
		if(team)
		{
			for(uint32 j=0;j<team->m_slots;j++)
				if( team->GetMemberBySlot(j) )
				{
					ArenaTeamMember *member = team->GetMemberBySlot(j);
					if( member->Info != NULL && member->Info->m_loggedInPlayer )
					{
						if( i == 0 )
							member->Info->m_loggedInPlayer->Event_Achiement_Received(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_TEAM_RATING,2,ACHIEVEMENT_UNUSED_FIELD_VALUE,1,ACHIEVEMENT_EVENT_ACTION_SET);
						if( i == 1 )
							member->Info->m_loggedInPlayer->Event_Achiement_Received(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_TEAM_RATING,3,ACHIEVEMENT_UNUSED_FIELD_VALUE,1,ACHIEVEMENT_EVENT_ACTION_SET);
						if( i == 2 )
							member->Info->m_loggedInPlayer->Event_Achiement_Received(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_TEAM_RATING,5,ACHIEVEMENT_UNUSED_FIELD_VALUE,1,ACHIEVEMENT_EVENT_ACTION_SET);
					}
				}
		}
	}
	//===========================================================================
	last_arena_time = UNIXTIME;
	m_dirty = true;
}
Beispiel #9
0
void Arena::Finish()
{
	m_ended = true;
	m_nextPvPUpdateTime = 0;
	UpdatePvPData();
	PlaySoundToAll(m_winningteam ? SOUND_ALLIANCEWINS : SOUND_HORDEWINS);

	sEventMgr.RemoveEvents(this, EVENT_BATTLEGROUND_CLOSE);
	sEventMgr.AddEvent(((CBattleground*)this), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0);

	/* update arena team stats */
	if(rated_match)
	{
		ArenaTeam *teams[2];
		teams[0] = objmgr.GetArenaTeamById(inscribe_teams[0]);
		teams[1] = objmgr.GetArenaTeamById(inscribe_teams[1]);

		if ( teams[0] == NULL || teams[1] == NULL )
			return;

		for (uint32 i = 0; i < 2; ++i)
		{
			uint32 j = i ? 0 : 1; // opposing side
			bool outcome;

			outcome = (i == m_winningteam);

			double power = (int)( teams[j]->m_stat_rating - teams[i]->m_stat_rating ) / 400.0f;
			double divisor = pow(((double)(10.0)), power);
			divisor += 1.0;

			double winChance = 1.0 / divisor;

			if (outcome)
			{
				teams[i]->m_stat_gameswonseason++;
				teams[i]->m_stat_gameswonweek++;
			}

			double multiplier = (outcome ? 1.0 : 0.0) - winChance;
			double deltaRating = 32.0 * multiplier;
			if ( deltaRating < 0 && (-1.0 * deltaRating) > teams[i]->m_stat_rating )
				teams[i]->m_stat_rating = 0;
			else
				teams[i]->m_stat_rating += long2int32(deltaRating);
			objmgr.UpdateArenaTeamRankings();

			teams[i]->SaveToDB();

			for(set<uint32>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
			{
				Player *plr = objmgr.GetPlayer(*itr);
				if( plr != NULL && plr->m_arenaTeams[m_arenateamtype] != NULL )
				{
					ArenaTeam * t = plr->m_arenaTeams[m_arenateamtype];
					ArenaTeamMember * tp = t->GetMember(plr->m_playerInfo);
					if( tp != NULL && outcome )
					{
						tp->Won_ThisWeek++;
						tp->Won_ThisSeason++;
					}
				}
			}
		}
	}

	for(int i = 0; i < 2; i++)
	{
		bool victorious = (i == m_winningteam);
		
		for(set<uint32>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); itr++)
		{
			Player *plr = objmgr.GetPlayer(*itr);
			if (plr != NULL)
				sHookInterface.OnArenaFinish(plr, plr->m_arenaTeams[m_arenateamtype], victorious, rated_match);
		}
	}
}