Skip to content

Commit

Permalink
refactor cleaving: added in player method to determine if character c…
Browse files Browse the repository at this point in the history
…an cleave and if an item is equipped.
  • Loading branch information
DakkJaniels committed Sep 1, 2023
1 parent bd8aab0 commit 32271a2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
12 changes: 1 addition & 11 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions Source/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 32271a2

Please sign in to comment.