diff --git a/Source/player.cpp b/Source/player.cpp index fa258f3036a..cf27f226311 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -854,17 +854,7 @@ bool DoAttack(Player &player) didhit = PlrHitObj(player, *object); } } - if ((player._pClass == HeroClass::Monk - && (player.InvBody[INVLOC_HAND_LEFT]._itype == ItemType::Staff || player.InvBody[INVLOC_HAND_RIGHT]._itype == ItemType::Staff)) - || (player._pClass == HeroClass::Bard - && player.InvBody[INVLOC_HAND_LEFT]._itype == ItemType::Sword && player.InvBody[INVLOC_HAND_RIGHT]._itype == ItemType::Sword) - || (player._pClass == HeroClass::Barbarian - && (player.InvBody[INVLOC_HAND_LEFT]._itype == ItemType::Axe || player.InvBody[INVLOC_HAND_RIGHT]._itype == ItemType::Axe - || (((player.InvBody[INVLOC_HAND_LEFT]._itype == ItemType::Mace && player.InvBody[INVLOC_HAND_LEFT]._iLoc == ILOC_TWOHAND) - || (player.InvBody[INVLOC_HAND_RIGHT]._itype == ItemType::Mace && player.InvBody[INVLOC_HAND_RIGHT]._iLoc == ILOC_TWOHAND) - || (player.InvBody[INVLOC_HAND_LEFT]._itype == ItemType::Sword && player.InvBody[INVLOC_HAND_LEFT]._iLoc == ILOC_TWOHAND) - || (player.InvBody[INVLOC_HAND_RIGHT]._itype == ItemType::Sword && player.InvBody[INVLOC_HAND_RIGHT]._iLoc == ILOC_TWOHAND)) - && !(player.InvBody[INVLOC_HAND_LEFT]._itype == ItemType::Shield || player.InvBody[INVLOC_HAND_RIGHT]._itype == ItemType::Shield))))) { + if (player.CanCleave()) { // playing as a class/weapon with cleave position = player.position.tile + Right(player._pdir); monster = FindMonsterAtPosition(position); diff --git a/Source/player.h b/Source/player.h index a89263c1e8f..158297e4e93 100644 --- a/Source/player.h +++ b/Source/player.h @@ -386,6 +386,50 @@ struct Player { && _pDexterity >= item._iMinDex; } + bool CanCleave() + { + switch (_pClass) { + case HeroClass::Warrior: + case HeroClass::Rogue: + case HeroClass::Sorcerer: + return false; + case HeroClass::Monk: + return isEquipped(ItemType::Staff); + case HeroClass::Bard: + return InvBody[INVLOC_HAND_LEFT]._itype == ItemType::Sword && InvBody[INVLOC_HAND_RIGHT]._itype == ItemType::Sword; + case HeroClass::Barbarian: + return isEquipped(ItemType::Axe) || (!isEquipped(ItemType::Shield) && (isEquipped(ItemType::Mace, true) || isEquipped(ItemType::Sword, true))); + default: + return false; + } + } + + bool isEquipped(ItemType itemType, bool isTwoHanded = false) + { + switch (itemType) { + case ItemType::Sword: + case ItemType::Axe: + case ItemType::Bow: + case ItemType::Mace: + case ItemType::Shield: + case ItemType::Staff: + return (InvBody[INVLOC_HAND_LEFT]._itype == itemType && (!isTwoHanded || InvBody[INVLOC_HAND_LEFT]._iLoc == ILOC_TWOHAND)) + || (InvBody[INVLOC_HAND_RIGHT]._itype == itemType && (!isTwoHanded || InvBody[INVLOC_HAND_LEFT]._iLoc == ILOC_TWOHAND)); + case ItemType::LightArmor: + case ItemType::MediumArmor: + case ItemType::HeavyArmor: + return InvBody[INVLOC_CHEST]._itype == itemType; + case ItemType::Helm: + return InvBody[INVLOC_HEAD]._itype == itemType; + case ItemType::Ring: + return InvBody[INVLOC_RING_LEFT]._itype == itemType || InvBody[INVLOC_RING_RIGHT]._itype == itemType; + case ItemType::Amulet: + return InvBody[INVLOC_AMULET]._itype == itemType; + default: + return false; + } + } + /** * @brief Remove an item from player inventory * @param iv invList index of item to be removed