From 1a2251e58d29676c1192606dbb43ff666ca641b7 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 4 May 2022 10:31:48 -0400 Subject: [PATCH] Core/Conditions: Implemented new condition type CONDITION_BATTLE_PET_COUNT to check how many copies of a battle pet are collected Port From (https://github.com/TrinityCore/TrinityCore/commit/b5a67cf17dbf18369a2a3370d9d45ca6c56e8cc7) --- Source/Framework/Constants/ConditionConst.cs | 1 + Source/Game/Conditions/Condition.cs | 7 +++++++ Source/Game/Conditions/ConditionManager.cs | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/Source/Framework/Constants/ConditionConst.cs b/Source/Framework/Constants/ConditionConst.cs index 0ead1d562..9a8a1c022 100644 --- a/Source/Framework/Constants/ConditionConst.cs +++ b/Source/Framework/Constants/ConditionConst.cs @@ -72,6 +72,7 @@ namespace Framework.Constants Gamemaster = 50, // canBeGM 0 0 true if player is gamemaster (or can be gamemaster) ObjectEntryGuid = 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 TypeMask = 52, // TypeMask 0 0 true if object is type object's TypeMask matches provided TypeMask + BattlePetCount = 53, // SpecieId count ComparisonType true if player has `count` of battle pet species Max } diff --git a/Source/Game/Conditions/Condition.cs b/Source/Game/Conditions/Condition.cs index 6ca235708..f66c81ca9 100644 --- a/Source/Game/Conditions/Condition.cs +++ b/Source/Game/Conditions/Condition.cs @@ -393,6 +393,12 @@ namespace Game.Conditions } break; } + case ConditionTypes.BattlePetCount: + { + if (player != null) + condMeets = MathFunctions.CompareValues((ComparisionType)ConditionValue3, player.GetSession().GetBattlePetMgr().GetPetCount(CliDB.BattlePetSpeciesStorage.LookupByKey(ConditionValue1), player.GetGUID()), ConditionValue2); + break; + } default: condMeets = false; break; @@ -503,6 +509,7 @@ namespace Game.Conditions break; case ConditionTypes.DailyQuestDone: case ConditionTypes.ObjectiveProgress: + case ConditionTypes.BattlePetCount: mask |= GridMapTypeMask.Player; break; default: diff --git a/Source/Game/Conditions/ConditionManager.cs b/Source/Game/Conditions/ConditionManager.cs index 39b9454ed..d0b3c2c69 100644 --- a/Source/Game/Conditions/ConditionManager.cs +++ b/Source/Game/Conditions/ConditionManager.cs @@ -1724,6 +1724,23 @@ namespace Game return false; } break; + case ConditionTypes.BattlePetCount: + if (!CliDB.BattlePetSpeciesStorage.ContainsKey(cond.ConditionValue1)) + { + Log.outError(LogFilter.Sql, $"{cond.ToString(true)} has non existing BattlePet SpeciesId in value1 ({cond.ConditionValue1}), skipped."); + return false; + } + if (cond.ConditionValue2 > SharedConst.DefaultMaxBattlePetsPerSpecies) + { + Log.outError(LogFilter.Sql, $"{cond.ToString(true)} has invalid (greater than {SharedConst.DefaultMaxBattlePetsPerSpecies}) value2 ({cond.ConditionValue2}), skipped."); + return false; + } + if (cond.ConditionValue3 >= (uint)ComparisionType.Max) + { + Log.outError(LogFilter.Sql, $"{cond.ToString(true)} has invalid ComparisionType ({cond.ConditionValue3}), skipped."); + return false; + } + break; default: Log.outError(LogFilter.Sql, $"{cond.ToString()} Invalid ConditionType in `condition` table, ignoring."); return false;