| 828 | } |
| 829 | |
| 830 | bool BattleUnit::startAttacking(GameState &state, WeaponStatus status) |
| 831 | { |
| 832 | switch (state.current_battle->mode) |
| 833 | { |
| 834 | case Battle::Mode::TurnBased: |
| 835 | { |
| 836 | if (moraleState == MoraleState::Normal) |
| 837 | { |
| 838 | // In Turn based we cannot fire both hands (unless zerking) |
| 839 | if (status == WeaponStatus::FiringBothHands) |
| 840 | { |
| 841 | // Right hand has priority |
| 842 | auto rhItem = agent->getFirstItemInSlot(EquipmentSlotType::RightHand); |
| 843 | if (rhItem && rhItem->canFire(state)) |
| 844 | { |
| 845 | status = WeaponStatus::FiringRightHand; |
| 846 | } |
| 847 | else |
| 848 | { |
| 849 | // We don't care what's in the left hand, |
| 850 | // we will just cancel firing in update() if there's nothing to fire |
| 851 | status = WeaponStatus::FiringLeftHand; |
| 852 | } |
| 853 | } |
| 854 | // Check TU |
| 855 | auto weapon = (status == WeaponStatus::FiringRightHand) |
| 856 | ? agent->getFirstItemInSlot(EquipmentSlotType::RightHand) |
| 857 | : agent->getFirstItemInSlot(EquipmentSlotType::LeftHand); |
| 858 | if (!weapon || !weapon->canFire(state, targetTile) || |
| 859 | !canAfford(state, getAttackCost(state, *weapon, targetTile), true, true)) |
| 860 | { |
| 861 | return false; |
| 862 | } |
| 863 | } |
| 864 | break; |
| 865 | } |
| 866 | case Battle::Mode::RealTime: |
| 867 | { |
| 868 | // Start firing both hands if added one hand to another |
| 869 | if ((weaponStatus == WeaponStatus::FiringLeftHand && |
| 870 | status == WeaponStatus::FiringRightHand) || |
| 871 | (weaponStatus == WeaponStatus::FiringRightHand && |
| 872 | status == WeaponStatus::FiringLeftHand)) |
| 873 | { |
| 874 | status = WeaponStatus::FiringBothHands; |
| 875 | } |
| 876 | |
| 877 | // Do not start an attack if unit's weapon(s) can't fire |
| 878 | auto const leftHandWeapon = agent->getFirstItemInSlot(EquipmentSlotType::LeftHand); |
| 879 | auto const rightHandWeapon = agent->getFirstItemInSlot(EquipmentSlotType::RightHand); |
| 880 | if (status == WeaponStatus::FiringLeftHand && |
| 881 | (!leftHandWeapon || !leftHandWeapon->canFire(state, targetTile))) |
| 882 | { |
| 883 | return false; |
| 884 | } |
| 885 | |
| 886 | if (status == WeaponStatus::FiringRightHand && |
| 887 | (!rightHandWeapon || !rightHandWeapon->canFire(state, targetTile))) |
no test coverage detected