diff --git a/Source/Game/BattlePets/BattlePetManager.cs b/Source/Game/BattlePets/BattlePetManager.cs index 33a6ca824..587ff1fb5 100644 --- a/Source/Game/BattlePets/BattlePetManager.cs +++ b/Source/Game/BattlePets/BattlePetManager.cs @@ -700,6 +700,59 @@ namespace Game.BattlePets } } + public void GrantBattlePetLevel(ObjectGuid guid, ushort grantedLevels) + { + if (!HasJournalLock()) + return; + + var pet = GetPet(guid); + if (pet == null) + return; + + var battlePetSpecies = CliDB.BattlePetSpeciesStorage.LookupByKey(pet.PacketInfo.Species); + if (battlePetSpecies != null) + if (battlePetSpecies.GetFlags().HasFlag(BattlePetSpeciesFlags.CantBattle)) + return; + + ushort level = pet.PacketInfo.Level; + if (level >= SharedConst.MaxBattlePetLevel) + return; + + Player player = _owner.GetPlayer(); + + while (grantedLevels > 0 && level < SharedConst.MaxBattlePetLevel) + { + ++level; + --grantedLevels; + + player.UpdateCriteria(CriteriaType.BattlePetReachLevel, pet.PacketInfo.Species, level); + } + + pet.PacketInfo.Level = level; + if (level >= SharedConst.MaxBattlePetLevel) + pet.PacketInfo.Exp = 0; + pet.CalculateStats(); + pet.PacketInfo.Health = pet.PacketInfo.MaxHealth; + + if (pet.SaveInfo != BattlePetSaveInfo.New) + pet.SaveInfo = BattlePetSaveInfo.Changed; + + List updates = new List(); + updates.Add(pet); + SendUpdates(updates, false); + + // Update battle pet related update fields + Creature summonedBattlePet = player.GetSummonedBattlePet(); + if (summonedBattlePet != null) + { + if (summonedBattlePet.GetBattlePetCompanionGUID() == guid) + { + summonedBattlePet.SetWildBattlePetLevel(pet.PacketInfo.Level); + player.SetBattlePetData(pet); + } + } + } + public void HealBattlePetsPct(byte pct) { // TODO: After each Pet Battle, any injured companion will automatically diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 5aab92d30..0f95d3108 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -5313,6 +5313,7 @@ namespace Game.Spells break; } case SpellEffectName.ChangeBattlepetQuality: + case SpellEffectName.GrantBattlepetLevel: case SpellEffectName.GrantBattlepetExperience: { Player playerCaster = m_caster.ToPlayer(); @@ -5362,7 +5363,7 @@ namespace Game.Spells return SpellCastResult.CantUpgradeBattlePet; } - if (spellEffectInfo.Effect == SpellEffectName.GrantBattlepetExperience) + if (spellEffectInfo.Effect == SpellEffectName.GrantBattlepetLevel || spellEffectInfo.Effect == SpellEffectName.GrantBattlepetExperience) if (battlePet.PacketInfo.Level >= SharedConst.MaxBattlePetLevel) return SpellCastResult.GrantPetLevelFail; diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 0174a852b..0c9969289 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -5101,6 +5101,22 @@ namespace Game.Spells garrison.ActivateBuilding((uint)effectInfo.MiscValue); } + [SpellEffectHandler(SpellEffectName.GrantBattlepetLevel)] + void EffectGrantBattlePetLevel() + { + if (effectHandleMode != SpellEffectHandleMode.HitTarget) + return; + + Player playerCaster = m_caster.ToPlayer(); + if (playerCaster == null) + return; + + if (unitTarget == null || !unitTarget.IsCreature()) + return; + + playerCaster.GetSession().GetBattlePetMgr().GrantBattlePetLevel(unitTarget.GetBattlePetCompanionGUID(), (ushort)damage); + } + [SpellEffectHandler(SpellEffectName.HealBattlepetPct)] void EffectHealBattlePetPct() {