From 48658da60c73b765188fdfd1bc1eb91c109a80ca Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Sun, 8 Dec 2019 15:18:24 +0200 Subject: [PATCH] Allow using up to 4 params in OR and AND conditions. --- src/game/Conditions.cpp | 45 ++++++++++++++++++++++++++++++++++++++--- src/game/Conditions.h | 4 ++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/game/Conditions.cpp b/src/game/Conditions.cpp index d126e7c7e..3c0e702fe 100644 --- a/src/game/Conditions.cpp +++ b/src/game/Conditions.cpp @@ -139,13 +139,24 @@ bool inline ConditionEntry::Evaluate(WorldObject const* target, Map const* map, } case CONDITION_OR: { - // Checked on load + // Third and fourth condition are optional + if (m_value3 && sConditionStorage.LookupEntry(m_value3)->Meets(target, map, source, conditionSourceType)) + return true; + if (m_value4 && sConditionStorage.LookupEntry(m_value4)->Meets(target, map, source, conditionSourceType)) + return true; + return sConditionStorage.LookupEntry(m_value1)->Meets(target, map, source, conditionSourceType) || sConditionStorage.LookupEntry(m_value2)->Meets(target, map, source, conditionSourceType); } case CONDITION_AND: { - // Checked on load - return sConditionStorage.LookupEntry(m_value1)->Meets(target, map, source, conditionSourceType) && sConditionStorage.LookupEntry(m_value2)->Meets(target, map, source, conditionSourceType); + // Third and fourth condition are optional + bool extraConditionsSatisfied = true; + if (m_value3) + extraConditionsSatisfied = extraConditionsSatisfied && sConditionStorage.LookupEntry(m_value3)->Meets(target, map, source, conditionSourceType); + if (m_value4) + extraConditionsSatisfied = extraConditionsSatisfied && sConditionStorage.LookupEntry(m_value4)->Meets(target, map, source, conditionSourceType); + + return extraConditionsSatisfied && sConditionStorage.LookupEntry(m_value1)->Meets(target, map, source, conditionSourceType) && sConditionStorage.LookupEntry(m_value2)->Meets(target, map, source, conditionSourceType); } case CONDITION_NONE: { @@ -657,6 +668,34 @@ bool ConditionEntry::IsValid() sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has value2 %u without proper condition, skipped", m_entry, m_condition, m_value2); return false; } + if (m_value3) + { + if (m_value3 >= m_entry) + { + sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has invalid value3 %u, must be lower than entry, skipped", m_entry, m_condition, m_value3); + return false; + } + const ConditionEntry* condition3 = sConditionStorage.LookupEntry(m_value3); + if (!condition3) + { + sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has value3 %u without proper condition, skipped", m_entry, m_condition, m_value3); + return false; + } + } + if (m_value4) + { + if (m_value4 >= m_entry) + { + sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has invalid value4 %u, must be lower than entry, skipped", m_entry, m_condition, m_value4); + return false; + } + const ConditionEntry* condition4 = sConditionStorage.LookupEntry(m_value4); + if (!condition4) + { + sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has value4 %u without proper condition, skipped", m_entry, m_condition, m_value4); + return false; + } + } break; } case CONDITION_AURA: diff --git a/src/game/Conditions.h b/src/game/Conditions.h index 5a1d1ec07..5b90105f3 100644 --- a/src/game/Conditions.h +++ b/src/game/Conditions.h @@ -27,8 +27,8 @@ enum ConditionType { // // value1 value2 value3 value4 CONDITION_NOT = -3, // cond-id-1 0 returns !cond-id-1 - CONDITION_OR = -2, // cond-id-1 cond-id-2 returns cond-id-1 OR cond-id-2 - CONDITION_AND = -1, // cond-id-1 cond-id-2 returns cond-id-1 AND cond-id-2 + CONDITION_OR = -2, // cond-id-1 cond-id-2 cond-id-3 cond-id-4 returns true if at least one of the conditions is satisfied + CONDITION_AND = -1, // cond-id-1 cond-id-2 cond-id-3 cond-id-4 returns true only if all conditions are satisfied CONDITION_NONE = 0, // 0 0 CONDITION_AURA = 1, // spell_id effindex CONDITION_ITEM = 2, // item_id count check present req. amount items in inventory