Browse Source

refactor cleaving: added in player method to determine if character can cleave and if an item is equipped.

pull/6548/head
DakkJaniels 3 years ago committed by Anders Jenbo
parent
commit
ef87664403
  1. 12
      Source/player.cpp
  2. 44
      Source/player.h

12
Source/player.cpp

@ -855,17 +855,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);

44
Source/player.h

@ -386,6 +386,50 @@ public:
&& _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

Loading…
Cancel
Save