From 10d20afa3bf7bb6adfa793614b0e0e80c51ea5cb Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 29 Nov 2021 16:31:04 -0500 Subject: [PATCH] Core/Conditions: implement CONDITION_GAMEMASTER Port From (https://github.com/TrinityCore/TrinityCore/commit/b26c2f5c130090554b6a723a540c42c88472d959) --- Source/Framework/Constants/ConditionConst.cs | 7 +- Source/Game/Conditions/Condition.cs | 270 ++++++++++--------- Source/Game/Conditions/ConditionManager.cs | 6 +- 3 files changed, 151 insertions(+), 132 deletions(-) diff --git a/Source/Framework/Constants/ConditionConst.cs b/Source/Framework/Constants/ConditionConst.cs index 72d41a168..4819ddf69 100644 --- a/Source/Framework/Constants/ConditionConst.cs +++ b/Source/Framework/Constants/ConditionConst.cs @@ -50,8 +50,8 @@ namespace Framework.Constants QuestComplete = 28, // Quest_Id 0 0 True If Player Has Quest_Id With All Objectives Complete, But Not Yet Rewarded NearCreature = 29, // Creature Entry Distance 0 True If There Is A Creature Of Entry In Range NearGameobject = 30, // Gameobject Entry Distance 0 True If There Is A Gameobject Of Entry In Range - ObjectEntryGuid = 31, // Typeid Entry 0 True If Object Is Type Typeid And The Entry Is 0 Or Matches Entry Of The Object - TypeMask = 32, // Typemask 0 0 True If Object Is Type Object'S Typemask Matches Provided Typemask + ObjectEntryGuidLegacy = 31, // LEGACY_TypeID Entry Guid True If Object Is Type Typeid And The Entry Is 0 Or Matches Entry Of The Object + TypeMaskLegacy = 32, // LEGACY_TypeMask 0 0 True If Object Is Type Object'S Typemask Matches Provided Typemask RelationTo = 33, // Conditiontarget Relationtype 0 True If Object Is In Given Relation With Object Specified By Conditiontarget ReactionTo = 34, // Conditiontarget Rankmask 0 True If Object'S Reaction Matches Rankmask Object Specified By Conditiontarget DistanceTo = 35, // Conditiontarget Distance Comparisontype True If Object And Conditiontarget Are Within Distance Given By Parameters @@ -69,6 +69,9 @@ namespace Framework.Constants Queststate = 47, // quest_id state_mask 0 true if player is in any of the provided quest states for the quest (1 = not taken, 2 = completed, 8 = in progress, 32 = failed, 64 = rewarded) ObjectiveComplete = 48, // ID 0 0 true if player has ID objective complete, but quest not yet rewarded DifficultyId = 49, // Difficulty 0 0 true is map has difficulty id + 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 Max } diff --git a/Source/Game/Conditions/Condition.cs b/Source/Game/Conditions/Condition.cs index 28645fb2f..1e290daf3 100644 --- a/Source/Game/Conditions/Condition.cs +++ b/Source/Game/Conditions/Condition.cs @@ -134,29 +134,29 @@ namespace Game.Conditions condMeets = Global.GameEventMgr.IsActiveEvent((ushort)ConditionValue1); break; case ConditionTypes.InstanceInfo: + { + var map = obj.GetMap(); + if (map.IsDungeon()) { - var map = obj.GetMap(); - if (map.IsDungeon()) + InstanceScript instance = ((InstanceMap)map).GetInstanceScript(); + if (instance != null) { - InstanceScript instance = ((InstanceMap)map).GetInstanceScript(); - if (instance != null) + switch ((InstanceInfo)ConditionValue3) { - switch ((InstanceInfo)ConditionValue3) - { - case InstanceInfo.Data: - condMeets = instance.GetData(ConditionValue1) == ConditionValue2; - break; - case InstanceInfo.Data64: - condMeets = instance.GetData64(ConditionValue1) == ConditionValue2; - break; - case InstanceInfo.BossState: - condMeets = instance.GetBossState(ConditionValue1) == (EncounterState)ConditionValue2; - break; - } + case InstanceInfo.Data: + condMeets = instance.GetData(ConditionValue1) == ConditionValue2; + break; + case InstanceInfo.Data64: + condMeets = instance.GetData64(ConditionValue1) == ConditionValue2; + break; + case InstanceInfo.BossState: + condMeets = instance.GetBossState(ConditionValue1) == (EncounterState)ConditionValue2; + break; } } - break; } + break; + } case ConditionTypes.Mapid: condMeets = obj.GetMapId() == ConditionValue1; break; @@ -204,56 +204,56 @@ namespace Game.Conditions condMeets = Convert.ToBoolean((TypeMask)ConditionValue1 & obj.ObjectTypeMask); break; case ConditionTypes.RelationTo: + { + WorldObject toObject = sourceInfo.mConditionTargets[ConditionValue1]; + if (toObject != null) { - WorldObject toObject = sourceInfo.mConditionTargets[ConditionValue1]; - if (toObject != null) + Unit toUnit = toObject.ToUnit(); + if (toUnit != null && unit != null) { - Unit toUnit = toObject.ToUnit(); - if (toUnit != null && unit != null) + switch ((RelationType)ConditionValue2) { - switch ((RelationType)ConditionValue2) - { - case RelationType.Self: - condMeets = unit == toUnit; - break; - case RelationType.InParty: - condMeets = unit.IsInPartyWith(toUnit); - break; - case RelationType.InRaidOrParty: - condMeets = unit.IsInRaidWith(toUnit); - break; - case RelationType.OwnedBy: - condMeets = unit.GetOwnerGUID() == toUnit.GetGUID(); - break; - case RelationType.PassengerOf: - condMeets = unit.IsOnVehicle(toUnit); - break; - case RelationType.CreatedBy: - condMeets = unit.GetCreatorGUID() == toUnit.GetGUID(); - break; - } + case RelationType.Self: + condMeets = unit == toUnit; + break; + case RelationType.InParty: + condMeets = unit.IsInPartyWith(toUnit); + break; + case RelationType.InRaidOrParty: + condMeets = unit.IsInRaidWith(toUnit); + break; + case RelationType.OwnedBy: + condMeets = unit.GetOwnerGUID() == toUnit.GetGUID(); + break; + case RelationType.PassengerOf: + condMeets = unit.IsOnVehicle(toUnit); + break; + case RelationType.CreatedBy: + condMeets = unit.GetCreatorGUID() == toUnit.GetGUID(); + break; } } - break; } + break; + } case ConditionTypes.ReactionTo: + { + WorldObject toObject = sourceInfo.mConditionTargets[ConditionValue1]; + if (toObject != null) { - WorldObject toObject = sourceInfo.mConditionTargets[ConditionValue1]; - if (toObject != null) - { - Unit toUnit = toObject.ToUnit(); - if (toUnit != null && unit != null) - condMeets = Convert.ToBoolean((1 << (int)unit.GetReactionTo(toUnit)) & ConditionValue2); - } - break; + Unit toUnit = toObject.ToUnit(); + if (toUnit != null && unit != null) + condMeets = Convert.ToBoolean((1 << (int)unit.GetReactionTo(toUnit)) & ConditionValue2); } + break; + } case ConditionTypes.DistanceTo: - { - WorldObject toObject = sourceInfo.mConditionTargets[ConditionValue1]; - if (toObject != null) - condMeets = MathFunctions.CompareValues((ComparisionType)ConditionValue3, obj.GetDistance(toObject), ConditionValue2); - break; - } + { + WorldObject toObject = sourceInfo.mConditionTargets[ConditionValue1]; + if (toObject != null) + condMeets = MathFunctions.CompareValues((ComparisionType)ConditionValue3, obj.GetDistance(toObject), ConditionValue2); + break; + } case ConditionTypes.Alive: if (unit != null) condMeets = unit.IsAlive(); @@ -281,19 +281,19 @@ namespace Game.Conditions condMeets = unit.HasUnitState((UnitState)ConditionValue1); break; case ConditionTypes.CreatureType: - { - Creature creature = obj.ToCreature(); - if (creature) - condMeets = (uint)creature.GetCreatureTemplate().CreatureType == ConditionValue1; - break; - } + { + Creature creature = obj.ToCreature(); + if (creature) + condMeets = (uint)creature.GetCreatureTemplate().CreatureType == ConditionValue1; + break; + } case ConditionTypes.RealmAchievement: - { - AchievementRecord achievement = CliDB.AchievementStorage.LookupByKey(ConditionValue1); - if (achievement != null && Global.AchievementMgr.IsRealmCompleted(achievement)) - condMeets = true; - break; - } + { + AchievementRecord achievement = CliDB.AchievementStorage.LookupByKey(ConditionValue1); + if (achievement != null && Global.AchievementMgr.IsRealmCompleted(achievement)) + condMeets = true; + break; + } case ConditionTypes.InWater: if (unit) condMeets = unit.IsInWater(); @@ -302,86 +302,97 @@ namespace Game.Conditions condMeets = obj.GetPhaseShift().HasVisibleMapId(ConditionValue1); break; case ConditionTypes.StandState: + { + if (unit) { - if (unit) - { - if (ConditionValue1 == 0) - condMeets = (unit.GetStandState() == (UnitStandStateType)ConditionValue2); - else if (ConditionValue2 == 0) - condMeets = unit.IsStandState(); - else if (ConditionValue2 == 1) - condMeets = unit.IsSitState(); - } - break; + if (ConditionValue1 == 0) + condMeets = (unit.GetStandState() == (UnitStandStateType)ConditionValue2); + else if (ConditionValue2 == 0) + condMeets = unit.IsStandState(); + else if (ConditionValue2 == 1) + condMeets = unit.IsSitState(); } + break; + } case ConditionTypes.DailyQuestDone: - { - if (player) - condMeets = player.IsDailyQuestDone(ConditionValue1); - break; - } + { + if (player) + condMeets = player.IsDailyQuestDone(ConditionValue1); + break; + } case ConditionTypes.Charmed: - { - if (unit) - condMeets = unit.IsCharmed(); - break; - } + { + if (unit) + condMeets = unit.IsCharmed(); + break; + } case ConditionTypes.PetType: + { + if (player) { - if (player) - { - Pet pet = player.GetPet(); - if (pet) - condMeets = (((1 << (int)pet.GetPetType()) & ConditionValue1) != 0); - } - break; + Pet pet = player.GetPet(); + if (pet) + condMeets = (((1 << (int)pet.GetPetType()) & ConditionValue1) != 0); } + break; + } case ConditionTypes.Taxi: - { - if (player) - condMeets = player.IsInFlight(); - break; - } + { + if (player) + condMeets = player.IsInFlight(); + break; + } case ConditionTypes.Queststate: + { + if (player) { - if (player) - { - if ( - (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.None)) && (player.GetQuestStatus(ConditionValue1) == QuestStatus.None)) || - (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.Complete)) && (player.GetQuestStatus(ConditionValue1) == QuestStatus.Complete)) || - (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.Incomplete)) && (player.GetQuestStatus(ConditionValue1) == QuestStatus.Incomplete)) || - (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.Failed)) && (player.GetQuestStatus(ConditionValue1) == QuestStatus.Failed)) || - (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.Rewarded)) && player.GetQuestRewardStatus(ConditionValue1)) - ) - condMeets = true; - } - break; + if ( + (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.None)) && (player.GetQuestStatus(ConditionValue1) == QuestStatus.None)) || + (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.Complete)) && (player.GetQuestStatus(ConditionValue1) == QuestStatus.Complete)) || + (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.Incomplete)) && (player.GetQuestStatus(ConditionValue1) == QuestStatus.Incomplete)) || + (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.Failed)) && (player.GetQuestStatus(ConditionValue1) == QuestStatus.Failed)) || + (Convert.ToBoolean(ConditionValue2 & (1 << (int)QuestStatus.Rewarded)) && player.GetQuestRewardStatus(ConditionValue1)) + ) + condMeets = true; } + break; + } case ConditionTypes.ObjectiveComplete: + { + if (player) { - if (player) - { - QuestObjective questObj = Global.ObjectMgr.GetQuestObjective(ConditionValue1); - if (questObj == null) - break; + QuestObjective questObj = Global.ObjectMgr.GetQuestObjective(ConditionValue1); + if (questObj == null) + break; - Quest quest = Global.ObjectMgr.GetQuestTemplate(questObj.QuestID); - if (quest == null) - break; + Quest quest = Global.ObjectMgr.GetQuestTemplate(questObj.QuestID); + if (quest == null) + break; - ushort slot = player.FindQuestSlot(questObj.QuestID); - if (slot >= SharedConst.MaxQuestLogSize) - break; + ushort slot = player.FindQuestSlot(questObj.QuestID); + if (slot >= SharedConst.MaxQuestLogSize) + break; - condMeets = (!player.GetQuestRewardStatus(questObj.QuestID) && player.IsQuestObjectiveComplete(slot, quest, questObj)); - } - break; + condMeets = (!player.GetQuestRewardStatus(questObj.QuestID) && player.IsQuestObjectiveComplete(slot, quest, questObj)); } + break; + } case ConditionTypes.DifficultyId: + { + condMeets = (uint)obj.GetMap().GetDifficultyID() == ConditionValue1; + break; + } + case ConditionTypes.Gamemaster: + { + if (player != null) { - condMeets = (uint)obj.GetMap().GetDifficultyID() == ConditionValue1; - break; + if (ConditionValue1 == 1) + condMeets = player.CanBeGameMaster(); + else + condMeets = player.IsGameMaster(); } + break; + } default: condMeets = false; break; @@ -439,6 +450,7 @@ namespace Game.Conditions case ConditionTypes.PetType: case ConditionTypes.Taxi: case ConditionTypes.Queststate: + case ConditionTypes.Gamemaster: mask |= GridMapTypeMask.Player; break; case ConditionTypes.UnitState: diff --git a/Source/Game/Conditions/ConditionManager.cs b/Source/Game/Conditions/ConditionManager.cs index d821c43c8..4d15ee877 100644 --- a/Source/Game/Conditions/ConditionManager.cs +++ b/Source/Game/Conditions/ConditionManager.cs @@ -1610,6 +1610,7 @@ namespace Game case ConditionTypes.InWater: case ConditionTypes.Charmed: case ConditionTypes.Taxi: + case ConditionTypes.Gamemaster: break; case ConditionTypes.DifficultyId: if (!CliDB.DifficultyStorage.ContainsKey(cond.ConditionValue1)) @@ -2526,7 +2527,10 @@ namespace Game new ConditionTypeInfo("On Taxi", false,false, false), new ConditionTypeInfo("Quest state mask", true, true, false), new ConditionTypeInfo("Objective Complete", true, false, false), - new ConditionTypeInfo("Map Difficulty", true, false, false) + new ConditionTypeInfo("Map Difficulty", true, false, false), + new ConditionTypeInfo("Is Gamemaster", true, false, false), + new ConditionTypeInfo("Object Entry or Guid", true, true, true), + new ConditionTypeInfo("Object TypeMask", true, false, false), }; public struct ConditionTypeInfo