From b332704df730af3e3940694dbc8c10a655314c9e Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 Mar 2016 18:03:59 +0100 Subject: [PATCH] Switch hand-to-hand attack types randomly when "always use best attack" is turned on (Fixes #3259) --- apps/openmw/mwmechanics/character.cpp | 28 +++++++++++++++++++++------ apps/openmw/mwmechanics/character.hpp | 3 ++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 0035ebb1a..30a4ec9f7 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1281,14 +1281,19 @@ bool CharacterController::updateWeaponState() mAttackType = "shoot"; else { - if(isWeapon && mPtr == getPlayer() && - Settings::Manager::getBool("best attack", "Game")) + if (isWeapon) { - MWWorld::ContainerStoreIterator weapon = mPtr.getClass().getInventoryStore(mPtr).getSlot(MWWorld::InventoryStore::Slot_CarriedRight); - mAttackType = getBestAttack(weapon->get()->mBase); + if(mPtr == getPlayer() && + Settings::Manager::getBool("best attack", "Game")) + { + MWWorld::ContainerStoreIterator weapon = mPtr.getClass().getInventoryStore(mPtr).getSlot(MWWorld::InventoryStore::Slot_CarriedRight); + mAttackType = getBestAttack(weapon->get()->mBase); + } + else + setAttackTypeBasedOnMovement(); } else - determineAttackType(); + setAttackTypeRandomly(); } mAnimation->play(mCurrentWeapon, priorityWeapon, @@ -2061,7 +2066,18 @@ void CharacterController::updateMagicEffects() mAnimation->setLightEffect(light); } -void CharacterController::determineAttackType() +void CharacterController::setAttackTypeRandomly() +{ + float random = Misc::Rng::rollProbability(); + if (random >= 2/3.f) + mAttackType = "thrust"; + else if (random >= 1/3.f) + mAttackType = "slash"; + else + mAttackType = "chop"; +} + +void CharacterController::setAttackTypeBasedOnMovement() { float *move = mPtr.getClass().getMovementSettings(mPtr).mPosition; diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 6db661ca5..6fab04d64 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -189,7 +189,8 @@ class CharacterController : public MWRender::Animation::TextKeyListener bool mAttackingOrSpell; - void determineAttackType(); + void setAttackTypeBasedOnMovement(); + void setAttackTypeRandomly(); void refreshCurrentAnims(CharacterState idle, CharacterState movement, JumpingState jump, bool force=false);