2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "WorldPacket.h"
20 #include "ObjectMgr.h"
21 #include "ArenaTeam.h"
23 ArenaTeam::ArenaTeam()
29 BackgroundColor
= 0; // background
30 EmblemStyle
= 0; // icon
31 EmblemColor
= 0; // icon color
32 BorderStyle
= 0; // border
33 BorderColor
= 0; // border color
35 stats
.games_season
= 0;
39 stats
.wins_season
= 0;
42 ArenaTeam::~ArenaTeam()
47 bool ArenaTeam::Create(uint64 captainGuid
, uint32 type
, std::string ArenaTeamName
)
49 if(!objmgr
.GetPlayer(captainGuid
)) // player not exist
51 if(objmgr
.GetArenaTeamByName(ArenaTeamName
)) // arena team with this name already exist
54 sLog
.outDebug("GUILD: creating arena team %s to leader: %u", ArenaTeamName
.c_str(), GUID_LOPART(captainGuid
));
56 CaptainGuid
= captainGuid
;
60 Id
= objmgr
.GenerateArenaTeamId();
62 // ArenaTeamName already assigned to ArenaTeam::name, use it to encode string for DB
63 CharacterDatabase
.escape_string(ArenaTeamName
);
65 CharacterDatabase
.BeginTransaction();
66 // CharacterDatabase.PExecute("DELETE FROM arena_team WHERE arenateamid='%u'", Id); - MAX(arenateam)+1 not exist
67 CharacterDatabase
.PExecute("DELETE FROM arena_team_member WHERE arenateamid='%u'", Id
);
68 CharacterDatabase
.PExecute("INSERT INTO arena_team (arenateamid,name,captainguid,type,BackgroundColor,EmblemStyle,EmblemColor,BorderStyle,BorderColor) "
69 "VALUES('%u','%s','%u','%u','%u','%u','%u','%u','%u')",
70 Id
, ArenaTeamName
.c_str(), GUID_LOPART(CaptainGuid
), Type
, BackgroundColor
, EmblemStyle
, EmblemColor
, BorderStyle
, BorderColor
);
71 CharacterDatabase
.PExecute("INSERT INTO arena_team_stats (arenateamid, rating, games, wins, played, wins2, rank) VALUES "
72 "('%u', '%u', '%u', '%u', '%u', '%u', '%u')", Id
, stats
.rating
, stats
.games_week
, stats
.wins_week
, stats
.games_season
, stats
.wins_season
, stats
.rank
);
74 CharacterDatabase
.CommitTransaction();
76 AddMember(CaptainGuid
);
80 bool ArenaTeam::AddMember(const uint64
& PlayerGuid
)
85 // arena team is full (can't have more than type * 2 players!)
86 if(GetMembersSize() >= GetType() * 2)
89 Player
*pl
= objmgr
.GetPlayer(PlayerGuid
);
92 if(pl
->GetArenaTeamId(GetSlot()))
94 sLog
.outError("Arena::AddMember() : player already in this sized team");
98 plClass
= (uint8
)pl
->getClass();
99 plName
= pl
->GetName();
104 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT name, class FROM characters WHERE guid='%u'", GUID_LOPART(PlayerGuid
));
108 plName
= (*result
)[0].GetCppString();
109 plClass
= (*result
)[1].GetUInt8();
112 // check if player already in arenateam of that size
113 if(Player::GetArenaTeamIdFromDB(PlayerGuid
, GetType()) != 0)
115 sLog
.outError("Arena::AddMember() : player already in this sized team");
120 // remove all player signs from another petitions
121 // this will be prevent attempt joining player to many arenateams and corrupt arena team data integrity
122 Player::RemovePetitionsAndSigns(PlayerGuid
, GetType());
124 ArenaTeamMember newmember
;
125 newmember
.name
= plName
;
126 newmember
.guid
= PlayerGuid
;
127 newmember
.Class
= plClass
;
128 newmember
.games_season
= 0;
129 newmember
.games_week
= 0;
130 newmember
.wins_season
= 0;
131 newmember
.wins_week
= 0;
132 newmember
.personal_rating
= 1500;
133 members
.push_back(newmember
);
135 CharacterDatabase
.PExecute("INSERT INTO arena_team_member (arenateamid, guid, personal_rating) VALUES ('%u', '%u', '%u')", Id
, GUID_LOPART(newmember
.guid
), newmember
.personal_rating
);
139 pl
->SetInArenaTeam(Id
, GetSlot());
140 pl
->SetArenaTeamIdInvited(0);
141 pl
->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ (GetSlot()*6) + 5, newmember
.personal_rating
);
143 // hide promote/remove buttons
144 if(CaptainGuid
!= PlayerGuid
)
145 pl
->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ (GetSlot() * 6) + 1, 1);
150 bool ArenaTeam::LoadArenaTeamFromDB(uint32 ArenaTeamId
)
152 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT arenateamid,name,captainguid,type,BackgroundColor,EmblemStyle,EmblemColor,BorderStyle,BorderColor FROM arena_team WHERE arenateamid = '%u'", ArenaTeamId
);
157 Field
*fields
= result
->Fetch();
159 Id
= fields
[0].GetUInt32();
160 Name
= fields
[1].GetCppString();
161 CaptainGuid
= MAKE_NEW_GUID(fields
[2].GetUInt32(), 0, HIGHGUID_PLAYER
);
162 Type
= fields
[3].GetUInt32();
163 BackgroundColor
= fields
[4].GetUInt32();
164 EmblemStyle
= fields
[5].GetUInt32();
165 EmblemColor
= fields
[6].GetUInt32();
166 BorderStyle
= fields
[7].GetUInt32();
167 BorderColor
= fields
[8].GetUInt32();
171 // only load here, so additional checks can be made
172 LoadStatsFromDB(ArenaTeamId
);
173 LoadMembersFromDB(ArenaTeamId
);
177 // arena team is empty, delete from db
178 CharacterDatabase
.BeginTransaction();
179 CharacterDatabase
.PExecute("DELETE FROM arena_team WHERE arenateamid = '%u'", ArenaTeamId
);
180 CharacterDatabase
.PExecute("DELETE FROM arena_team_member WHERE arenateamid = '%u'", ArenaTeamId
);
181 CharacterDatabase
.PExecute("DELETE FROM arena_team_stats WHERE arenateamid = '%u'", ArenaTeamId
);
182 CharacterDatabase
.CommitTransaction();
189 void ArenaTeam::LoadStatsFromDB(uint32 ArenaTeamId
)
192 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT rating,games,wins,played,wins2,rank FROM arena_team_stats WHERE arenateamid = '%u'", ArenaTeamId
);
197 Field
*fields
= result
->Fetch();
199 stats
.rating
= fields
[0].GetUInt32();
200 stats
.games_week
= fields
[1].GetUInt32();
201 stats
.wins_week
= fields
[2].GetUInt32();
202 stats
.games_season
= fields
[3].GetUInt32();
203 stats
.wins_season
= fields
[4].GetUInt32();
204 stats
.rank
= fields
[5].GetUInt32();
209 void ArenaTeam::LoadMembersFromDB(uint32 ArenaTeamId
)
212 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT member.guid,played_week,wons_week,played_season,wons_season,personal_rating,name,class "
213 "FROM arena_team_member member "
214 "INNER JOIN characters chars on member.guid = chars.guid "
215 "WHERE member.arenateamid = '%u'", ArenaTeamId
);
221 Field
*fields
= result
->Fetch();
222 ArenaTeamMember newmember
;
223 newmember
.guid
= MAKE_NEW_GUID(fields
[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
224 newmember
.games_week
= fields
[1].GetUInt32();
225 newmember
.wins_week
= fields
[2].GetUInt32();
226 newmember
.games_season
= fields
[3].GetUInt32();
227 newmember
.wins_season
= fields
[4].GetUInt32();
228 newmember
.personal_rating
= fields
[5].GetUInt32();
229 newmember
.name
= fields
[6].GetCppString();
230 newmember
.Class
= fields
[7].GetUInt8();
231 members
.push_back(newmember
);
232 }while( result
->NextRow() );
236 void ArenaTeam::SetCaptain(const uint64
& guid
)
238 // disable remove/promote buttons
239 Player
*oldcaptain
= objmgr
.GetPlayer(GetCaptain());
241 oldcaptain
->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ 1 + (GetSlot() * 6), 1);
247 CharacterDatabase
.PExecute("UPDATE arena_team SET captainguid = '%u' WHERE arenateamid = '%u'", GUID_LOPART(guid
), Id
);
249 // enable remove/promote buttons
250 Player
*newcaptain
= objmgr
.GetPlayer(guid
);
252 newcaptain
->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ 1 + (GetSlot() * 6), 0);
255 void ArenaTeam::DelMember(uint64 guid
)
257 for (MemberList::iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
259 if (itr
->guid
== guid
)
266 Player
*player
= objmgr
.GetPlayer(guid
);
270 player
->SetInArenaTeam(0, GetSlot());
271 player
->GetSession()->SendArenaTeamCommandResult(ERR_ARENA_TEAM_QUIT_S
, GetName(), "", 0);
272 // delete all info regarding this team
273 for(int i
= 0; i
< 6; ++i
)
275 player
->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ (GetSlot() * 6) + i
, 0);
279 CharacterDatabase
.PExecute("DELETE FROM arena_team_member WHERE arenateamid = '%u' AND guid = '%u'", GetId(), GUID_LOPART(guid
));
282 void ArenaTeam::Disband(WorldSession
*session
)
286 session
->BuildArenaTeamEventPacket(&data
, ERR_ARENA_TEAM_DISBANDED_S
, 2, session
->GetPlayerName(), GetName(), "");
287 BroadcastPacket(&data
);
289 while (!members
.empty())
291 // Removing from members is done in DelMember.
292 DelMember(members
.front().guid
);
295 CharacterDatabase
.BeginTransaction();
296 CharacterDatabase
.PExecute("DELETE FROM arena_team WHERE arenateamid = '%u'", Id
);
297 CharacterDatabase
.PExecute("DELETE FROM arena_team_member WHERE arenateamid = '%u'", Id
); //< this should be alredy done by calling DelMember(memberGuids[j]); for each member
298 CharacterDatabase
.PExecute("DELETE FROM arena_team_stats WHERE arenateamid = '%u'", Id
);
299 CharacterDatabase
.CommitTransaction();
300 objmgr
.RemoveArenaTeam(Id
);
303 void ArenaTeam::Roster(WorldSession
*session
)
309 WorldPacket
data(SMSG_ARENA_TEAM_ROSTER
, 100);
310 data
<< uint32(GetId()); // arena team id
311 data
<< uint8(unk308
); // 308 unknown value but affect packet structure
312 data
<< uint32(GetMembersSize()); // members count
313 data
<< uint32(GetType()); // arena team type?
315 for (MemberList::const_iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
317 pl
= objmgr
.GetPlayer(itr
->guid
);
319 data
<< uint64(itr
->guid
); // guid
320 data
<< uint8((pl
? 1 : 0)); // online flag
321 data
<< itr
->name
; // member name
322 data
<< uint32((itr
->guid
== GetCaptain() ? 0 : 1));// captain flag 0 captain 1 member
323 data
<< uint8((pl
? pl
->getLevel() : 0)); // unknown, level?
324 data
<< uint8(itr
->Class
); // class
325 data
<< uint32(itr
->games_week
); // played this week
326 data
<< uint32(itr
->wins_week
); // wins this week
327 data
<< uint32(itr
->games_season
); // played this season
328 data
<< uint32(itr
->wins_season
); // wins this season
329 data
<< uint32(itr
->personal_rating
); // personal rating
332 data
<< float(0.0); // 308 unk
333 data
<< float(0.0); // 308 unk
337 session
->SendPacket(&data
);
338 sLog
.outDebug("WORLD: Sent SMSG_ARENA_TEAM_ROSTER");
341 void ArenaTeam::Query(WorldSession
*session
)
343 WorldPacket
data(SMSG_ARENA_TEAM_QUERY_RESPONSE
, 4*7+GetName().size()+1);
344 data
<< uint32(GetId()); // team id
345 data
<< GetName(); // team name
346 data
<< uint32(GetType()); // arena team type (2=2x2, 3=3x3 or 5=5x5)
347 data
<< uint32(BackgroundColor
); // background color
348 data
<< uint32(EmblemStyle
); // emblem style
349 data
<< uint32(EmblemColor
); // emblem color
350 data
<< uint32(BorderStyle
); // border style
351 data
<< uint32(BorderColor
); // border color
352 session
->SendPacket(&data
);
353 sLog
.outDebug("WORLD: Sent SMSG_ARENA_TEAM_QUERY_RESPONSE");
356 void ArenaTeam::Stats(WorldSession
*session
)
358 WorldPacket
data(SMSG_ARENA_TEAM_STATS
, 4*7);
359 data
<< uint32(GetId()); // arena team id
360 data
<< uint32(stats
.rating
); // rating
361 data
<< uint32(stats
.games_week
); // games this week
362 data
<< uint32(stats
.wins_week
); // wins this week
363 data
<< uint32(stats
.games_season
); // played this season
364 data
<< uint32(stats
.wins_season
); // wins this season
365 data
<< uint32(stats
.rank
); // rank
366 session
->SendPacket(&data
);
369 void ArenaTeam::NotifyStatsChanged()
371 // this is called after a rated match ended
372 // updates arena team stats for every member of the team (not only the ones who participated!)
373 for(MemberList::const_iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
375 Player
* plr
= objmgr
.GetPlayer(itr
->guid
);
377 Stats(plr
->GetSession());
381 void ArenaTeam::InspectStats(WorldSession
*session
, uint64 guid
)
383 ArenaTeamMember
* member
= GetMember(guid
);
387 WorldPacket
data(MSG_INSPECT_ARENA_TEAMS
, 8+1+4*6);
388 data
<< uint64(guid
); // player guid
389 data
<< uint8(GetSlot()); // slot (0...2)
390 data
<< uint32(GetId()); // arena team id
391 data
<< uint32(stats
.rating
); // rating
392 data
<< uint32(stats
.games_season
); // season played
393 data
<< uint32(stats
.wins_season
); // season wins
394 data
<< uint32(member
->games_season
); // played (count of all games, that the inspected member participated...)
395 data
<< uint32(member
->personal_rating
); // personal rating
396 session
->SendPacket(&data
);
399 void ArenaTeam::SetEmblem(uint32 backgroundColor
, uint32 emblemStyle
, uint32 emblemColor
, uint32 borderStyle
, uint32 borderColor
)
401 BackgroundColor
= backgroundColor
;
402 EmblemStyle
= emblemStyle
;
403 EmblemColor
= emblemColor
;
404 BorderStyle
= borderStyle
;
405 BorderColor
= borderColor
;
407 CharacterDatabase
.PExecute("UPDATE arena_team SET BackgroundColor='%u', EmblemStyle='%u', EmblemColor='%u', BorderStyle='%u', BorderColor='%u' WHERE arenateamid='%u'", BackgroundColor
, EmblemStyle
, EmblemColor
, BorderStyle
, BorderColor
, Id
);
410 void ArenaTeam::SetStats(uint32 stat_type
, uint32 value
)
414 case STAT_TYPE_RATING
:
415 stats
.rating
= value
;
416 CharacterDatabase
.PExecute("UPDATE arena_team_stats SET rating = '%u' WHERE arenateamid = '%u'", value
, GetId());
418 case STAT_TYPE_GAMES_WEEK
:
419 stats
.games_week
= value
;
420 CharacterDatabase
.PExecute("UPDATE arena_team_stats SET games = '%u' WHERE arenateamid = '%u'", value
, GetId());
422 case STAT_TYPE_WINS_WEEK
:
423 stats
.wins_week
= value
;
424 CharacterDatabase
.PExecute("UPDATE arena_team_stats SET wins = '%u' WHERE arenateamid = '%u'", value
, GetId());
426 case STAT_TYPE_GAMES_SEASON
:
427 stats
.games_season
= value
;
428 CharacterDatabase
.PExecute("UPDATE arena_team_stats SET played = '%u' WHERE arenateamid = '%u'", value
, GetId());
430 case STAT_TYPE_WINS_SEASON
:
431 stats
.wins_season
= value
;
432 CharacterDatabase
.PExecute("UPDATE arena_team_stats SET wins2 = '%u' WHERE arenateamid = '%u'", value
, GetId());
436 CharacterDatabase
.PExecute("UPDATE arena_team_stats SET rank = '%u' WHERE arenateamid = '%u'", value
, GetId());
439 sLog
.outDebug("unknown stat type in ArenaTeam::SetStats() %u", stat_type
);
444 void ArenaTeam::BroadcastPacket(WorldPacket
*packet
)
446 for (MemberList::const_iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
448 Player
*player
= objmgr
.GetPlayer(itr
->guid
);
450 player
->GetSession()->SendPacket(packet
);
454 uint8
ArenaTeam::GetSlotByType( uint32 type
)
458 case ARENA_TEAM_2v2
: return 0;
459 case ARENA_TEAM_3v3
: return 1;
460 case ARENA_TEAM_5v5
: return 2;
464 sLog
.outError("FATAL: Unknown arena team type %u for some arena team", type
);
468 bool ArenaTeam::HaveMember( const uint64
& guid
) const
470 for (MemberList::const_iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
471 if(itr
->guid
== guid
)
477 uint32
ArenaTeam::GetPoints(uint32 MemberRating
)
479 // returns how many points would be awarded with this team type with this rating
482 uint32 rating
= MemberRating
+ 150 < stats
.rating
? MemberRating
: stats
.rating
;
485 points
= (float)rating
* 0.22f
+ 14.0f
;
487 points
= 1511.26f
/ (1.0f
+ 1639.28f
* exp(-0.00412f
* (float)rating
));
489 // type penalties for <5v5 teams
490 if(Type
== ARENA_TEAM_2v2
)
492 else if(Type
== ARENA_TEAM_3v3
)
495 return (uint32
) points
;
498 float ArenaTeam::GetChanceAgainst(uint32 own_rating
, uint32 enemy_rating
)
500 // returns the chance to win against a team with the given rating, used in the rating adjustment calculation
502 return 1.0f
/(1.0f
+exp(log(10.0f
)*(float)((float)enemy_rating
- (float)own_rating
)/400.0f
));
505 int32
ArenaTeam::WonAgainst(uint32 againstRating
)
507 // called when the team has won
508 //'chance' calculation - to beat the opponent
509 float chance
= GetChanceAgainst(stats
.rating
,againstRating
);
510 // calculate the rating modification (ELO system with k=32)
511 int32 mod
= (int32
)floor(32.0f
* (1.0f
- chance
));
512 // modify the team stats accordingly
514 stats
.games_week
+= 1;
515 stats
.wins_week
+= 1;
516 stats
.games_season
+= 1;
517 stats
.wins_season
+= 1;
520 ObjectMgr::ArenaTeamMap::const_iterator i
= objmgr
.GetArenaTeamMapBegin();
521 for ( ; i
!= objmgr
.GetArenaTeamMapEnd(); ++i
)
523 if (i
->second
->GetType() == this->Type
&& i
->second
->GetStats().rating
> stats
.rating
)
527 // return the rating change, used to display it on the results screen
531 int32
ArenaTeam::LostAgainst(uint32 againstRating
)
533 // called when the team has lost
534 //'chance' calculation - to loose to the opponent
535 float chance
= GetChanceAgainst(stats
.rating
,againstRating
);
536 // calculate the rating modification (ELO system with k=32)
537 int32 mod
= (int32
)ceil(32.0f
* (0.0f
- chance
));
538 // modify the team stats accordingly
540 stats
.games_week
+= 1;
541 stats
.games_season
+= 1;
545 ObjectMgr::ArenaTeamMap::const_iterator i
= objmgr
.GetArenaTeamMapBegin();
546 for ( ; i
!= objmgr
.GetArenaTeamMapEnd(); ++i
)
548 if (i
->second
->GetType() == this->Type
&& i
->second
->GetStats().rating
> stats
.rating
)
552 // return the rating change, used to display it on the results screen
556 void ArenaTeam::MemberLost(Player
* plr
, uint32 againstRating
)
558 // called for each participant of a match after losing
559 for(MemberList::iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
561 if(itr
->guid
== plr
->GetGUID())
563 // update personal rating
564 float chance
= GetChanceAgainst(itr
->personal_rating
, againstRating
);
565 int32 mod
= (int32
)ceil(32.0f
* (0.0f
- chance
));
566 itr
->ModifyPersonalRating(plr
, mod
, GetSlot());
567 // update personal played stats
569 itr
->games_season
+=1;
570 // update the unit fields
571 plr
->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ 6 * GetSlot() + 2, itr
->games_week
);
572 plr
->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ 6 * GetSlot() + 3, itr
->games_season
);
578 void ArenaTeam::OfflineMemberLost(uint64 guid
, uint32 againstRating
)
580 // called for offline player after ending rated arena match!
581 for(MemberList::iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
583 if(itr
->guid
== guid
)
585 // update personal rating
586 float chance
= GetChanceAgainst(itr
->personal_rating
, againstRating
);
587 int32 mod
= (int32
)ceil(32.0f
* (0.0f
- chance
));
588 if (int32(itr
->personal_rating
) + mod
< 0)
589 itr
->personal_rating
= 0;
591 itr
->personal_rating
+= mod
;
592 // update personal played stats
594 itr
->games_season
+=1;
600 void ArenaTeam::MemberWon(Player
* plr
, uint32 againstRating
)
602 // called for each participant after winning a match
603 for(MemberList::iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
605 if(itr
->guid
== plr
->GetGUID())
607 // update personal rating
608 float chance
= GetChanceAgainst(itr
->personal_rating
, againstRating
);
609 int32 mod
= (int32
)floor(32.0f
* (1.0f
- chance
));
610 itr
->ModifyPersonalRating(plr
, mod
, GetSlot());
611 // update personal stats
613 itr
->games_season
+=1;
614 itr
->wins_season
+= 1;
616 // update unit fields
617 plr
->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ 6 * GetSlot() + 2, itr
->games_week
);
618 plr
->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ 6 * GetSlot() + 3, itr
->games_season
);
624 void ArenaTeam::UpdateArenaPointsHelper(std::map
<uint32
, uint32
>& PlayerPoints
)
626 // called after a match has ended and the stats are already modified
627 // helper function for arena point distribution (this way, when distributing, no actual calculation is required, just a few comparisons)
628 // 10 played games per week is a minimum
629 if (stats
.games_week
< 10)
631 // to get points, a player has to participate in at least 30% of the matches
632 uint32 min_plays
= (uint32
) ceil(stats
.games_week
* 0.3);
633 for(MemberList::const_iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
635 // the player participated in enough games, update his points
636 uint32 points_to_add
= 0;
637 if (itr
->games_week
>= min_plays
)
638 points_to_add
= GetPoints(itr
->personal_rating
);
639 // OBSOLETE : CharacterDatabase.PExecute("UPDATE arena_team_member SET points_to_add = '%u' WHERE arenateamid = '%u' AND guid = '%u'", points_to_add, Id, itr->guid);
641 std::map
<uint32
, uint32
>::iterator plr_itr
= PlayerPoints
.find(GUID_LOPART(itr
->guid
));
642 if (plr_itr
!= PlayerPoints
.end())
644 //check if there is already more points
645 if (plr_itr
->second
< points_to_add
)
646 PlayerPoints
[GUID_LOPART(itr
->guid
)] = points_to_add
;
649 PlayerPoints
[GUID_LOPART(itr
->guid
)] = points_to_add
;
653 void ArenaTeam::SaveToDB()
655 // save team and member stats to db
656 // called after a match has ended, or when calculating arena_points
657 CharacterDatabase
.BeginTransaction();
658 CharacterDatabase
.PExecute("UPDATE arena_team_stats SET rating = '%u',games = '%u',played = '%u',rank = '%u',wins = '%u',wins2 = '%u' WHERE arenateamid = '%u'", stats
.rating
, stats
.games_week
, stats
.games_season
, stats
.rank
, stats
.wins_week
, stats
.wins_season
, GetId());
659 for(MemberList::const_iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
661 CharacterDatabase
.PExecute("UPDATE arena_team_member SET played_week = '%u', wons_week = '%u', played_season = '%u', wons_season = '%u', personal_rating = '%u' WHERE arenateamid = '%u' AND guid = '%u'", itr
->games_week
, itr
->wins_week
, itr
->games_season
, itr
->wins_season
, itr
->personal_rating
, Id
, GUID_LOPART(itr
->guid
));
663 CharacterDatabase
.CommitTransaction();
666 void ArenaTeam::FinishWeek()
668 stats
.games_week
= 0; // played this week
669 stats
.wins_week
= 0; // wins this week
670 for(MemberList::iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
677 bool ArenaTeam::IsFighting() const
679 for (MemberList::const_iterator itr
= members
.begin(); itr
!= members
.end(); ++itr
)
681 if (Player
*p
= objmgr
.GetPlayer(itr
->guid
))
683 if (p
->GetMap()->IsBattleArena())
691 arenateam fields (id from 2.3.3 client):
692 1414 - arena team id 2v2
693 1415 - 0=captain, 1=member
694 1416 - played this week
695 1417 - played this season
697 1419 - personal arena rating
698 1420 - arena team id 3v3
699 1421 - 0=captain, 1=member
700 1422 - played this week
701 1423 - played this season
703 1425 - personal arena rating
704 1426 - arena team id 5v5
705 1427 - 0=captain, 1=member
706 1428 - played this week
707 1429 - played this season
709 1431 - personal arena rating