Пример #1
0
        public void AddPet(uint species, uint creatureId, ushort breed, byte quality, ushort level = 1)
        {
            BattlePetSpeciesRecord battlePetSpecies = CliDB.BattlePetSpeciesStorage.LookupByKey(species);

            if (battlePetSpecies == null) // should never happen
            {
                return;
            }

            BattlePet pet = new BattlePet();

            pet.PacketInfo.Guid       = ObjectGuid.Create(HighGuid.BattlePet, Global.ObjectMgr.GetGenerator(HighGuid.BattlePet).Generate());
            pet.PacketInfo.Species    = species;
            pet.PacketInfo.CreatureID = creatureId;
            pet.PacketInfo.Level      = level;
            pet.PacketInfo.Exp        = 0;
            pet.PacketInfo.Flags      = 0;
            pet.PacketInfo.Breed      = breed;
            pet.PacketInfo.Quality    = quality;
            pet.PacketInfo.Name       = "";
            pet.CalculateStats();
            pet.PacketInfo.Health = pet.PacketInfo.MaxHealth;
            pet.SaveInfo          = BattlePetSaveInfo.New;

            _pets[pet.PacketInfo.Guid.GetCounter()] = pet;

            List <BattlePet> updates = new List <BattlePet>();

            updates.Add(pet);
            SendUpdates(updates, true);

            _owner.GetPlayer().UpdateCriteria(CriteriaTypes.OwnBattlePet, species);
        }
Пример #2
0
        public void SummonPet(ObjectGuid guid)
        {
            BattlePet pet = GetPet(guid);

            if (pet == null)
            {
                return;
            }

            BattlePetSpeciesRecord speciesEntry = CliDB.BattlePetSpeciesStorage.LookupByKey(pet.PacketInfo.Species);

            if (speciesEntry == null)
            {
                return;
            }

            Player player = _owner.GetPlayer();

            player.SetBattlePetData(pet);

            CastSpellExtraArgs args = new();
            uint summonSpellId      = speciesEntry.SummonSpellID;

            if (summonSpellId == 0)
            {
                summonSpellId = SharedConst.SpellSummonBattlePet;
                args.AddSpellMod(SpellValueMod.BasePoint0, (int)speciesEntry.CreatureID);
            }
            player.CastSpell(_owner.GetPlayer(), summonSpellId, args);
        }
Пример #3
0
 private string AddInfo( BattlePet pet)
 {
     string info = pet.Name;
     if (pet.PetType == 1)
         info += " (Hum)";
     else if (pet.PetType == 2)
         info += " (Drag)";
     else if (pet.PetType == 3)
         info += " (Fly)";
     else if (pet.PetType == 4)
         info += " (Und)";
     else if (pet.PetType == 5)
         info += " (Crit)";
     else if (pet.PetType == 6)
         info += " (Mag)";
     else if (pet.PetType == 7)
         info += " (Elem)";
     else if (pet.PetType == 8)
         info += " (Beast)";
     else if (pet.PetType == 9)
         info += " (Aqua)";
     else if (pet.PetType == 10)
         info += " (Mech)";
     return info;
 }
Пример #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            BattlePet battlePet = db.BattlePet.Find(id);

            db.BattlePet.Remove(battlePet);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #5
0
 public ActionResult Edit([Bind(Include = "Id,name,hp,dmg,speed")] BattlePet battlePet)
 {
     if (ModelState.IsValid)
     {
         db.Entry(battlePet).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(battlePet));
 }
Пример #6
0
        public ActionResult Create([Bind(Include = "Id,name,hp,dmg,speed")] BattlePet battlePet)
        {
            if (ModelState.IsValid)
            {
                db.BattlePet.Add(battlePet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(battlePet));
        }
Пример #7
0
        public void ChangeBattlePetQuality(ObjectGuid guid, BattlePetBreedQuality quality)
        {
            if (!HasJournalLock())
            {
                return;
            }

            BattlePet pet = GetPet(guid);

            if (pet == null)
            {
                return;
            }

            if (quality > BattlePetBreedQuality.Rare)
            {
                return;
            }

            var battlePetSpecies = CliDB.BattlePetSpeciesStorage.LookupByKey(pet.PacketInfo.Species);

            if (battlePetSpecies != null)
            {
                if (battlePetSpecies.GetFlags().HasFlag(BattlePetSpeciesFlags.CantBattle))
                {
                    return;
                }
            }

            byte qualityValue = (byte)quality;

            if (pet.PacketInfo.Quality >= qualityValue)
            {
                return;
            }

            pet.PacketInfo.Quality = qualityValue;
            pet.CalculateStats();
            pet.PacketInfo.Health = pet.PacketInfo.MaxHealth;

            if (pet.SaveInfo != BattlePetSaveInfo.New)
            {
                pet.SaveInfo = BattlePetSaveInfo.Changed;
            }

            List <BattlePet> updates = new();

            updates.Add(pet);
            SendUpdates(updates, false);

            // UF::PlayerData::CurrentBattlePetBreedQuality isn't updated (Intended)
            // _owner.GetPlayer().SetCurrentBattlePetBreedQuality(qualityValue);
        }
Пример #8
0
        public void LoadFromDB(SQLResult petsResult, SQLResult slotsResult)
        {
            if (!petsResult.IsEmpty())
            {
                do
                {
                    uint species = petsResult.Read <uint>(1);

                    BattlePetSpeciesRecord speciesEntry = CliDB.BattlePetSpeciesStorage.LookupByKey(species);
                    if (speciesEntry != null)
                    {
                        if (GetPetCount(species) >= SharedConst.MaxBattlePetsPerSpecies)
                        {
                            Log.outError(LogFilter.Misc, "Battlenet account with id {0} has more than 3 battle pets of species {1}", _owner.GetBattlenetAccountId(), species);
                            continue;
                        }

                        BattlePet pet = new BattlePet();
                        pet.PacketInfo.Guid       = ObjectGuid.Create(HighGuid.BattlePet, petsResult.Read <ulong>(0));
                        pet.PacketInfo.Species    = species;
                        pet.PacketInfo.Breed      = petsResult.Read <ushort>(2);
                        pet.PacketInfo.Level      = petsResult.Read <ushort>(3);
                        pet.PacketInfo.Exp        = petsResult.Read <ushort>(4);
                        pet.PacketInfo.Health     = petsResult.Read <uint>(5);
                        pet.PacketInfo.Quality    = petsResult.Read <byte>(6);
                        pet.PacketInfo.Flags      = petsResult.Read <ushort>(7);
                        pet.PacketInfo.Name       = petsResult.Read <string>(8);
                        pet.PacketInfo.CreatureID = speciesEntry.CreatureID;
                        pet.SaveInfo = BattlePetSaveInfo.Unchanged;
                        pet.CalculateStats();
                        _pets[pet.PacketInfo.Guid.GetCounter()] = pet;
                    }
                } while (petsResult.NextRow());
            }

            if (!slotsResult.IsEmpty())
            {
                byte i = 0; // slots.GetRowCount() should equal MAX_BATTLE_PET_SLOTS

                do
                {
                    _slots[i].Index = slotsResult.Read <byte>(0);
                    var battlePet = _pets.LookupByKey(slotsResult.Read <ulong>(1));
                    if (battlePet != null)
                    {
                        _slots[i].Pet = battlePet.PacketInfo;
                    }
                    _slots[i].Locked = slotsResult.Read <bool>(2);
                    i++;
                } while (slotsResult.NextRow());
            }
        }
Пример #9
0
        void HandleBattlePetSetBattleSlot(BattlePetSetBattleSlot battlePetSetBattleSlot)
        {
            BattlePet pet = GetBattlePetMgr().GetPet(battlePetSetBattleSlot.PetGuid);

            if (pet != null)
            {
                BattlePetSlot slot = GetBattlePetMgr().GetSlot((BattlePetSlots)battlePetSetBattleSlot.Slot);
                if (slot != null)
                {
                    slot.Pet = pet.PacketInfo;
                }
            }
        }
Пример #10
0
        // GET: BattlePets/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BattlePet battlePet = db.BattlePet.Find(id);

            if (battlePet == null)
            {
                return(HttpNotFound());
            }
            return(View(battlePet));
        }
Пример #11
0
        public void ClearFanfare(ObjectGuid guid)
        {
            BattlePet pet = GetPet(guid);

            if (pet == null)
            {
                return;
            }

            pet.PacketInfo.Flags &= (ushort)~BattlePetDbFlags.FanfareNeeded;

            if (pet.SaveInfo != BattlePetSaveInfo.New)
            {
                pet.SaveInfo = BattlePetSaveInfo.Changed;
            }
        }
Пример #12
0
        public void RemovePet(ObjectGuid guid)
        {
            if (!HasJournalLock())
            {
                return;
            }

            BattlePet pet = GetPet(guid);

            if (pet == null)
            {
                return;
            }

            pet.SaveInfo = BattlePetSaveInfo.Removed;
        }
Пример #13
0
        public void RemovePet(ObjectGuid guid)
        {
            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);*/
        }
Пример #14
0
        void HandleQueryBattlePetName(QueryBattlePetName queryBattlePetName)
        {
            QueryBattlePetNameResponse response = new();

            response.BattlePetID = queryBattlePetName.BattlePetID;

            Creature summonedBattlePet = ObjectAccessor.GetCreatureOrPetOrVehicle(_player, queryBattlePetName.UnitGUID);

            if (!summonedBattlePet || !summonedBattlePet.IsSummon())
            {
                SendPacket(response);
                return;
            }

            response.CreatureID = summonedBattlePet.GetEntry();
            response.Timestamp  = summonedBattlePet.GetBattlePetCompanionNameTimestamp();

            Unit petOwner = summonedBattlePet.ToTempSummon().GetSummonerUnit();

            if (!petOwner.IsPlayer())
            {
                SendPacket(response);
                return;
            }

            BattlePet battlePet = petOwner.ToPlayer().GetSession().GetBattlePetMgr().GetPet(queryBattlePetName.BattlePetID);

            if (battlePet == null)
            {
                SendPacket(response);
                return;
            }

            response.Name = battlePet.PacketInfo.Name;
            if (battlePet.DeclinedName != null)
            {
                response.HasDeclined   = true;
                response.DeclinedNames = battlePet.DeclinedName;
            }

            response.Allow = !response.Name.IsEmpty();

            SendPacket(response);
        }
Пример #15
0
        public void ModifyName(ObjectGuid guid, string name, DeclinedName declinedName)
        {
            if (!HasJournalLock())
            {
                return;
            }

            BattlePet pet = GetPet(guid);

            if (pet == null)
            {
                return;
            }

            pet.PacketInfo.Name = name;
            pet.NameTimestamp   = GameTime.GetGameTime();

            pet.DeclinedName = new DeclinedName();
            if (declinedName != null)
            {
                pet.DeclinedName = declinedName;
            }

            if (pet.SaveInfo != BattlePetSaveInfo.New)
            {
                pet.SaveInfo = BattlePetSaveInfo.Changed;
            }

            // Update the timestamp if the battle pet is summoned
            Player   player            = _owner.GetPlayer();
            Creature summonedBattlePet = ObjectAccessor.GetCreatureOrPetOrVehicle(player, player.GetCritterGUID());

            if (summonedBattlePet != null)
            {
                if (player.GetSummonedBattlePetGUID() == summonedBattlePet.GetBattlePetCompanionGUID())
                {
                    if (summonedBattlePet.GetBattlePetCompanionGUID() == guid)
                    {
                        summonedBattlePet.SetBattlePetCompanionNameTimestamp((uint)pet.NameTimestamp);
                    }
                }
            }
        }
Пример #16
0
        public void SummonPet(ObjectGuid guid)
        {
            BattlePet pet = GetPet(guid);

            if (pet == null)
            {
                return;
            }

            BattlePetSpeciesRecord speciesEntry = CliDB.BattlePetSpeciesStorage.LookupByKey(pet.PacketInfo.Species);

            if (speciesEntry == null)
            {
                return;
            }

            // TODO: set proper CreatureID for spell DEFAULT_SUMMON_BATTLE_PET_SPELL (default EffectMiscValueA is 40721 - Murkimus the Gladiator)
            _owner.GetPlayer().CastSpell(_owner.GetPlayer(), speciesEntry.SummonSpellID != 0 ? speciesEntry.SummonSpellID : SharedConst.DefaultSummonBattlePetSpell);

            // TODO: set pet level, quality... update fields
        }
Пример #17
0
        public void CageBattlePet(ObjectGuid guid)
        {
            BattlePet pet = GetPet(guid);

            if (pet == null)
            {
                return;
            }

            List <ItemPosCount> dest = new List <ItemPosCount>();

            if (_owner.GetPlayer().CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, SharedConst.BattlePetCageItemId, 1) != InventoryResult.Ok)
            {
                return;
            }

            Item item = _owner.GetPlayer().StoreNewItem(dest, SharedConst.BattlePetCageItemId, true);

            if (!item)
            {
                return;
            }

            item.SetModifier(ItemModifier.BattlePetSpeciesId, pet.PacketInfo.Species);
            item.SetModifier(ItemModifier.BattlePetBreedData, (uint)(pet.PacketInfo.Breed | (pet.PacketInfo.Quality << 24)));
            item.SetModifier(ItemModifier.BattlePetLevel, pet.PacketInfo.Level);
            item.SetModifier(ItemModifier.BattlePetDisplayId, pet.PacketInfo.CreatureID);

            // FIXME: "You create: ." - item name missing in chat
            _owner.GetPlayer().SendNewItem(item, 1, true, false);

            RemovePet(guid);

            BattlePetDeleted deletePet = new BattlePetDeleted();

            deletePet.PetGuid = guid;
            _owner.SendPacket(deletePet);
        }
Пример #18
0
        public void CageBattlePet(ObjectGuid guid)
        {
            if (!HasJournalLock())
            {
                return;
            }

            BattlePet pet = GetPet(guid);

            if (pet == null)
            {
                return;
            }

            var battlePetSpecies = CliDB.BattlePetSpeciesStorage.LookupByKey(pet.PacketInfo.Species);

            if (battlePetSpecies != null)
            {
                if (battlePetSpecies.GetFlags().HasFlag(BattlePetSpeciesFlags.NotTradable))
                {
                    return;
                }
            }

            if (IsPetInSlot(guid))
            {
                return;
            }

            if (pet.PacketInfo.Health < pet.PacketInfo.MaxHealth)
            {
                return;
            }

            List <ItemPosCount> dest = new();

            if (_owner.GetPlayer().CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, SharedConst.BattlePetCageItemId, 1) != InventoryResult.Ok)
            {
                return;
            }

            Item item = _owner.GetPlayer().StoreNewItem(dest, SharedConst.BattlePetCageItemId, true);

            if (!item)
            {
                return;
            }

            item.SetModifier(ItemModifier.BattlePetSpeciesId, pet.PacketInfo.Species);
            item.SetModifier(ItemModifier.BattlePetBreedData, (uint)(pet.PacketInfo.Breed | (pet.PacketInfo.Quality << 24)));
            item.SetModifier(ItemModifier.BattlePetLevel, pet.PacketInfo.Level);
            item.SetModifier(ItemModifier.BattlePetDisplayId, pet.PacketInfo.DisplayID);

            _owner.GetPlayer().SendNewItem(item, 1, true, false);

            RemovePet(guid);

            BattlePetDeleted deletePet = new();

            deletePet.PetGuid = guid;
            _owner.SendPacket(deletePet);

            // Battle pet despawns if it's summoned
            Player   player            = _owner.GetPlayer();
            Creature summonedBattlePet = player.GetSummonedBattlePet();

            if (summonedBattlePet != null)
            {
                if (summonedBattlePet.GetBattlePetCompanionGUID() == guid)
                {
                    summonedBattlePet.DespawnOrUnsummon();
                    player.SetBattlePetData(null);
                }
            }
        }
Пример #19
0
        public void GrantBattlePetExperience(ObjectGuid guid, ushort xp, BattlePetXpSource xpSource)
        {
            if (!HasJournalLock())
            {
                return;
            }

            BattlePet pet = GetPet(guid);

            if (pet == null)
            {
                return;
            }

            if (xp <= 0 || xpSource >= BattlePetXpSource.Count)
            {
                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;
            }

            var xpEntry = CliDB.BattlePetXPGameTable.GetRow(level);

            if (xpEntry == null)
            {
                return;
            }

            Player player      = _owner.GetPlayer();
            ushort nextLevelXp = (ushort)CliDB.GetBattlePetXPPerLevel(xpEntry);

            if (xpSource == BattlePetXpSource.PetBattle)
            {
                xp = (ushort)(xp * player.GetTotalAuraMultiplier(AuraType.ModBattlePetXpPct));
            }

            xp += pet.PacketInfo.Exp;

            while (xp >= nextLevelXp && level < SharedConst.MaxBattlePetLevel)
            {
                xp -= nextLevelXp;

                xpEntry = CliDB.BattlePetXPGameTable.GetRow(++level);
                if (xpEntry == null)
                {
                    return;
                }

                nextLevelXp = (ushort)CliDB.GetBattlePetXPPerLevel(xpEntry);

                player.UpdateCriteria(CriteriaType.BattlePetReachLevel, pet.PacketInfo.Species, level);
                if (xpSource == BattlePetXpSource.PetBattle)
                {
                    player.UpdateCriteria(CriteriaType.ActivelyEarnPetLevel, pet.PacketInfo.Species, level);
                }
            }

            pet.PacketInfo.Level = level;
            pet.PacketInfo.Exp   = (ushort)(level < SharedConst.MaxBattlePetLevel ? xp : 0);
            pet.CalculateStats();
            pet.PacketInfo.Health = pet.PacketInfo.MaxHealth;

            if (pet.SaveInfo != BattlePetSaveInfo.New)
            {
                pet.SaveInfo = BattlePetSaveInfo.Changed;
            }

            List <BattlePet> updates = new();

            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);
                }
            }
        }
Пример #20
0
 public void AddPetToCollection(BattlePet battlePet)
 {
     battlePetCollection.Add(battlePet);
 }
Пример #21
0
 private void PB_Pet_Load(PBwithText_v2 pB, Label label, BattlePet pet)
 {
     if (pet.Name == "nil") { pB.Text = ""; }
     else
     {
         pB.Text = AddInfo(pet);
     }
     pB.Favourite = pet.IsFavorite;
     pB.Percent = pet.HealthPercent;
     label.Text = pet.Level.ToString();
     if (pet.Rarity > 3)
         { pB.ForeColor = label.ForeColor = Color.DarkBlue; }
     else if (pet.Rarity > 2)
     { pB.ForeColor = label.ForeColor = Color.DarkGreen; }
     else
     {
         pB.ForeColor = Color.Black;
         label.ForeColor = Color.Gray;
     }
     pB.Invalidate(); label.Invalidate();
 }