comparison 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
comparison
equal deleted inserted replaced
1360:a47d9282ea7c 1361:b3ac17fd12de
1 #pragma once
2 #include "Conditions.h"
3 #include "Party.h"
4 std::array<ConditionProcessor, 18> conditionArray =
5 {
6 // hint: condname, protfrommagic, gmprot, enchantment, ...
7 ConditionProcessor(Condition_Cursed, false, false, 0),
8 ConditionProcessor(Condition_Weak, true, false, 0),
9 ConditionProcessor(Condition_Sleep, false, false, 22, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR),
10 ConditionProcessor(Condition_Fear, false, false, 0),
11 ConditionProcessor(Condition_Drunk, false, false, 0),
12 ConditionProcessor(Condition_Insane, false, false, 19, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
13 ConditionProcessor(Condition_Poison1, true, false, 21, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
14 ConditionProcessor(Condition_Disease1, true, false, 18, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
15 ConditionProcessor(Condition_Poison2, true, false, 21, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
16 ConditionProcessor(Condition_Disease2, true, false, 18, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
17 ConditionProcessor(Condition_Poison3, true, false, 21, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
18 ConditionProcessor(Condition_Disease3, true, false, 18, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
19 ConditionProcessor(Condition_Paralyzed, false, false, 20, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK, ITEM_ARTIFACT_GHOULSBANE, EQIUP_ANY),
20 ConditionProcessor(Condition_Unconcious,false, false, 0),
21 ConditionProcessor(Condition_Dead, true, true, 0),
22 ConditionProcessor(Condition_Pertified, true, false, 23, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK, ITEM_RELIC_KELEBRIM, EQIUP_ANY),
23 ConditionProcessor(Condition_Eradicated, true, true, 0),
24 ConditionProcessor(Condition_Zombie, false, false, 0)
25 };
26
27 bool ConditionProcessor::IsPlayerAffected( Player* inPlayer, int condToCheck, int blockable)
28 {
29 if ( !blockable )
30 {
31 return true;
32 }
33 ConditionProcessor* thisProc = &conditionArray[condToCheck];
34 if (thisProc->m_IsBlockedByProtFromMagic && pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0)
35 {
36 if (!(thisProc->m_DoesNeedGmProtFromMagic && pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uSkill < 4))
37 {
38 --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower;
39 if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u )
40 pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset();
41 return false;
42 }
43 }
44 if (thisProc->m_WorkingEnchantment != 0)
45 {
46 if (inPlayer->HasEnchantedItemEquipped(thisProc->m_WorkingEnchantment))
47 return false;
48 }
49 for (unsigned int i = 0; i < thisProc->m_equipmentPairs.size() / 2; i++)
50 {
51 if (thisProc->m_equipmentPairs[i * 2].m_ItemId == (ITEM_TYPE)0)
52 {
53 return true;
54 }
55 ITEM_TYPE itemId = thisProc->m_equipmentPairs[i * 2].m_ItemId;
56 ITEM_EQUIP_TYPE slot = thisProc->m_equipmentPairs[i * 2 + 1].m_EquipSlot;
57 if (inPlayer->WearsItem(itemId, slot))
58 {
59 return false;
60 }
61 }
62 return true;
63 }