diff Player.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 a47d9282ea7c
children d6cf8ead9242
line wrap: on
line diff
--- a/Player.cpp	Sat Jul 13 21:36:35 2013 +0200
+++ b/Player.cpp	Sun Jul 14 23:22:43 2013 +0200
@@ -698,18 +698,16 @@
   }
 }
 
-
 //----- (00492D65) --------------------------------------------------------
-int Player::SetCondition(unsigned int uConditionIdx, int a3)
+void Player::SetCondition( unsigned int uConditionIdx, int a3 )
 {
   signed int player_sex; // ecx@77
-  char zombi_face; // al@80
   signed int remainig_player; // ebx@82
   int players_before; // [sp+10h] [bp-4h]@2
   int players_after; // [sp+20h] [bp+Ch]@82
 
   if ( pConditions[uConditionIdx] )
-      return 0;
+      return;
 
   players_before = 0;
 
@@ -718,128 +716,43 @@
       if ( pPlayers[i]->CanAct() )
           ++players_before;
   }
+  
+  if (!ConditionProcessor::IsPlayerAffected(this, uConditionIdx, a3))
+  {
+    return;
+  }
 
   switch ( uConditionIdx )
   {
-    case Condition_Cursed:
-      PlaySound((PlayerSpeech)30, 0);
-    break;
-    case Condition_Weak:
-      if ( a3 == 1 && (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0 )
-      {
-        --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 0;
-      }
-      PlaySound((PlayerSpeech)25, 0);
-    break;
-    case Condition_Sleep:
-      if ( a3 == 1 && (HasEnchantedItemEquipped(22) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR))) 
-        return 0;
-    break;
-
-    case Condition_Fear:
-      PlaySound((PlayerSpeech)26, 0);
-    break;
-    case Condition_Drunk:
-      PlaySound((PlayerSpeech)31, 0);
-    break;
-    case Condition_Insane:
-      if ( a3 == 1 && (HasEnchantedItemEquipped(19) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK)) )
-        return 0;
-      PlaySound((PlayerSpeech)29, 0);
-    break;
+    case Condition_Cursed: PlaySound(SPEECH_30, 0); break;
+    case Condition_Weak: PlaySound(SPEECH_25, 0); break;
+    case Condition_Sleep: break; //nosound
+    case Condition_Fear: PlaySound(SPEECH_26, 0); break;
+    case Condition_Drunk: PlaySound(SPEECH_31, 0); break;
+    case Condition_Insane: PlaySound(SPEECH_29, 0); break;
     case Condition_Poison1:
     case Condition_Poison2:
-    case Condition_Poison3:
-      if ( a3 == 1 )
-      {
-        if ( (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 )
-        {
-          --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 0;
-        }
-        if ( HasEnchantedItemEquipped(21) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK) )
-            return 0;
-      }
-      PlaySound((PlayerSpeech)27, 0);
-    break;
+    case Condition_Poison3: PlaySound(SPEECH_27, 0); break;
     case Condition_Disease1:
     case Condition_Disease2:
-    case Condition_Disease3:
-      if ( a3 == 1 )
-      {            
-        if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 )
-        {
-          --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 0;
-        }
-        if ( HasEnchantedItemEquipped(18) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK) )
-          return 0;
-      }
-      PlaySound((PlayerSpeech)28, 0);
-    break;
-    case Condition_Paralyzed:
-      if ( a3 == 1 )
-      {
-        if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 )
-        {
-          --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 0;
-        }
-        if ( HasEnchantedItemEquipped(20) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_GHOULSBANE, EQIUP_ANY) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK))
-          return 0;
-      }
-    break;
+    case Condition_Disease3: PlaySound(SPEECH_28, 0);break;
+    case Condition_Paralyzed: break;  //nosound
     case Condition_Unconcious:
       PlaySound(SPEECH_32, 0);
       if ( sHealth > 0 )
         sHealth = 0;
     break;
     case Condition_Dead:
-      if ( a3 == 1 && (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 && pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uSkill >= 4u )
-      {
-        --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 0;
-      }
-      PlaySound((PlayerSpeech)33, 0);
+      PlaySound(SPEECH_33, 0);
       if ( sHealth > 0 )
         sHealth = 0;
       if ( sMana > 0 )
         sMana = 0;
     break;
     case Condition_Pertified:
-      if ( a3 == 1 )
-      {            
-        if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 )
-        {
-          --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 0;
-        }
-        if ( HasEnchantedItemEquipped(23) || WearsItem(ITEM_RELIC_KELEBRIM, EQIUP_ANY) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK) )
-          return 0;
-      }
       PlaySound((PlayerSpeech)34, 0);
     break;
     case Condition_Eradicated:
-      if ( a3 == 1 && ((signed __int64)pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0 ) &&( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uSkill >= 4u ))
-      {
-        --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 0;
-      }
       PlaySound(SPEECH_35, 0);
       if (sHealth > 0 )
         sHealth = 0;
@@ -848,7 +761,7 @@
     break;
     case Condition_Zombie:
       if ( classType == PLAYER_CLASS_LICH || Eradicated() || Zombie() || !Dead())
-        return 0;
+        return;
       memset(&pConditions[0], 0, sizeof(pConditions));
       sHealth = GetMaxHealth();
       sMana = 0;
@@ -865,12 +778,12 @@
         uCurrentFace = 24;
         uVoiceID = 24;
       }
-      PlaySound((PlayerSpeech)SPEECH_99, 0);
+      PlaySound(SPEECH_99, 0);
     break;
   }
 
   remainig_player = 0;
-  pConditions[uConditionIdx] = pParty->uTimePlayed;
+  pConditions[uConditionIdx] = 1;
   players_after = 0;
   for (int i = 1; i < 5; ++i)
   {
@@ -884,7 +797,7 @@
   {
     pPlayers[remainig_player]->PlaySound(SPEECH_107, 0);
   }
-  return 1;
+  return;
 }
 
 //----- (00492528) --------------------------------------------------------
@@ -9060,6 +8973,8 @@
     }
   }
 }
+
+
 //----- (0049387A) --------------------------------------------------------
 int CycleCharacter(unsigned int _this)
 {
@@ -9862,4 +9777,145 @@
       }
     }
   }
+}
+
+
+bool Player::Weak()
+{
+  return pConditions[Condition_Weak] != 0;
+}
+
+bool Player::Dead()
+{
+  return pConditions[Condition_Dead] != 0;
+}
+
+bool Player::Eradicated()
+{
+  return pConditions[Condition_Eradicated] != 0;
+}
+
+bool Player::Zombie()
+{
+  return pConditions[Condition_Zombie] != 0;
+}
+
+bool Player::Cursed()
+{
+  return pConditions[Condition_Cursed] != 0;
+}
+
+bool Player::Pertified()
+{
+  return pConditions[Condition_Pertified] != 0;
+}
+
+bool Player::Unconcious()
+{
+  return pConditions[Condition_Unconcious] != 0;
+}
+
+void Player::SetCursed( bool state )
+{
+  pConditions[Condition_Cursed] = state;
+}
+
+void Player::SetWeak( bool state )
+{
+  pConditions[Condition_Weak] = state;
+}
+
+void Player::SetAsleep( bool state )
+{
+  pConditions[Condition_Sleep] = state;
+}
+
+void Player::SetAfraid( bool state )
+{
+  pConditions[Condition_Fear] = state;
+}
+
+void Player::SetDrunk( bool state )
+{
+  pConditions[Condition_Drunk] = state;
+}
+
+void Player::SetInsane( bool state )
+{
+  pConditions[Condition_Insane] = state;
+}
+
+void Player::SetPoison1( bool state )
+{
+  pConditions[Condition_Poison1] = state;
+}
+
+void Player::SetDisease1( bool state )
+{
+  pConditions[Condition_Disease1] = state;
+}
+
+void Player::SetPoison2( bool state )
+{
+  pConditions[Condition_Poison2] = state;
+}
+
+void Player::SetDisease2( bool state )
+{
+  pConditions[Condition_Disease2] = state;
+}
+
+void Player::SetPoison3( bool state )
+{
+  pConditions[Condition_Poison3] = state;
+}
+
+void Player::SetDisease3( bool state )
+{
+  pConditions[Condition_Disease3] = state;
+}
+
+void Player::SetParalyzed( bool state )
+{
+  pConditions[Condition_Paralyzed] = state;
+}
+
+void Player::SetUnconcious( bool state )
+{
+  pConditions[Condition_Unconcious] = state;
+}
+
+void Player::SetDead( bool state )
+{
+  pConditions[Condition_Dead] = state;
+}
+
+void Player::SetPertified( bool state )
+{
+  pConditions[Condition_Pertified] = state;
+}
+
+void Player::SetEradicated( bool state )
+{
+  pConditions[Condition_Eradicated] = state;
+}
+
+void Player::SetZombie( bool state )
+{
+  pConditions[Condition_Zombie] = state;
+}
+
+void Player::SetCondWeakWithBlockCheck( int blockable )
+{
+  SetCondition(Condition_Weak, blockable);
+}
+
+void Player::SetCondInsaneWithBlockCheck( int blockable )
+{
+  SetCondition(Condition_Insane, blockable);
+}
+
+void Player::SetCondDeadWithBlockCheck( int blockable )
+{
+  SetCondition(Condition_Dead, blockable);
 }
\ No newline at end of file