Core/BattlePets: Misc fixes

This commit is contained in:
hondacrx
2018-01-02 13:00:19 -05:00
parent ba92c58e6c
commit c7798c00fc
7 changed files with 51 additions and 43 deletions
+33 -3
View File
@@ -333,9 +333,14 @@ namespace Game.BattlePets
_owner.SendPacket(updates);
}
public List<BattlePet> GetLearnedPets()
public ushort GetMaxPetLevel()
{
return _pets.Values.Where(p => p.SaveInfo != BattlePetSaveInfo.Removed).ToList();
ushort level = 0;
foreach (var pet in _pets)
if (pet.Value.SaveInfo != BattlePetSaveInfo.Removed)
level = Math.Max(level, pet.Value.PacketInfo.Level);
return level;
}
public void CageBattlePet(ObjectGuid guid)
@@ -359,7 +364,7 @@ namespace Game.BattlePets
item.SetModifier(ItemModifier.BattlePetDisplayId, pet.PacketInfo.CreatureID);
// FIXME: "You create: ." - item name missing in chat
_owner.GetPlayer().SendNewItem(item, 1, true, true);
_owner.GetPlayer().SendNewItem(item, 1, true, false);
RemovePet(guid);
@@ -401,11 +406,36 @@ namespace Game.BattlePets
return;
// TODO: set proper CreatureID for spell DEFAULT_SUMMON_BATTLE_PET_SPELL (default EffectMiscValueA is 40721 - Murkimus the Gladiator)
_owner.GetPlayer().SetGuidValue(PlayerFields.SummonedBattlePetId, guid);
_owner.GetPlayer().CastSpell(_owner.GetPlayer(), speciesEntry.SummonSpellID != 0 ? speciesEntry.SummonSpellID : SharedConst.DefaultSummonBattlePetSpell);
// TODO: set pet level, quality... update fields
}
public void DismissPet()
{
Player ownerPlayer = _owner.GetPlayer();
Creature pet = ObjectAccessor.GetCreatureOrPetOrVehicle(ownerPlayer, ownerPlayer.GetCritterGUID());
if (pet && ownerPlayer.GetGuidValue(PlayerFields.SummonedBattlePetId) == pet.GetGuidValue(UnitFields.BattlePetCompanionGuid))
{
pet.DespawnOrUnsummon();
ownerPlayer.SetGuidValue(PlayerFields.SummonedBattlePetId, ObjectGuid.Empty);
}
}
public void SendJournal()
{
BattlePetJournal battlePetJournal = new BattlePetJournal();
battlePetJournal.Trap = _trapLevel;
foreach (var pet in _pets)
if (pet.Value.SaveInfo != BattlePetSaveInfo.Removed)
battlePetJournal.Pets.Add(pet.Value.PacketInfo);
battlePetJournal.Slots = _slots;
_owner.SendPacket(battlePetJournal);
}
void SendUpdates(List<BattlePet> pets, bool petAdded)
{
BattlePetUpdates updates = new BattlePetUpdates();
+2 -2
View File
@@ -2565,10 +2565,10 @@ namespace Game.Entities
//packet.QuestLogItemID;
packet.Quantity = quantity;
packet.QuantityInInventory = GetItemCount(item.GetEntry());
//packet.DungeonEncounterID;
//packet.DungeonEncounterID;
packet.BattlePetSpeciesID = (int)item.GetModifier(ItemModifier.BattlePetSpeciesId);
packet.BattlePetBreedID = (int)item.GetModifier(ItemModifier.BattlePetBreedData) & 0xFFFFFF;
packet.BattlePetBreedQuality = (item.GetModifier(ItemModifier.BattlePetBreedData) >> 24) & 0xFF;
packet.BattlePetSpeciesID = (int)item.GetModifier(ItemModifier.BattlePetSpeciesId);
packet.BattlePetLevel = (int)item.GetModifier(ItemModifier.BattlePetLevel);
packet.ItemGUID = item.GetGUID();
+4
View File
@@ -199,7 +199,11 @@ namespace Game.Entities
AddGuidValue(UnitFields.Summon, minion.GetGUID());
if (minion.m_Properties != null && minion.m_Properties.Type == SummonType.Minipet)
{
SetCritterGUID(minion.GetGUID());
if (GetTypeId() == TypeId.Player)
minion.SetGuidValue(UnitFields.BattlePetCompanionGuid, GetGuidValue(PlayerFields.SummonedBattlePetId));
}
// PvP, FFAPvP
minion.SetByteValue(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag, GetByteValue(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag));
+5 -10
View File
@@ -27,15 +27,7 @@ namespace Game
[WorldPacketHandler(ClientOpcodes.BattlePetRequestJournal)]
void HandleBattlePetRequestJournal(BattlePetRequestJournal battlePetRequestJournal)
{
// TODO: Move this to BattlePetMgr::SendJournal() just to have all packets in one file
BattlePetJournal battlePetJournal = new BattlePetJournal();
battlePetJournal.Trap = GetBattlePetMgr().GetTrapLevel();
foreach (var battlePet in GetBattlePetMgr().GetLearnedPets())
battlePetJournal.Pets.Add(battlePet.PacketInfo);
battlePetJournal.Slots = GetBattlePetMgr().GetSlots();
SendPacket(battlePetJournal);
GetBattlePetMgr().SendJournal();
}
[WorldPacketHandler(ClientOpcodes.BattlePetSetBattleSlot)]
@@ -90,7 +82,10 @@ namespace Game
[WorldPacketHandler(ClientOpcodes.BattlePetSummon, Processing = PacketProcessing.Inplace)]
void HandleBattlePetSummon(BattlePetSummon battlePetSummon)
{
GetBattlePetMgr().SummonPet(battlePetSummon.PetGuid);
if (_player.GetGuidValue(PlayerFields.SummonedBattlePetId) != battlePetSummon.PetGuid)
GetBattlePetMgr().SummonPet(battlePetSummon.PetGuid);
else
GetBattlePetMgr().DismissPet();
}
}
}
@@ -268,7 +268,7 @@ namespace Game.Network.Packets
public ObjectGuid Guid;
public uint Species;
public uint CreatureID;
public uint CollarID; // what's this?
public uint CollarID;
public ushort Breed;
public ushort Level;
public ushort Exp;
@@ -294,7 +294,7 @@ namespace Game.Network.Packets
}
public BattlePetStruct Pet;
public uint CollarID; // what's this?
public uint CollarID;
public byte Index;
public bool Locked = true;
}
+2 -2
View File
@@ -424,9 +424,9 @@ namespace Game.Network.Packets
_worldPacket.WriteUInt32(Quantity);
_worldPacket.WriteUInt32(QuantityInInventory);
_worldPacket.WriteUInt32(DungeonEncounterID);
_worldPacket.WriteInt32(BattlePetSpeciesID);
_worldPacket.WriteInt32(BattlePetBreedID);
_worldPacket.WriteUInt32(BattlePetBreedQuality);
_worldPacket.WriteInt32(BattlePetSpeciesID);
_worldPacket.WriteInt32(BattlePetLevel);
_worldPacket.WritePackedGuid(ItemGUID);
_worldPacket.WriteBit(Pushed);
@@ -448,9 +448,9 @@ namespace Game.Network.Packets
public uint Quantity;
public uint QuantityInInventory;
public int DungeonEncounterID;
public int BattlePetSpeciesID;
public int BattlePetBreedID;
public uint BattlePetBreedQuality;
public int BattlePetSpeciesID;
public int BattlePetLevel;
public ObjectGuid ItemGUID;
public bool Pushed;
+3 -24
View File
@@ -1900,23 +1900,6 @@ namespace Game.Spells
uint spellToLearn = (m_spellInfo.Id == 483 || m_spellInfo.Id == 55884) ? (uint)damage : effectInfo.TriggerSpell;
player.LearnSpell(spellToLearn, false);
if (m_spellInfo.Id == 55884)
{
BattlePetMgr battlePetMgr = player.GetSession().GetBattlePetMgr();
if (battlePetMgr != null)
{
foreach (var entry in CliDB.BattlePetSpeciesStorage.Values)
{
if (entry.SummonSpellID == spellToLearn)
{
battlePetMgr.AddPet(entry.Id, entry.CreatureID);
player.UpdateCriteria(CriteriaTypes.OwnBattlePetCount);
break;
}
}
}
}
Log.outDebug(LogFilter.Spells, "Spell: Player {0} has learned spell {1} from NpcGUID={2}", player.GetGUID().ToString(), spellToLearn, m_caster.GetGUID().ToString());
}
@@ -5634,14 +5617,9 @@ namespace Game.Spells
if (battlePetMgr == null)
return;
ushort maxLearnedLevel = 0;
foreach (var pet in battlePetMgr.GetLearnedPets())
maxLearnedLevel = Math.Max(pet.PacketInfo.Level, maxLearnedLevel);
// TODO: This means if you put your highest lvl pet into cage, you won't be able to uncage it again which is probably wrong.
// We will need to store maxLearnedLevel somewhere to avoid this behaviour.
if (maxLearnedLevel < level)
if (battlePetMgr.GetMaxPetLevel() < level)
{
battlePetMgr.SendError(BattlePetError.TooHighLevelToUncage, creatureId); // or speciesEntry.CreatureID
SendCastResult(SpellCastResult.CantAddBattlePet);
@@ -5655,10 +5633,11 @@ namespace Game.Spells
return;
}
battlePetMgr.AddPet(speciesId, creatureId, breed, quality, level);
if (!plr.HasSpell(speciesEntry.SummonSpellID))
plr.LearnSpell(speciesEntry.SummonSpellID, false);
battlePetMgr.AddPet(speciesId, creatureId, breed, quality, level);
plr.DestroyItem(m_CastItem.GetBagSlot(), m_CastItem.GetSlot(), true);
m_CastItem = null;
}