[7255] Allows saving characters in Battle Grounds.

* Now player can join to BG after logout during 5 minutes, if BG in progress.
* All players after server crash or restart should appear at the battlemaster

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
GriffonHeart 2009-02-09 16:07:16 +03:00 committed by VladimirMangos
parent 8af53064eb
commit 75121a5823
11 changed files with 162 additions and 52 deletions

View file

@ -14028,8 +14028,8 @@ float Player::GetFloatValueFromDB(uint16 index, uint64 guid)
bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
{
//// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [28] [29] 30 31 32 33
//QueryResult *result = CharacterDatabase.PQuery("SELECT guid, account, data, name, race, class, position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeon_difficulty, arena_pending_points FROM characters WHERE guid = '%u'", guid);
//// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [28] [29] 30 31 32 33 34 35 36 37 38 39 40
//QueryResult *result = CharacterDatabase.PQuery("SELECT guid, account, data, name, race, class, position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeon_difficulty, arena_pending_points,bgid,bgteam,bgmap,bgx,bgy,bgz,bgo FROM characters WHERE guid = '%u'", guid);
QueryResult *result = holder->GetResult(PLAYER_LOGIN_QUERY_LOADFROM);
if(!result)
@ -14154,6 +14154,51 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
m_movementInfo.t_o = 0.0f;
}
uint32 bgid = fields[34].GetUInt32();
uint32 bgteam = fields[35].GetUInt32();
if(bgid) //saved in BattleGround
{
SetBattleGroundEntryPoint(fields[36].GetUInt32(),fields[37].GetFloat(),fields[38].GetFloat(),fields[39].GetFloat(),fields[40].GetFloat());
// check entry point and fix to homebind if need
if(!MapManager::IsValidMapCoord(m_bgEntryPoint))
SetBattleGroundEntryPoint(m_homebindMapId,m_homebindX,m_homebindY,m_homebindZ,0.0f);
BattleGround *currentBg = sBattleGroundMgr.GetBattleGround(bgid);
if(currentBg && currentBg->IsPlayerInBattleGround(GetGUID()))
{
uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(currentBg->GetTypeID(), currentBg->GetArenaType());
uint32 queueSlot = AddBattleGroundQueueId(bgQueueTypeId);
SetBattleGroundId(currentBg->GetInstanceID());
SetBGTeam(bgteam);
SetInviteForBattleGroundQueueType(bgQueueTypeId,currentBg->GetInstanceID());
}
else
{
Relocate(GetBattleGroundEntryPoint());
//RemoveArenaAuras(true);
}
}
else
{
MapEntry const* mapEntry = sMapStore.LookupEntry(GetMapId());
// if server restart after player save in BG or area
// player can have current coordinates in to BG/Arean map, fix this
if(!mapEntry || mapEntry->IsBattleGroundOrArena())
{
// return to BG master
SetMapId(fields[36].GetUInt32());
Relocate(fields[37].GetFloat(),fields[38].GetFloat(),fields[39].GetFloat(),fields[40].GetFloat());
// check entry point and fix to homebind if need
if(!IsPositionValid())
RelocateToHomebind();
}
}
if (transGUID != 0)
{
m_movementInfo.t_x = fields[20].GetFloat();
@ -15481,12 +15526,6 @@ void Player::SaveToDB()
// first save/honor gain after midnight will also update the player's honor fields
UpdateHonorFields();
// players aren't saved on battleground maps
uint32 mapid = IsBeingTeleported() ? GetTeleportDest().mapid : GetMapId();
const MapEntry * me = sMapStore.LookupEntry(mapid);
if(!me || me->IsBattleGroundOrArena())
return;
int is_save_resting = HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) ? 1 : 0;
//save, far from tavern/city
//save, but in tavern/city
@ -15522,23 +15561,14 @@ void Player::SaveToDB()
"taximask, online, cinematic, "
"totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, "
"trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, "
"death_expire_time, taxi_path, arena_pending_points) VALUES ("
"death_expire_time, taxi_path, arena_pending_points, bgid, bgteam, bgmap, bgx, bgy, bgz, bgo) VALUES ("
<< GetGUIDLow() << ", "
<< GetSession()->GetAccountId() << ", '"
<< sql_name << "', "
<< m_race << ", "
<< m_class << ", ";
bool save_to_dest = false;
if(IsBeingTeleported())
{
// don't save to battlegrounds or arenas
const MapEntry *entry = sMapStore.LookupEntry(GetTeleportDest().mapid);
if(entry && entry->map_type != MAP_BATTLEGROUND && entry->map_type != MAP_ARENA)
save_to_dest = true;
}
if(!save_to_dest)
if(!IsBeingTeleported())
{
ss << GetMapId() << ", "
<< (uint32)GetDifficulty() << ", "
@ -15620,7 +15650,17 @@ void Player::SaveToDB()
ss << ", '";
ss << m_taxi.SaveTaxiDestinationsToString();
ss << "', '0' )";
ss << "', '0', ";
ss << GetBattleGroundId();
ss << ", ";
ss << GetBGTeam();
ss << ", ";
ss << m_bgEntryPoint.mapid << ", "
<< finiteAlways(m_bgEntryPoint.x) << ", "
<< finiteAlways(m_bgEntryPoint.y) << ", "
<< finiteAlways(m_bgEntryPoint.z) << ", "
<< finiteAlways(m_bgEntryPoint.o);
ss << ")";
CharacterDatabase.Execute( ss.str().c_str() );
@ -18054,6 +18094,40 @@ void Player::SendInitialPacketsAfterAddToMap()
SendMessageToSet(&data,true);
}
// setup BG group membership if need
if(BattleGround* currentBg = GetBattleGround())
{
// call for invited (join) or listed (relogin) and avoid other cases (GM teleport)
if (IsInvitedForBattleGroundInstance(GetBattleGroundId()) ||
currentBg->IsPlayerInBattleGround(GetGUID()))
{
currentBg->PlayerRelogin(this);
if(currentBg->GetMapId() == GetMapId()) // we teleported/login to/in bg
{
uint32 team = currentBg->GetPlayerTeam(GetGUID());
if(!team)
team = GetTeam();
Group* group = currentBg->GetBgRaid(team);
if(!group) // first player joined
{
group = new Group;
currentBg->SetBgRaid(team, group);
group->Create(GetGUIDLow(), GetName());
}
else // raid already exist
{
if(group->IsMember(GetGUID()))
{
uint8 subgroup = group->GetMemberGroup(GetGUID());
SetGroup(group, subgroup);
}
else
currentBg->GetBgRaid(team)->AddMember(GetGUID(), GetName());
}
}
}
}
SendAurasForTarget(this);
SendEnchantmentDurations(); // must be after add to map
SendItemDurations(); // must be after add to map