Use fCombatDelayCreature, fCombatDelayNpc for random delays between aicombat attacks (Bug #1876)

c++11
scrawl 10 years ago
parent a7bd050928
commit 6bcea21e14

@ -81,6 +81,7 @@ namespace MWMechanics
/// \brief This class holds the variables AiCombat needs which are deleted if the package becomes inactive. /// \brief This class holds the variables AiCombat needs which are deleted if the package becomes inactive.
struct AiCombatStorage : AiTemporaryBase struct AiCombatStorage : AiTemporaryBase
{ {
float mAttackCooldown;
float mTimerReact; float mTimerReact;
float mTimerCombatMove; float mTimerCombatMove;
bool mReadyToAttack; bool mReadyToAttack;
@ -98,6 +99,7 @@ namespace MWMechanics
MWMechanics::Movement mMovement; MWMechanics::Movement mMovement;
AiCombatStorage(): AiCombatStorage():
mAttackCooldown(0),
mTimerReact(0), mTimerReact(0),
mTimerCombatMove(0), mTimerCombatMove(0),
mReadyToAttack(false), mReadyToAttack(false),
@ -339,6 +341,8 @@ namespace MWMechanics
float& strength = storage.mStrength; float& strength = storage.mStrength;
// start new attack // start new attack
if(readyToAttack && characterController.readyToStartAttack()) if(readyToAttack && characterController.readyToStartAttack())
{
if (storage.mAttackCooldown <= 0)
{ {
attack = true; // attack starts just now attack = true; // attack starts just now
characterController.setAttackingOrSpell(attack); characterController.setAttackingOrSpell(attack);
@ -348,16 +352,24 @@ namespace MWMechanics
strength = Misc::Rng::rollClosedProbability(); strength = Misc::Rng::rollClosedProbability();
const MWWorld::ESMStore &store = world->getStore();
//say a provoking combat phrase //say a provoking combat phrase
if (actor.getClass().isNpc()) if (actor.getClass().isNpc())
{ {
const MWWorld::ESMStore &store = world->getStore();
int chance = store.get<ESM::GameSetting>().find("iVoiceAttackOdds")->getInt(); int chance = store.get<ESM::GameSetting>().find("iVoiceAttackOdds")->getInt();
if (Misc::Rng::roll0to99() < chance) if (Misc::Rng::roll0to99() < chance)
{ {
MWBase::Environment::get().getDialogueManager()->say(actor, "attack"); MWBase::Environment::get().getDialogueManager()->say(actor, "attack");
} }
} }
float baseDelay = store.get<ESM::GameSetting>().find("fCombatDelayCreature")->getFloat();
if (actor.getClass().isNpc())
baseDelay = store.get<ESM::GameSetting>().find("fCombatDelayNPC")->getFloat();
storage.mAttackCooldown = std::min(baseDelay + 0.01 * Misc::Rng::roll0to99(), baseDelay + 0.9);
}
else
storage.mAttackCooldown -= tReaction;
} }

Loading…
Cancel
Save