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