1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 00:55:50 +00:00
OpenMW/apps/openmw/mwmechanics/disease.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
3.5 KiB
C++
Raw Normal View History

#ifndef OPENMW_MECHANICS_DISEASE_H
#define OPENMW_MECHANICS_DISEASE_H
#include <components/esm3/loadmgef.hpp>
2015-04-22 15:58:55 +00:00
#include <components/misc/rng.hpp>
#include <components/misc/strings/format.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
2016-06-17 14:07:16 +00:00
#include "../mwworld/class.hpp"
2014-02-23 19:11:05 +00:00
#include "../mwworld/esmstore.hpp"
#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"
namespace MWMechanics
{
/// Call when \a actor has got in contact with \a carrier (e.g. hit by him, or loots him)
/// @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)
{
2015-08-21 09:12:39 +00:00
if (!carrier.getClass().isActor() || actor != getPlayer())
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();
const MagicEffects& actorEffects = actor.getClass().getCreatureStats(actor).getMagicEffects();
Spells& spells = carrier.getClass().getCreatureStats(carrier).getSpells();
for (const ESM::Spell* spell : spells)
{
if (actor.getClass().getCreatureStats(actor).getSpells().hasSpell(spell->mId))
continue;
float resist = 0.f;
if (Spells::hasCorprusEffect(spell))
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());
else if (spell->mData.mType == ESM::Spell::ST_Disease)
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());
else if (spell->mData.mType == ESM::Spell::ST_Blight)
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());
else
continue;
int x = static_cast<int>(fDiseaseXferChance * 100 * resist);
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
if (Misc::Rng::rollDice(10000, prng) < x)
{
// Contracted disease!
actor.getClass().getCreatureStats(actor).getSpells().add(spell);
MWBase::Environment::get().getWorld()->applyLoopingParticles(actor);
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();
msg = Misc::StringUtils::format(msg, spell->mName);
MWBase::Environment::get().getWindowManager()->messageBox(msg);
}
}
}
}
#endif