44 bool BattlePetNameMatches(std::string
const& left, std::string
const& right)
46 return !left.empty() && !right.empty() && !stricmp(left.c_str(), right.c_str());
54 return uint8(std::min<uint32>(100, health * 100 / maxHealth));
57 float BattlePetTrapFailedAttemptBonus(
uint32 trapAbility)
74 float BattlePetTrapCaptureChance(
uint32 trapAbility,
uint8 failedAttempts)
80 float const bonus = BattlePetTrapFailedAttemptBonus(trapAbility);
81 for (
uint8 i = 0; i < failedAttempts; ++i)
82 chance += (100.0f - chance) * bonus / 100.0f;
84 return std::min<float>(99.0f, chance);
103 Field* fields = result->Fetch();
107 std::string nickname = fields[2].
GetString();
121 SF_LOG_ERROR(
"sql.sql",
"Species %u defined in `account_battle_pet` for Battle Pet %lu does not exist, skipped.", speciesId, (
uint64)
id);
127 SF_LOG_ERROR(
"sql.sql",
"Breed %u defined in `account_battle_pet` for Battle Pet %lu does not exist, skipped.", breedId, (
uint64)
id);
134 SF_LOG_ERROR(
"sql.sql",
"Quality %u defined in `account_battle_pet` for Battle Pet %lu is invalid, skipped.", quality, (
uint64)
id);
141 SF_LOG_ERROR(
"sql.sql",
"Level %u defined in `account_battle_pet` for Battle Pet %lu is invalid, skipped.", level, (
uint64)
id);
146 health, maxHealth, power, speed, quality, breedId, flags);
149 }
while (result->NextRow());
237 Field* fields = result->Fetch();
257 std::set<uint8> slotErrors;
266 for (std::set<uint8>::const_iterator citr = slotErrors.begin(); citr != slotErrors.end(); ++citr)
268 SF_LOG_ERROR(
"sql.sql",
"Battle Pet slot %u in `account_battle_pet_slots` for account %u is invalid!",
269 *citr,
m_owner->GetSession()->GetAccountId());
272 bool hasError = slotErrors.size() > 0;
305 if ((*itr)->GetId() ==
id)
346 CreatureTemplate const* creatureTemplate = GetBattlePetCreatureTemplate(battlePet);
347 return creatureTemplate ? creatureTemplate->
Name : std::string();
352 std::vector<BattlePet*> matches;
362 if (BattlePetNameMatches(battlePet->
GetNickname(), name))
363 matches.push_back(battlePet);
366 if (!matches.empty())
376 matches.push_back(battlePet);
554 bool updated =
false;
575 uint8 const quality =
sObjectMgr->BattlePetGetRandomQuality(speciesId);
576 return Create(speciesId, level, quality);
581 return Create(speciesId, level, quality,
sObjectMgr->BattlePetGetRandomBreed(speciesId), notification);
598 breed =
sObjectMgr->BattlePetGetRandomBreed(speciesId);
670 if (health <= battlePet->GetCurrentHealth())
684 enemyPetId, enemyMaxHealth, enemyHealth, enemySpecies, enemyLevel, enemyQuality, enemyBreed, allyFrontPet);
694 enemyPetId, enemyMaxHealth, enemyHealth, enemySpecies, enemyLevel, enemyQuality,
695 allyFrontPet, enemyFrontPet, source);
705 m_owner->UpdateVisibilityOf(creature);
752 else if (creature->ToTempSummon())
753 creature->DespawnOrUnsummon();
756 if (creature->IsAlive())
759 creature->RemoveCorpse();
760 creature->SaveRespawnTime();
784 m_owner->UpdateVisibilityOf(creature);
811 bool const enemyTameable = enemySpecies
845 abilitySlot, abilityId, abilityCooldown);
865 uint32 allyIncomingDamageReduction,
uint8 allyIncomingDamageReductionRounds,
866 uint32 enemyIncomingDamageReduction,
uint8 enemyIncomingDamageReductionRounds,
871 allyIncomingDamageReduction, allyIncomingDamageReductionRounds);
873 enemyIncomingDamageReduction, enemyIncomingDamageReductionRounds);
878 allyAbilitySlot, allyAbilityId, allyAbilityCooldown, allyTurn, enemyTurn))
948 if (!
m_activePetBattle.ApplyTrapRoundWithEnemyResponse(roundId, captured, enemyDamage, trapTurn, enemyTurn))
1041 std::set<uint16> species;
1052 return uint32(species.size());
1056 uint16 speciesId,
uint8 quality,
bool won,
bool captured)
const
1129 if (!
m_owner || finalLevel <= initialLevel)
1133 for (
uint8 level = initialLevel + 1; level <= finalLevel; ++level)
1165 std::vector<Skyfire::BattlePetPackets::BattlePetFinalRoundPet> pets;
1173 uint8 const initialLevel = battlePet ? battlePet->
GetLevel() : 0;
1174 bool const petEarnedExperience = awardExperience && i ==
m_activePetBattle.AllyFrontPet
1177 battlePet, petEarnedExperience);
1178 uint8 const finalLevel = battlePet ? battlePet->
GetLevel() : initialLevel;
1179 uint16 const finalXp = battlePet ? battlePet->
GetXp() : 0;
1188 allyPet.
Xp = finalXp;
1191 allyPet.
AwardedXP = awardedXp != 0 || finalLevel != initialLevel;
1192 pets.push_back(allyPet);
1195 if (awardExperience)
1207 pets.push_back(enemyPet);
1226 m_owner->GetSession()->SendPacket(&data);
1232 m_owner->GetSession()->SendPacket(&data);
1241 m_owner->GetSession()->SendPacket(&data);
1253 size_t writePos = data.
bitwpos();
1265 CreatureTemplate const* creatureTemplate = GetBattlePetCreatureTemplate(battlePet);
1266 if (!creatureTemplate)
1347 slotData <<
uint8(i);
1351 data.
PutBits(writePos, petCount, 19);
1354 data.
append(journalData);
1357 m_owner->GetSession()->SendPacket(&data);
1395 data <<
uint8(slot);
1398 m_owner->GetSession()->SendPacket(&data);
1408 CreatureTemplate const* creatureTemplate = GetBattlePetCreatureTemplate(battlePet);
1409 if (!creatureTemplate)
1462 m_owner->GetSession()->SendPacket(&data);
uint16 BattlePetExperienceReward(uint8 petLevel, uint8 enemyLevel, uint8 participatingPetCount)
uint16 BattlePetHealthFromPercent(uint16 maxHealth, uint8 percent)
uint32 BattlePetSpeciesFamilyMask(uint16 speciesId)
uint32 BattlePetSpeciesNpcId(uint16 speciesId)
@ BATTLE_PET_DB_STATE_NONE
@ BATTLE_PET_DB_STATE_DELETE
@ BATTLE_PET_DB_STATE_SAVE
BattlePetAchievementSource
#define BATTLE_PET_MAX_LEVEL
uint8 BattlePetCapturedLevel(uint8 level)
@ PET_BATTLE_TRAP_STATUS_UNAVAILABLE
@ PET_BATTLE_TRAP_STATUS_ACTIVE
@ PET_BATTLE_WINNER_ENEMY
uint8 BattlePetLoadoutSlotForAchievement(uint32 achievementId)
@ BATTLE_PET_ABILITY_STRONG_TRAP
@ BATTLE_PET_ABILITY_GM_TRAP
@ BATTLE_PET_ABILITY_TRAP
@ BATTLE_PET_ABILITY_PRISTINE_TRAP
@ SPELL_REVIVE_BATTLE_PETS
@ SPELL_BATTLE_PET_TRAINING_PASSIVE
@ BATTLE_PET_ACHIEVEMENT_JUST_A_PUP
@ BATTLE_PET_ACHIEVEMENT_NEWBIE
#define BATTLE_PET_MAX_LOADOUT_SLOTS
#define BATTLE_PET_MAX_JOURNAL_SPECIES
@ BATTLE_PET_LOADOUT_SLOT_NONE
@ BATTLE_PET_LOADOUT_SLOT_1
@ BATTLE_PET_LOADOUT_SLOT_3
@ BATTLE_PET_LOADOUT_SLOT_2
#define BATTLE_PET_MAX_JOURNAL_PETS
@ BATTLE_PET_LOADOUT_SLOT_FLAG_SLOT_1
@ BATTLE_PET_LOADOUT_SLOT_FLAG_SLOT_2
@ BATTLE_PET_LOADOUT_SLOT_FLAG_SLOT_3
@ BATTLE_PET_LOADOUT_SLOT_FLAG_NONE
@ BATTLE_PET_LOADOUT_TRAP
uint32 BattlePetTrapAbilityForLoadoutFlags(uint8 flags)
#define sBattlePetSpawnMgr
@ CHAR_DEL_ACCOUNT_BATTLE_PET
@ CHAR_INS_ACCOUNT_BATTLE_PET
@ CHAR_DEL_ACCOUNT_BATTLE_PET_SLOTS
@ CHAR_INS_ACCOUNT_BATTLE_PET_SLOTS
@ BATTLE_PET_FLAG_NOT_TAMEABLE
bool BattlePetSpeciesHasFlag(uint16 speciesId, uint16 flag)
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore(BattlePetSpeciesfmt)
BattlePetBreedSet sBattlePetBreedSet
uint32 BattlePetGetSummonSpell(uint16 speciesId)
@ ACHIEVEMENT_CRITERIA_TYPE_REACH_BATTLE_PET_LEVEL
@ ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL
@ ACHIEVEMENT_CRITERIA_TYPE_OWN_BATTLE_PET_COUNT
@ ACHIEVEMENT_CRITERIA_TYPE_COLLECT_BATTLE_PET_SPECIES
@ ACHIEVEMENT_CRITERIA_TYPE_CAPTURE_BATTLE_PET
@ ACHIEVEMENT_CRITERIA_TYPE_CAPTURE_BATTLE_PET2
@ ACHIEVEMENT_CRITERIA_TYPE_COLLECT_BATTLE_PET
@ ACHIEVEMENT_CRITERIA_TYPE_WIN_PET_BATTLE
#define SF_LOG_ERROR(filterType__,...)
@ PLAYER_FLAGS_BATTLE_PET_ENABLED
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Skyfire::AutoPtr< Transaction, Skyfire::Mutex > SQLTransaction
@ UNIT_FLAG_IMMUNE_TO_NPC
@ PLAYER_FIELD_PLAYER_FLAGS
bool roll_chance_f(float chance)
void SetCurrentHealth(uint16 health)
uint16 GetCurrentHealth() const
uint16 GetSpecies() const
uint16 GetMaxHealth() const
std::string GetNickname() const
void SetDbState(BattlePetDbState state)
uint16 AddExperience(uint16 xp)
BattlePetDbState GetDbState() const
uint32 GetTimestamp() const
bool SetActivePetBattleAllyPet(uint8 petIndex, uint64 petId, uint32 maxHealth, uint32 health)
void ClearActivePetBattleWorldObjectState()
uint8 GetLoadoutFlags() const
uint16 RewardActivePetBattlePet(BattlePet *battlePet, bool awardExperience)
void OnAchievementEarned(uint32 achievementId)
void StartPvpPetBattle(uint64 opponentGuid, uint64 allyPetId, uint32 allyMaxHealth, uint32 allyHealth, uint64 enemyPetId, uint32 enemyMaxHealth, uint32 enemyHealth, uint16 enemySpecies=0, uint8 enemyLevel=0, uint8 enemyQuality=0, uint8 allyFrontPet=0, uint8 enemyFrontPet=3, BattlePetAchievementSource source=BATTLE_PET_ACHIEVEMENT_SOURCE_PVP_DUEL)
bool ApplyBattlePetAbilityInput(uint32 roundId, uint32 damage, uint32 abilityEffectId, uint8 abilitySlot, uint32 abilityId, uint16 abilityCooldown, Skyfire::BattlePetPackets::BattlePetRoundResult &round, Skyfire::BattlePetPackets::BattlePetFinalRound *finalRound=NULL)
uint8 GetActivePetBattleTrapStatus() const
void ClearActivePetBattlePlayerState()
uint32 GetTrapAbility() const
void HideActivePetBattleWorldObject(Creature *creature)
uint32 GetBattlePetCount() const
void SetLoadoutFlag(uint8 flag)
void SendBattlePetJournal()
void Delete(BattlePet *battlePet)
bool HasLoadoutFlag(uint8 flag) const
void ClearActivePetBattle()
BattlePet * GetFirstAliveLoadoutBattlePet() const
bool m_petBattlePvpQueued
void ResummonLastBattlePet()
void UpdateCapturedBattlePetAchievements(BattlePet const &battlePet)
bool ApplyBattlePetAbilityExchangeInput(uint32 roundId, uint32 allyDamage, uint32 allyAbilityEffectId, uint8 allyAbilitySlot, uint32 allyAbilityId, uint16 allyAbilityCooldown, uint32 enemyDamage, uint32 enemyAbilityEffectId, uint32 allyIncomingDamageReduction, uint8 allyIncomingDamageReductionRounds, uint32 enemyIncomingDamageReduction, uint8 enemyIncomingDamageReductionRounds, Skyfire::BattlePetPackets::BattlePetRoundResult &round, Skyfire::BattlePetPackets::BattlePetFinalRound *finalRound=NULL)
void PersistActivePetBattleHealth()
void SyncAchievementLoadoutRewards()
std::string GetBattlePetSpeciesName(BattlePet const *battlePet) const
uint64 m_activePetBattleWorldObjectGuid
void SendBattlePetSlotUpdate(uint8 slot, bool notification, uint64 id=0)
uint32 GetUniqueBattlePetSpeciesCount() const
bool m_activePetBattleWorldObjectHidden
void UpdateFinishedPetBattleAchievements()
void FinishActivePetBattle(uint8 winner)
bool ApplyBattlePetTrapInput(uint32 roundId, uint32 trapAbilityEffectId, uint32 enemyDamage, uint32 enemyAbilityEffectId, Skyfire::BattlePetPackets::BattlePetRoundResult &round, Skyfire::BattlePetPackets::BattlePetFinalRound &finalRound)
BattlePet * Create(uint16 speciesId)
BattlePetSet m_battlePetSet
uint64 m_loadout[BATTLE_PET_MAX_LOADOUT_SLOTS]
bool ApplyEnemyBattlePetDamage(uint32 damage, uint32 abilityEffectId, Skyfire::BattlePetPackets::BattlePetRoundResult &round)
bool ApplyBattlePetSwapInput(uint32 roundId, uint8 newFrontPet, Skyfire::BattlePetPackets::BattlePetRoundResult &round)
void SendBattlePetJournalLock()
ActivePetBattle m_activePetBattle
bool ApplyAchievementLoadoutReward(uint32 achievementId)
void LoadSlotsFromDb(PreparedQueryResult result)
uint64 GetLoadoutSlot(uint8 slot) const
BattlePetAchievementContext BuildActivePetBattleAchievementContext(uint16 speciesId, uint8 quality, bool won, bool captured) const
uint8 GetLoadoutSlotForBattlePet(uint64 id) const
bool HasLoadoutSlot(uint8 slot) const
void ApplyActivePetBattleRoundState(Skyfire::BattlePetPackets::BattlePetRoundResult &round) const
void LoadFromDb(PreparedQueryResult result)
void StartWildPetBattle(uint64 enemyGuid, uint64 allyPetId, uint32 allyMaxHealth, uint32 allyHealth, uint64 enemyPetId, uint32 enemyMaxHealth, uint32 enemyHealth, uint16 enemySpecies=0, uint8 enemyLevel=0, uint8 enemyQuality=0, uint8 enemyBreed=0, uint8 allyFrontPet=0)
void DespawnResolvedWildPetBattleWorldObject()
bool ApplyBattlePetForfeitInput(uint32 roundId, Skyfire::BattlePetPackets::BattlePetFinalRound &finalRound)
void SaveSlotsToDb(SQLTransaction &trans)
BattlePet * GetBattlePet(uint64 id) const
void UpdateBattlePetLevelAchievement(BattlePet const &battlePet, uint8 initialLevel, uint8 finalLevel)
void SetLoadoutSlot(uint8 slot, uint64 id, bool save=false)
void SendBattlePetUpdate(BattlePet *battlePet, bool notification)
bool BuildActivePetBattleFinalRound(bool abandoned, Skyfire::BattlePetPackets::BattlePetFinalRound &finalRound, bool captured=false)
bool CanCreateBattlePet(uint16 speciesId) const
void SendBattlePetDeleted(uint64 id)
bool m_activePetBattlePlayerStateApplied
void UnSummonCurrentBattlePet(bool temporary)
void ApplyActivePetBattlePlayerState(float faceX, float faceY)
void SendPetBattleRequestFailed(uint8 reason)
std::vector< BattlePet * > FindBattlePetNameMatches(std::string const &name) const
void HealBattlePets(uint8 percent)
bool HasLoadoutBattlePet() const
void UpdateBattlePetCollectionAchievements(BattlePet const *battlePet=NULL)
bool SelectActivePetBattleFrontPet(uint8 frontPet)
void UnlockLoadoutSlot(uint8 slot)
void WriteGuidBytes(const ObjectGuid &guid, Offsets... offsets)
bool WriteBit(uint32 bit)
void WriteGuidMask(const ObjectGuid &guid, Offsets... offsets)
size_t bitwpos() const
Returns position of last written bit.
void WriteString(std::string const &str)
void PutBits(size_t pos, T value, uint32 bitCount)
void WriteBits(T value, size_t bits)
void WriteByteSeq(uint8 b)
std::string GetString() const
static Creature * GetCreature(WorldObject const &u, uint64 guid)
void setString(const uint8 index, const std::string &value)
void setUInt16(const uint8 index, const uint16 value)
void setUInt64(const uint8 index, const uint64 value)
void setUInt32(const uint8 index, const uint32 value)
void setUInt8(const uint8 index, const uint8 value)
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
@ SMSG_BATTLE_PET_JOURNAL_LOCK_ACQUIRED
@ SMSG_BATTLE_PET_SLOT_UPDATE
@ SMSG_BATTLE_PET_JOURNAL
@ SMSG_BATTLE_PET_PET_UPDATES
@ SMSG_BATTLE_PET_DELETED
@ CONFIG_BATTLE_PET_INITIAL_LEVEL
WorldPacket BuildRequestFailedPacket(uint8 reason)
BattlePetRoundResult BuildRoundResultFromTurn(ActivePetBattleTurn const &turn, uint32 abilityEffectId)
@ BATTLE_PET_ROUND_INPUT_FLAG_SELECT_NEW_FRONT_PET
BattlePetRoundEffect BuildCatchEffect(uint8 casterPet, uint8 targetPet, uint32 abilityEffectId, bool captured, uint16 turnInstanceId)
BattlePetRoundEffect BuildDamageEffect(uint8 casterPet, uint8 targetPet, int32 remainingHealth, uint32 abilityEffectId, uint16 turnInstanceId)
void AppendRoundCooldowns(BattlePetRoundResult &round, ActivePetBattleTurn const &turn)
BattlePetFinalRound BuildFinalRoundState(bool allyWon, bool abandoned, std::vector< BattlePetFinalRoundPet > const &pets)
void MarkRoundResultAsCatchOrKill(BattlePetRoundResult &round)
static constexpr uint8 BATTLE_PET_MAX_ACTIVE_TEAM_PETS
BattlePetAchievementSource Source
std::vector< BattlePetRoundEffect > Effects
std::vector< uint8 > DeadPets