Core/BattlePets: Journal lock improvements
Port From (https://github.com/TrinityCore/TrinityCore/commit/895367e69fac542ea00079ee1405228d9f150898)
This commit is contained in:
@@ -363,16 +363,14 @@ namespace Game.BattlePets
|
||||
|
||||
public void RemovePet(ObjectGuid guid)
|
||||
{
|
||||
if (!HasJournalLock())
|
||||
return;
|
||||
|
||||
BattlePet pet = GetPet(guid);
|
||||
if (pet == null)
|
||||
return;
|
||||
|
||||
pet.SaveInfo = BattlePetSaveInfo.Removed;
|
||||
|
||||
// spell is not unlearned on retail
|
||||
/*if (GetPetCount(pet.PacketInfo.Species) == 0)
|
||||
if (BattlePetSpeciesEntry const* speciesEntry = sBattlePetSpeciesStore.LookupEntry(pet.PacketInfo.Species))
|
||||
_owner.GetPlayer().RemoveSpell(speciesEntry.SummonSpellID);*/
|
||||
}
|
||||
|
||||
public void ClearFanfare(ObjectGuid guid)
|
||||
@@ -389,6 +387,9 @@ namespace Game.BattlePets
|
||||
|
||||
public void ModifyName(ObjectGuid guid, string name, DeclinedName declinedName)
|
||||
{
|
||||
if (!HasJournalLock())
|
||||
return;
|
||||
|
||||
BattlePet pet = GetPet(guid);
|
||||
if (pet == null)
|
||||
return;
|
||||
@@ -458,6 +459,9 @@ namespace Game.BattlePets
|
||||
|
||||
public void CageBattlePet(ObjectGuid guid)
|
||||
{
|
||||
if (!HasJournalLock())
|
||||
return;
|
||||
|
||||
BattlePet pet = GetPet(guid);
|
||||
if (pet == null)
|
||||
return;
|
||||
@@ -548,8 +552,12 @@ namespace Game.BattlePets
|
||||
|
||||
public void SendJournal()
|
||||
{
|
||||
if (!HasJournalLock())
|
||||
SendJournalLockStatus();
|
||||
|
||||
BattlePetJournal battlePetJournal = new();
|
||||
battlePetJournal.Trap = _trapLevel;
|
||||
battlePetJournal.HasJournalLock = _hasJournalLock;
|
||||
|
||||
foreach (var pet in _pets)
|
||||
if (pet.Value.SaveInfo != BattlePetSaveInfo.Removed)
|
||||
@@ -577,15 +585,33 @@ namespace Game.BattlePets
|
||||
_owner.SendPacket(battlePetError);
|
||||
}
|
||||
|
||||
public void SendJournalLockStatus()
|
||||
{
|
||||
if (!IsJournalLockAcquired())
|
||||
ToggleJournalLock(true);
|
||||
|
||||
if (HasJournalLock())
|
||||
_owner.SendPacket(new BattlePetJournalLockAcquired());
|
||||
else
|
||||
_owner.SendPacket(new BattlePetJournalLockDenied());
|
||||
}
|
||||
|
||||
public bool IsJournalLockAcquired()
|
||||
{
|
||||
return Global.WorldMgr.IsBattlePetJournalLockAcquired(_owner.GetBattlenetAccountGUID());
|
||||
}
|
||||
|
||||
public BattlePetSlot GetSlot(byte slot) { return slot < _slots.Count ? _slots[slot] : null; }
|
||||
WorldSession GetOwner() { return _owner; }
|
||||
|
||||
public ushort GetTrapLevel() { return _trapLevel; }
|
||||
public List<BattlePetSlot> GetSlots() { return _slots; }
|
||||
|
||||
public bool HasJournalLock() { return true; }
|
||||
public bool HasJournalLock() { return _hasJournalLock; }
|
||||
public void ToggleJournalLock(bool on) { _hasJournalLock = on; }
|
||||
|
||||
WorldSession _owner;
|
||||
bool _hasJournalLock;
|
||||
ushort _trapLevel;
|
||||
Dictionary<ulong, BattlePet> _pets = new();
|
||||
List<BattlePetSlot> _slots = new();
|
||||
|
||||
@@ -30,6 +30,15 @@ namespace Game
|
||||
GetBattlePetMgr().SendJournal();
|
||||
}
|
||||
|
||||
[WorldPacketHandler(ClientOpcodes.BattlePetRequestJournalLock)]
|
||||
void HandleBattlePetRequestJournalLock(BattlePetRequestJournalLock battlePetRequestJournalLock)
|
||||
{
|
||||
GetBattlePetMgr().SendJournalLockStatus();
|
||||
|
||||
if (GetBattlePetMgr().HasJournalLock())
|
||||
GetBattlePetMgr().SendJournal();
|
||||
}
|
||||
|
||||
[WorldPacketHandler(ClientOpcodes.BattlePetSetBattleSlot)]
|
||||
void HandleBattlePetSetBattleSlot(BattlePetSetBattleSlot battlePetSetBattleSlot)
|
||||
{
|
||||
@@ -57,6 +66,9 @@ namespace Game
|
||||
[WorldPacketHandler(ClientOpcodes.BattlePetSetFlags)]
|
||||
void HandleBattlePetSetFlags(BattlePetSetFlags battlePetSetFlags)
|
||||
{
|
||||
if (!GetBattlePetMgr().HasJournalLock())
|
||||
return;
|
||||
|
||||
var pet = GetBattlePetMgr().GetPet(battlePetSetFlags.PetGuid);
|
||||
if (pet != null)
|
||||
{
|
||||
|
||||
@@ -784,8 +784,7 @@ namespace Game
|
||||
pCurrChar.SetGuildLevel(0);
|
||||
}
|
||||
|
||||
// TODO: Move this to BattlePetMgr::SendJournalLock() just to have all packets in one file
|
||||
SendPacket(new BattlePetJournalLockAcquired());
|
||||
pCurrChar.GetSession().GetBattlePetMgr().SendJournalLockStatus();
|
||||
|
||||
pCurrChar.SendInitialPacketsBeforeAddToMap();
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Game.Networking.Packets
|
||||
}
|
||||
|
||||
public ushort Trap;
|
||||
bool HasJournalLock = true;
|
||||
public bool HasJournalLock = false;
|
||||
public List<BattlePetSlot> Slots = new();
|
||||
public List<BattlePetStruct> Pets = new();
|
||||
}
|
||||
@@ -55,6 +55,13 @@ namespace Game.Networking.Packets
|
||||
public override void Write() { }
|
||||
}
|
||||
|
||||
class BattlePetJournalLockDenied : ServerPacket
|
||||
{
|
||||
public BattlePetJournalLockDenied() : base(ServerOpcodes.BattlePetJournalLockDenied) { }
|
||||
|
||||
public override void Write() { }
|
||||
}
|
||||
|
||||
class BattlePetRequestJournal : ClientPacket
|
||||
{
|
||||
public BattlePetRequestJournal(WorldPacket packet) : base(packet) { }
|
||||
@@ -62,6 +69,13 @@ namespace Game.Networking.Packets
|
||||
public override void Read() { }
|
||||
}
|
||||
|
||||
class BattlePetRequestJournalLock : ClientPacket
|
||||
{
|
||||
public BattlePetRequestJournalLock(WorldPacket packet) : base(packet) { }
|
||||
|
||||
public override void Read() { }
|
||||
}
|
||||
|
||||
class BattlePetUpdates : ServerPacket
|
||||
{
|
||||
public BattlePetUpdates() : base(ServerOpcodes.BattlePetUpdates) { }
|
||||
|
||||
@@ -205,10 +205,13 @@ namespace Game
|
||||
// prevent decrease sessions count if session queued
|
||||
if (RemoveQueuedPlayer(old))
|
||||
decrease_session = false;
|
||||
|
||||
m_sessionsByBnetGuid.Remove(old.GetBattlenetAccountGUID(), old);
|
||||
}
|
||||
}
|
||||
|
||||
m_sessions[s.GetAccountId()] = s;
|
||||
m_sessionsByBnetGuid.Add(s.GetBattlenetAccountGUID(), s);
|
||||
|
||||
int Sessions = GetActiveAndQueuedSessionCount();
|
||||
uint pLimit = GetPlayerAmountLimit();
|
||||
@@ -1876,6 +1879,7 @@ namespace Game
|
||||
|
||||
RemoveQueuedPlayer(session);
|
||||
m_sessions.TryRemove(pair.Key, out _);
|
||||
m_sessionsByBnetGuid.Remove(session.GetBattlenetAccountGUID(), session);
|
||||
session.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -2206,6 +2210,15 @@ namespace Game
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsBattlePetJournalLockAcquired(ObjectGuid battlenetAccountGuid)
|
||||
{
|
||||
foreach (var sessionForBnet in m_sessionsByBnetGuid.LookupByKey(battlenetAccountGuid))
|
||||
if (sessionForBnet.GetBattlePetMgr().HasJournalLock())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LoadWorldStates()
|
||||
{
|
||||
uint oldMSTime = Time.GetMSTime();
|
||||
@@ -2429,6 +2442,7 @@ namespace Game
|
||||
long blackmarket_timer;
|
||||
|
||||
ConcurrentDictionary<uint, WorldSession> m_sessions = new();
|
||||
MultiMap<ObjectGuid, WorldSession> m_sessionsByBnetGuid = new();
|
||||
Dictionary<uint, long> m_disconnects = new();
|
||||
uint m_maxActiveSessionCount;
|
||||
uint m_maxQueuedSessionCount;
|
||||
|
||||
@@ -160,6 +160,10 @@ namespace Game
|
||||
// Remove pet
|
||||
_player.RemovePet(null, PetSaveMode.AsCurrent, true);
|
||||
|
||||
///- Release battle pet journal lock
|
||||
if (_battlePetMgr.HasJournalLock())
|
||||
_battlePetMgr.ToggleJournalLock(false);
|
||||
|
||||
// Clear whisper whitelist
|
||||
_player.ClearWhisperWhiteList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user