Core/BattlePets: Improvements when enabling battle pets

Port From (https://github.com/TrinityCore/TrinityCore/commit/0a8f79ad5ad5afbf6a6aedc9ad46c3b774877b31)
This commit is contained in:
hondacrx
2021-12-16 13:10:24 -05:00
parent f7023cb290
commit da41af6279
5 changed files with 29 additions and 14 deletions
+15 -9
View File
@@ -31,7 +31,7 @@ namespace Game.BattlePets
public BattlePetMgr(WorldSession owner)
{
_owner = owner;
for (byte i = 0; i < SharedConst.MaxPetBattleSlots; ++i)
for (byte i = 0; i < (int)BattlePetSlots.Count; ++i)
{
BattlePetSlot slot = new();
slot.Index = i;
@@ -510,15 +510,19 @@ namespace Game.BattlePets
return (uint)speciesIds.Count;
}
public void UnlockSlot(byte slot)
public void UnlockSlot(BattlePetSlots slot)
{
if (!_slots[slot].Locked)
if (slot >= BattlePetSlots.Count)
return;
_slots[slot].Locked = false;
byte slotIndex = (byte)slot;
if (!_slots[slotIndex].Locked)
return;
_slots[slotIndex].Locked = false;
PetBattleSlotUpdates updates = new();
updates.Slots.Add(_slots[slot]);
updates.Slots.Add(_slots[slotIndex]);
updates.AutoSlotted = false; // what's this?
updates.NewSlot = true; // causes the "new slot unlocked" bubble to appear
_owner.SendPacket(updates);
@@ -609,11 +613,11 @@ namespace Game.BattlePets
if (speciesEntry == null)
return;
// TODO: set proper CreatureID for spell DEFAULT_SUMMON_BATTLE_PET_SPELL (default EffectMiscValueA is 40721 - Murkimus the Gladiator)
// TODO: set proper CreatureID for spell SPELL_SUMMON_BATTLE_PET (default EffectMiscValueA is 40721 - Murkimus the Gladiator)
Player player = _owner.GetPlayer();
player.SetSummonedBattlePetGUID(guid);
player.SetCurrentBattlePetBreedQuality(pet.PacketInfo.Quality);
player.CastSpell(_owner.GetPlayer(), speciesEntry.SummonSpellID != 0 ? speciesEntry.SummonSpellID : SharedConst.DefaultSummonBattlePetSpell);
player.CastSpell(_owner.GetPlayer(), speciesEntry.SummonSpellID != 0 ? speciesEntry.SummonSpellID : SharedConst.SpellSummonBattlePet);
}
public void DismissPet()
@@ -680,7 +684,7 @@ namespace Game.BattlePets
return Global.WorldMgr.IsBattlePetJournalLockAcquired(_owner.GetBattlenetAccountGUID());
}
public BattlePetSlot GetSlot(byte slot) { return slot < _slots.Count ? _slots[slot] : null; }
public BattlePetSlot GetSlot(BattlePetSlots slot) { return slot < BattlePetSlots.Count ? _slots[(byte)slot] : null; }
WorldSession GetOwner() { return _owner; }
public ushort GetTrapLevel() { return _trapLevel; }
@@ -688,7 +692,9 @@ namespace Game.BattlePets
public bool HasJournalLock() { return _hasJournalLock; }
public void ToggleJournalLock(bool on) { _hasJournalLock = on; }
public bool IsBattlePetSystemEnabled() { return GetSlot(BattlePetSlots.Slot0).Locked != true; }
WorldSession _owner;
bool _hasJournalLock;
ushort _trapLevel;
+4
View File
@@ -3332,6 +3332,10 @@ namespace Game.Entities
_restMgr.AddRestBonus(RestTypes.XP, time_diff * _restMgr.CalcExtraPerSec(RestTypes.XP, bubble));
}
// Unlock battle pet system if it's enabled in bnet account
if (GetSession().GetBattlePetMgr().IsBattlePetSystemEnabled())
LearnSpell(SharedConst.SpellBattlePetTraining, false);
m_achievementSys.CheckAllAchievementCriteria(this);
m_questObjectiveCriteriaMgr.CheckAllQuestObjectiveCriteria(this);
+1 -1
View File
@@ -47,7 +47,7 @@ namespace Game
BattlePetMgr.BattlePet pet = GetBattlePetMgr().GetPet(battlePetSetBattleSlot.PetGuid);
if (pet != null)
{
BattlePetSlot slot = GetBattlePetMgr().GetSlot(battlePetSetBattleSlot.Slot);
BattlePetSlot slot = GetBattlePetMgr().GetSlot((BattlePetSlots)battlePetSetBattleSlot.Slot);
if (slot != null)
slot.Pet = pet.PacketInfo;
}
+4 -4
View File
@@ -5270,12 +5270,12 @@ namespace Game.Spells
if (effectHandleMode != SpellEffectHandleMode.HitTarget)
return;
if (!unitTarget || !unitTarget.IsTypeId(TypeId.Player))
if (unitTarget == null || !unitTarget.IsPlayer())
return;
Player plr = unitTarget.ToPlayer();
plr.AddPlayerFlag(PlayerFlags.PetBattlesUnlocked);
plr.GetSession().GetBattlePetMgr().UnlockSlot(0);
Player player = unitTarget.ToPlayer();
player.AddPlayerFlag(PlayerFlags.PetBattlesUnlocked);
player.GetSession().GetBattlePetMgr().UnlockSlot(BattlePetSlots.Slot0);
}
[SpellEffectHandler(SpellEffectName.LaunchQuestChoice)]
@@ -0,0 +1,5 @@
DELETE FROM `spell_learn_spell` WHERE `entry` = 125610;
INSERT INTO `spell_learn_spell` (`entry`, `SpellID`, `Active`) VALUES
(125610,119467,1),
(125610,122026,1),
(125610,125439,1);