Core/Conditions: Implemented new condition type CONDITION_BATTLE_PET_COUNT to check how many copies of a battle pet are collected (#27689)

Co-authored-by: Shauren <shauren.trinity@gmail.com>
This commit is contained in:
Antonio Martín Berti
2022-02-06 14:57:19 -03:00
committed by GitHub
parent 3fa4c04919
commit b5a67cf17d
2 changed files with 32 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#include "AchievementMgr.h"
#include "AreaTrigger.h"
#include "AreaTriggerDataStore.h"
#include "BattlePetMgr.h"
#include "Containers.h"
#include "ConversationDataStore.h"
#include "DatabaseEnv.h"
@@ -144,6 +145,7 @@ ConditionMgr::ConditionTypeInfo const ConditionMgr::StaticConditionTypeData[COND
{ "Is Gamemaster", true, false, false },
{ "Object Entry or Guid", true, true, true },
{ "Object TypeMask", true, false, false },
{ "BattlePet Species Learned", true, true, true },
};
// Checks if object meets the condition
@@ -564,6 +566,14 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo) const
}
break;
}
case CONDITION_BATTLE_PET_COUNT:
{
if (Player* player = object->ToPlayer())
condMeets = CompareValues(static_cast<ComparisionType>(ConditionValue3),
player->GetSession()->GetBattlePetMgr()->GetPetCount(sBattlePetSpeciesStore.AssertEntry(ConditionValue1), player->GetGUID()),
static_cast<uint8>(ConditionValue2));
break;
}
default:
condMeets = false;
break;
@@ -765,6 +775,9 @@ uint32 Condition::GetSearcherTypeMaskForCondition() const
case CONDITION_GAMEMASTER:
mask |= GRID_MAP_TYPE_MASK_PLAYER;
break;
case CONDITION_BATTLE_PET_COUNT:
mask |= GRID_MAP_TYPE_MASK_PLAYER;
break;
default:
ABORT_MSG("Condition::GetSearcherTypeMaskForCondition - missing condition handling!");
break;
@@ -2553,6 +2566,24 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) const
return false;
}
break;
case CONDITION_BATTLE_PET_COUNT:
if (!sBattlePetSpeciesStore.LookupEntry(cond->ConditionValue1))
{
TC_LOG_ERROR("sql.sql", "%s has non existing BattlePet SpeciesId in value1 (%u), skipped.", cond->ToString(true).c_str(), cond->ConditionValue1);
return false;
}
if (cond->ConditionValue2 > BattlePets::DEFAULT_MAX_BATTLE_PETS_PER_SPECIES)
{
TC_LOG_ERROR("sql.sql", "%s has invalid (greater than %u) value2 (%u), skipped.", cond->ToString(true).c_str(),
uint32(BattlePets::DEFAULT_MAX_BATTLE_PETS_PER_SPECIES), cond->ConditionValue2);
return false;
}
if (cond->ConditionValue3 >= COMP_TYPE_MAX)
{
TC_LOG_ERROR("sql.sql", "%s has invalid ComparisionType (%u), skipped.", cond->ToString(true).c_str(), cond->ConditionValue3);
return false;
}
break;
default:
TC_LOG_ERROR("sql.sql", "%s Invalid ConditionType in `condition` table, ignoring.", cond->ToString().c_str());
return false;

View File

@@ -109,6 +109,7 @@ enum ConditionTypes
CONDITION_GAMEMASTER = 50, // canBeGM 0 0 true if player is gamemaster (or can be gamemaster)
CONDITION_OBJECT_ENTRY_GUID = 51, // TypeID entry guid true if object is type TypeID and the entry is 0 or matches entry of the object or matches guid of the object
CONDITION_TYPE_MASK = 52, // TypeMask 0 0 true if object is type object's TypeMask matches provided TypeMask
CONDITION_BATTLE_PET_COUNT = 53, // SpecieId count ComparisonType true if player has `count` of battle pet species
CONDITION_MAX
};