[6922] Whitespace and newline fixes
[getmangos.git] / src / game / ArenaTeam.cpp
blob5f1dfdb93d79b9fa7eccfc0a94292e2e714a9b07
1 /*
2 * Copyright (C) 2005-2008 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()
25 Id = 0;
26 Type = 0;
27 Name = "";
28 CaptainGuid = 0;
29 BackgroundColor = 0; // background
30 EmblemStyle = 0; // icon
31 EmblemColor = 0; // icon color
32 BorderStyle = 0; // border
33 BorderColor = 0; // border color
34 stats.games_week = 0;
35 stats.games_season = 0;
36 stats.rank = 0;
37 stats.rating = 1500;
38 stats.wins_week = 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
50 return false;
51 if(objmgr.GetArenaTeamByName(ArenaTeamName)) // arena team with this name already exist
52 return false;
54 sLog.outDebug("GUILD: creating arena team %s to leader: %u", ArenaTeamName.c_str(), GUID_LOPART(captainGuid));
56 CaptainGuid = captainGuid;
57 Name = ArenaTeamName;
58 Type = type;
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);
77 return true;
80 bool ArenaTeam::AddMember(const uint64& PlayerGuid)
82 std::string plName;
83 uint8 plClass;
85 // arena team is full (can't have more than type * 2 players!)
86 if(GetMembersSize() >= GetType() * 2)
87 return false;
89 Player *pl = objmgr.GetPlayer(PlayerGuid);
90 if(pl)
92 if(pl->GetArenaTeamId(GetSlot()))
94 sLog.outError("Arena::AddMember() : player already in this sized team");
95 return false;
98 plClass = (uint8)pl->getClass();
99 plName = pl->GetName();
101 else
103 // 0 1
104 QueryResult *result = CharacterDatabase.PQuery("SELECT name, class FROM characters WHERE guid='%u'", GUID_LOPART(PlayerGuid));
105 if(!result)
106 return false;
108 plName = (*result)[0].GetCppString();
109 plClass = (*result)[1].GetUInt8();
110 delete result;
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");
116 return false;
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 );
137 if(pl)
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);
147 return true;
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);
154 if(!result)
155 return false;
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();
169 delete result;
171 // only load here, so additional checks can be made
172 LoadStatsFromDB(ArenaTeamId);
173 LoadMembersFromDB(ArenaTeamId);
175 if(Empty())
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();
183 return false;
186 return true;
189 void ArenaTeam::LoadStatsFromDB(uint32 ArenaTeamId)
191 // 0 1 2 3 4 5
192 QueryResult *result = CharacterDatabase.PQuery("SELECT rating,games,wins,played,wins2,rank FROM arena_team_stats WHERE arenateamid = '%u'", ArenaTeamId);
194 if(!result)
195 return;
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();
206 delete result;
209 void ArenaTeam::LoadMembersFromDB(uint32 ArenaTeamId)
211 // 0 1 2 3 4 5 6 7
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);
216 if(!result)
217 return;
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() );
233 delete result;
236 void ArenaTeam::SetCaptain(const uint64& guid)
238 // disable remove/promote buttons
239 Player *oldcaptain = objmgr.GetPlayer(GetCaptain());
240 if(oldcaptain)
241 oldcaptain->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 1 + (GetSlot() * 6), 1);
243 // set new captain
244 CaptainGuid = guid;
246 // update database
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);
251 if(newcaptain)
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)
261 members.erase(itr);
262 break;
266 Player *player = objmgr.GetPlayer(guid);
268 if(player)
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)
284 // event
285 WorldPacket data;
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(this);
303 void ArenaTeam::Roster(WorldSession *session)
305 Player *pl = NULL;
307 WorldPacket data(SMSG_ARENA_TEAM_ROSTER, 100);
308 data << uint32(GetId()); // arena team id
309 data << uint32(GetMembersSize()); // members count
310 data << uint32(GetType()); // arena team type?
312 for (MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
314 pl = objmgr.GetPlayer(itr->guid);
316 data << uint64(itr->guid); // guid
317 data << uint8((pl ? 1 : 0)); // online flag
318 data << itr->name; // member name
319 data << uint32((itr->guid == GetCaptain() ? 0 : 1));// captain flag 0 captain 1 member
320 data << uint8((pl ? pl->getLevel() : 0)); // unknown, level?
321 data << uint8(itr->Class); // class
322 data << uint32(itr->games_week); // played this week
323 data << uint32(itr->wins_week); // wins this week
324 data << uint32(itr->games_season); // played this season
325 data << uint32(itr->wins_season); // wins this season
326 data << uint32(itr->personal_rating); // personal rating
328 session->SendPacket(&data);
329 sLog.outDebug("WORLD: Sent SMSG_ARENA_TEAM_ROSTER");
332 void ArenaTeam::Query(WorldSession *session)
334 WorldPacket data(SMSG_ARENA_TEAM_QUERY_RESPONSE, 4*7+GetName().size()+1);
335 data << uint32(GetId()); // team id
336 data << GetName(); // team name
337 data << uint32(GetType()); // arena team type (2=2x2, 3=3x3 or 5=5x5)
338 data << uint32(BackgroundColor); // background color
339 data << uint32(EmblemStyle); // emblem style
340 data << uint32(EmblemColor); // emblem color
341 data << uint32(BorderStyle); // border style
342 data << uint32(BorderColor); // border color
343 session->SendPacket(&data);
344 sLog.outDebug("WORLD: Sent SMSG_ARENA_TEAM_QUERY_RESPONSE");
347 void ArenaTeam::Stats(WorldSession *session)
349 WorldPacket data(SMSG_ARENA_TEAM_STATS, 4*7);
350 data << uint32(GetId()); // arena team id
351 data << uint32(stats.rating); // rating
352 data << uint32(stats.games_week); // games this week
353 data << uint32(stats.wins_week); // wins this week
354 data << uint32(stats.games_season); // played this season
355 data << uint32(stats.wins_season); // wins this season
356 data << uint32(stats.rank); // rank
357 session->SendPacket(&data);
360 void ArenaTeam::NotifyStatsChanged()
362 // this is called after a rated match ended
363 // updates arena team stats for every member of the team (not only the ones who participated!)
364 for(MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
366 Player * plr = objmgr.GetPlayer(itr->guid);
367 if(plr)
368 Stats(plr->GetSession());
372 void ArenaTeam::InspectStats(WorldSession *session, uint64 guid)
374 ArenaTeamMember* member = GetMember(guid);
375 if(!member)
376 return;
378 WorldPacket data(MSG_INSPECT_ARENA_TEAMS, 8+1+4*6);
379 data << uint64(guid); // player guid
380 data << uint8(GetSlot()); // slot (0...2)
381 data << uint32(GetId()); // arena team id
382 data << uint32(stats.rating); // rating
383 data << uint32(stats.games_season); // season played
384 data << uint32(stats.wins_season); // season wins
385 data << uint32(member->games_season); // played (count of all games, that the inspected member participated...)
386 data << uint32(member->personal_rating); // personal rating
387 session->SendPacket(&data);
390 void ArenaTeam::SetEmblem(uint32 backgroundColor, uint32 emblemStyle, uint32 emblemColor, uint32 borderStyle, uint32 borderColor)
392 BackgroundColor = backgroundColor;
393 EmblemStyle = emblemStyle;
394 EmblemColor = emblemColor;
395 BorderStyle = borderStyle;
396 BorderColor = borderColor;
398 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);
401 void ArenaTeam::SetStats(uint32 stat_type, uint32 value)
403 switch(stat_type)
405 case STAT_TYPE_RATING:
406 stats.rating = value;
407 CharacterDatabase.PExecute("UPDATE arena_team_stats SET rating = '%u' WHERE arenateamid = '%u'", value, GetId());
408 break;
409 case STAT_TYPE_GAMES_WEEK:
410 stats.games_week = value;
411 CharacterDatabase.PExecute("UPDATE arena_team_stats SET games = '%u' WHERE arenateamid = '%u'", value, GetId());
412 break;
413 case STAT_TYPE_WINS_WEEK:
414 stats.wins_week = value;
415 CharacterDatabase.PExecute("UPDATE arena_team_stats SET wins = '%u' WHERE arenateamid = '%u'", value, GetId());
416 break;
417 case STAT_TYPE_GAMES_SEASON:
418 stats.games_season = value;
419 CharacterDatabase.PExecute("UPDATE arena_team_stats SET played = '%u' WHERE arenateamid = '%u'", value, GetId());
420 break;
421 case STAT_TYPE_WINS_SEASON:
422 stats.wins_season = value;
423 CharacterDatabase.PExecute("UPDATE arena_team_stats SET wins2 = '%u' WHERE arenateamid = '%u'", value, GetId());
424 break;
425 case STAT_TYPE_RANK:
426 stats.rank = value;
427 CharacterDatabase.PExecute("UPDATE arena_team_stats SET rank = '%u' WHERE arenateamid = '%u'", value, GetId());
428 break;
429 default:
430 sLog.outDebug("unknown stat type in ArenaTeam::SetStats() %u", stat_type);
431 break;
435 void ArenaTeam::BroadcastPacket(WorldPacket *packet)
437 for (MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
439 Player *player = objmgr.GetPlayer(itr->guid);
440 if(player)
441 player->GetSession()->SendPacket(packet);
445 uint8 ArenaTeam::GetSlotByType( uint32 type )
447 switch(type)
449 case ARENA_TEAM_2v2: return 0;
450 case ARENA_TEAM_3v3: return 1;
451 case ARENA_TEAM_5v5: return 2;
452 default:
453 break;
455 sLog.outError("FATAL: Unknown arena team type %u for some arena team", type);
456 return 0xFF;
459 bool ArenaTeam::HaveMember( const uint64& guid ) const
461 for (MemberList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
462 if(itr->guid == guid)
463 return true;
465 return false;
468 uint32 ArenaTeam::GetPoints(uint32 MemberRating)
470 // returns how many points would be awarded with this team type with this rating
471 float points;
473 uint32 rating = MemberRating + 150 < stats.rating ? MemberRating : stats.rating;
475 if(rating<=1500)
476 points = (float)rating * 0.22f + 14.0f;
477 else
478 points = 1511.26f / (1.0f + 1639.28f * exp(-0.00412f * (float)rating));
480 // type penalties for <5v5 teams
481 if(Type == ARENA_TEAM_2v2)
482 points *= 0.76f;
483 else if(Type == ARENA_TEAM_3v3)
484 points *= 0.88f;
486 return (uint32) points;
489 float ArenaTeam::GetChanceAgainst(uint32 own_rating, uint32 enemy_rating)
491 // returns the chance to win against a team with the given rating, used in the rating adjustment calculation
492 // ELO system
493 return 1.0f/(1.0f+exp(log(10.0f)*(float)((float)enemy_rating - (float)own_rating)/400.0f));
496 int32 ArenaTeam::WonAgainst(uint32 againstRating)
498 // called when the team has won
499 //'chance' calculation - to beat the opponent
500 float chance = GetChanceAgainst(stats.rating,againstRating);
501 // calculate the rating modification (ELO system with k=32)
502 int32 mod = (int32)floor(32.0f * (1.0f - chance));
503 // modify the team stats accordingly
504 stats.rating += mod;
505 stats.games_week += 1;
506 stats.wins_week += 1;
507 stats.games_season += 1;
508 stats.wins_season += 1;
509 //update team's rank
510 stats.rank = 1;
511 ObjectMgr::ArenaTeamMap::iterator i = objmgr.GetArenaTeamMapBegin();
512 for ( ; i != objmgr.GetArenaTeamMapEnd(); ++i)
514 if (i->second->GetType() == this->Type && i->second->GetStats().rating > stats.rating)
515 ++stats.rank;
518 // return the rating change, used to display it on the results screen
519 return mod;
522 int32 ArenaTeam::LostAgainst(uint32 againstRating)
524 // called when the team has lost
525 //'chance' calculation - to loose to the opponent
526 float chance = GetChanceAgainst(stats.rating,againstRating);
527 // calculate the rating modification (ELO system with k=32)
528 int32 mod = (int32)ceil(32.0f * (0.0f - chance));
529 // modify the team stats accordingly
530 stats.rating += mod;
531 stats.games_week += 1;
532 stats.games_season += 1;
533 //update team's rank
535 stats.rank = 1;
536 ObjectMgr::ArenaTeamMap::iterator i = objmgr.GetArenaTeamMapBegin();
537 for ( ; i != objmgr.GetArenaTeamMapEnd(); ++i)
539 if (i->second->GetType() == this->Type && i->second->GetStats().rating > stats.rating)
540 ++stats.rank;
543 // return the rating change, used to display it on the results screen
544 return mod;
547 void ArenaTeam::MemberLost(Player * plr, uint32 againstRating)
549 // called for each participant of a match after losing
550 for(MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
552 if(itr->guid == plr->GetGUID())
554 // update personal rating
555 float chance = GetChanceAgainst(itr->personal_rating, againstRating);
556 int32 mod = (int32)ceil(32.0f * (0.0f - chance));
557 itr->ModifyPersonalRating(plr, mod, GetSlot());
558 // update personal played stats
559 itr->games_week +=1;
560 itr->games_season +=1;
561 // update the unit fields
562 plr->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 6 * GetSlot() + 2, itr->games_week);
563 plr->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 6 * GetSlot() + 3, itr->games_season);
564 return;
569 void ArenaTeam::MemberWon(Player * plr, uint32 againstRating)
571 // called for each participant after winning a match
572 for(MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
574 if(itr->guid == plr->GetGUID())
576 // update personal rating
577 float chance = GetChanceAgainst(itr->personal_rating, againstRating);
578 int32 mod = (int32)floor(32.0f * (1.0f - chance));
579 itr->ModifyPersonalRating(plr, mod, GetSlot());
580 // update personal stats
581 itr->games_week +=1;
582 itr->games_season +=1;
583 itr->wins_season += 1;
584 itr->wins_week += 1;
585 // update unit fields
586 plr->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 6 * GetSlot() + 2, itr->games_week);
587 plr->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 6 * GetSlot() + 3, itr->games_season);
588 return;
593 void ArenaTeam::UpdateArenaPointsHelper(std::map<uint32, uint32>& PlayerPoints)
595 // called after a match has ended and the stats are already modified
596 // helper function for arena point distribution (this way, when distributing, no actual calculation is required, just a few comparisons)
597 // 10 played games per week is a minimum
598 if (stats.games_week < 10)
599 return;
600 // to get points, a player has to participate in at least 30% of the matches
601 uint32 min_plays = (uint32) ceil(stats.games_week * 0.3);
602 for(MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
604 // the player participated in enough games, update his points
605 uint32 points_to_add = 0;
606 if (itr->games_week >= min_plays)
607 points_to_add = GetPoints(itr->personal_rating);
608 // OBSOLETE : CharacterDatabase.PExecute("UPDATE arena_team_member SET points_to_add = '%u' WHERE arenateamid = '%u' AND guid = '%u'", points_to_add, Id, itr->guid);
610 std::map<uint32, uint32>::iterator plr_itr = PlayerPoints.find(GUID_LOPART(itr->guid));
611 if (plr_itr != PlayerPoints.end())
613 //check if there is already more points
614 if (plr_itr->second < points_to_add)
615 PlayerPoints[GUID_LOPART(itr->guid)] = points_to_add;
617 else
618 PlayerPoints[GUID_LOPART(itr->guid)] = points_to_add;
622 void ArenaTeam::SaveToDB()
624 // save team and member stats to db
625 // called after a match has ended, or when calculating arena_points
626 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());
627 for(MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
629 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, itr->guid);
633 void ArenaTeam::FinishWeek()
635 stats.games_week = 0; // played this week
636 stats.wins_week = 0; // wins this week
637 for(MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
639 itr->games_week = 0;
640 itr->wins_week = 0;
645 arenateam fields (id from 2.3.3 client):
646 1414 - arena team id 2v2
647 1415 - 0=captain, 1=member
648 1416 - played this week
649 1417 - played this season
650 1418 - unk - rank?
651 1419 - personal arena rating
652 1420 - arena team id 3v3
653 1421 - 0=captain, 1=member
654 1422 - played this week
655 1423 - played this season
656 1424 - unk - rank?
657 1425 - personal arena rating
658 1426 - arena team id 5v5
659 1427 - 0=captain, 1=member
660 1428 - played this week
661 1429 - played this season
662 1430 - unk - rank?
663 1431 - personal arena rating