Mercurial > mm7
diff Conditions.cpp @ 1361:b3ac17fd12de
Moved condition checking to a separate class, extracted it from player::SetCondition
author | Grumpy7 |
---|---|
date | Sun, 14 Jul 2013 23:22:43 +0200 |
parents | |
children | 0311debb684c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Conditions.cpp Sun Jul 14 23:22:43 2013 +0200 @@ -0,0 +1,63 @@ +#pragma once +#include "Conditions.h" +#include "Party.h" +std::array<ConditionProcessor, 18> conditionArray = +{ + // hint: condname, protfrommagic, gmprot, enchantment, ... + ConditionProcessor(Condition_Cursed, false, false, 0), + ConditionProcessor(Condition_Weak, true, false, 0), + ConditionProcessor(Condition_Sleep, false, false, 22, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR), + ConditionProcessor(Condition_Fear, false, false, 0), + ConditionProcessor(Condition_Drunk, false, false, 0), + ConditionProcessor(Condition_Insane, false, false, 19, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK), + ConditionProcessor(Condition_Poison1, true, false, 21, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK), + ConditionProcessor(Condition_Disease1, true, false, 18, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK), + ConditionProcessor(Condition_Poison2, true, false, 21, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK), + ConditionProcessor(Condition_Disease2, true, false, 18, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK), + ConditionProcessor(Condition_Poison3, true, false, 21, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK), + ConditionProcessor(Condition_Disease3, true, false, 18, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK), + ConditionProcessor(Condition_Paralyzed, false, false, 20, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK, ITEM_ARTIFACT_GHOULSBANE, EQIUP_ANY), + ConditionProcessor(Condition_Unconcious,false, false, 0), + ConditionProcessor(Condition_Dead, true, true, 0), + ConditionProcessor(Condition_Pertified, true, false, 23, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK, ITEM_RELIC_KELEBRIM, EQIUP_ANY), + ConditionProcessor(Condition_Eradicated, true, true, 0), + ConditionProcessor(Condition_Zombie, false, false, 0) +}; + +bool ConditionProcessor::IsPlayerAffected( Player* inPlayer, int condToCheck, int blockable) +{ + if ( !blockable ) + { + return true; + } + ConditionProcessor* thisProc = &conditionArray[condToCheck]; + if (thisProc->m_IsBlockedByProtFromMagic && pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0) + { + if (!(thisProc->m_DoesNeedGmProtFromMagic && pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uSkill < 4)) + { + --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower; + if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u ) + pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset(); + return false; + } + } + if (thisProc->m_WorkingEnchantment != 0) + { + if (inPlayer->HasEnchantedItemEquipped(thisProc->m_WorkingEnchantment)) + return false; + } + for (unsigned int i = 0; i < thisProc->m_equipmentPairs.size() / 2; i++) + { + if (thisProc->m_equipmentPairs[i * 2].m_ItemId == (ITEM_TYPE)0) + { + return true; + } + ITEM_TYPE itemId = thisProc->m_equipmentPairs[i * 2].m_ItemId; + ITEM_EQUIP_TYPE slot = thisProc->m_equipmentPairs[i * 2 + 1].m_EquipSlot; + if (inPlayer->WearsItem(itemId, slot)) + { + return false; + } + } + return true; +}