2014-01-03 22:33:14 +00:00
|
|
|
#ifndef OPENMW_MECHANICS_DISEASE_H
|
|
|
|
#define OPENMW_MECHANICS_DISEASE_H
|
|
|
|
|
2022-09-05 17:35:15 +00:00
|
|
|
#include <components/esm3/loadmgef.hpp>
|
2015-04-22 15:58:55 +00:00
|
|
|
#include <components/misc/rng.hpp>
|
2022-08-02 22:00:54 +00:00
|
|
|
#include <components/misc/strings/format.hpp>
|
2015-03-15 01:07:47 +00:00
|
|
|
|
2014-01-03 22:33:14 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
2016-06-17 14:07:16 +00:00
|
|
|
|
2014-01-03 22:33:14 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2014-02-23 19:11:05 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2014-01-03 22:33:14 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2016-06-17 14:07:16 +00:00
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
#include "actorutil.hpp"
|
|
|
|
#include "creaturestats.hpp"
|
|
|
|
#include "spells.hpp"
|
|
|
|
|
2014-01-03 22:33:14 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Call when \a actor has got in contact with \a carrier (e.g. hit by him, or loots him)
|
2014-07-15 19:10:30 +00:00
|
|
|
/// @param actor The actor that will potentially catch diseases. Currently only the player can catch diseases.
|
|
|
|
/// @param carrier The disease carrier.
|
2021-06-23 21:13:59 +00:00
|
|
|
inline void diseaseContact(const MWWorld::Ptr& actor, const MWWorld::Ptr& carrier)
|
2014-01-03 22:33:14 +00:00
|
|
|
{
|
2015-08-21 09:12:39 +00:00
|
|
|
if (!carrier.getClass().isActor() || actor != getPlayer())
|
2014-01-03 22:33:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
float fDiseaseXferChance = MWBase::Environment::get()
|
2023-04-20 19:07:53 +00:00
|
|
|
.getESMStore()
|
|
|
|
->get<ESM::GameSetting>()
|
2018-08-29 15:38:12 +00:00
|
|
|
.find("fDiseaseXferChance")
|
|
|
|
->mValue.getFloat();
|
2014-01-03 22:33:14 +00:00
|
|
|
|
2021-08-27 18:07:50 +00:00
|
|
|
const MagicEffects& actorEffects = actor.getClass().getCreatureStats(actor).getMagicEffects();
|
2014-10-02 00:27:10 +00:00
|
|
|
|
2014-01-03 22:33:14 +00:00
|
|
|
Spells& spells = carrier.getClass().getCreatureStats(carrier).getSpells();
|
2021-08-27 18:07:50 +00:00
|
|
|
for (const ESM::Spell* spell : spells)
|
2014-01-03 22:33:14 +00:00
|
|
|
{
|
2014-07-15 19:10:30 +00:00
|
|
|
if (actor.getClass().getCreatureStats(actor).getSpells().hasSpell(spell->mId))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
float resist = 0.f;
|
2020-07-28 06:33:28 +00:00
|
|
|
if (Spells::hasCorprusEffect(spell))
|
2015-03-08 00:07:29 +00:00
|
|
|
resist = 1.f
|
|
|
|
- 0.01f
|
2023-05-23 17:06:08 +00:00
|
|
|
* (actorEffects.getOrDefault(ESM::MagicEffect::ResistCorprusDisease).getMagnitude()
|
|
|
|
- actorEffects.getOrDefault(ESM::MagicEffect::WeaknessToCorprusDisease).getMagnitude());
|
2014-07-15 19:10:30 +00:00
|
|
|
else if (spell->mData.mType == ESM::Spell::ST_Disease)
|
2015-03-08 00:07:29 +00:00
|
|
|
resist = 1.f
|
|
|
|
- 0.01f
|
2023-05-23 17:06:08 +00:00
|
|
|
* (actorEffects.getOrDefault(ESM::MagicEffect::ResistCommonDisease).getMagnitude()
|
|
|
|
- actorEffects.getOrDefault(ESM::MagicEffect::WeaknessToCommonDisease).getMagnitude());
|
2014-07-15 19:10:30 +00:00
|
|
|
else if (spell->mData.mType == ESM::Spell::ST_Blight)
|
2015-03-08 00:07:29 +00:00
|
|
|
resist = 1.f
|
|
|
|
- 0.01f
|
2023-05-23 17:06:08 +00:00
|
|
|
* (actorEffects.getOrDefault(ESM::MagicEffect::ResistBlightDisease).getMagnitude()
|
|
|
|
- actorEffects.getOrDefault(ESM::MagicEffect::WeaknessToBlightDisease).getMagnitude());
|
2014-07-15 19:10:30 +00:00
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
2015-03-08 00:07:29 +00:00
|
|
|
int x = static_cast<int>(fDiseaseXferChance * 100 * resist);
|
2022-03-06 19:56:02 +00:00
|
|
|
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
|
|
|
if (Misc::Rng::rollDice(10000, prng) < x)
|
2014-07-15 19:10:30 +00:00
|
|
|
{
|
|
|
|
// Contracted disease!
|
2021-08-27 18:07:50 +00:00
|
|
|
actor.getClass().getCreatureStats(actor).getSpells().add(spell);
|
2019-04-20 05:38:32 +00:00
|
|
|
MWBase::Environment::get().getWorld()->applyLoopingParticles(actor);
|
2014-07-15 19:10:30 +00:00
|
|
|
|
2022-08-28 13:06:31 +00:00
|
|
|
std::string msg = MWBase::Environment::get()
|
2023-04-20 19:07:53 +00:00
|
|
|
.getESMStore()
|
|
|
|
->get<ESM::GameSetting>()
|
2022-08-28 13:06:31 +00:00
|
|
|
.find("sMagicContractDisease")
|
|
|
|
->mValue.getString();
|
2019-05-19 08:33:57 +00:00
|
|
|
msg = Misc::StringUtils::format(msg, spell->mName);
|
2014-07-15 19:10:30 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox(msg);
|
|
|
|
}
|
2014-01-03 22:33:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|