1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-07 12:54:00 +00:00
OpenMW/apps/openmw/mwmechanics/disease.hpp

72 lines
3.0 KiB
C++
Raw Normal View History

#ifndef OPENMW_MECHANICS_DISEASE_H
#define OPENMW_MECHANICS_DISEASE_H
2015-04-22 15:58:55 +00:00
#include <components/misc/rng.hpp>
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
2016-06-17 14:07:16 +00:00
#include "../mwworld/ptr.hpp"
#include "../mwworld/class.hpp"
2014-02-23 19:11:05 +00:00
#include "../mwworld/esmstore.hpp"
2016-06-17 14:07:16 +00:00
2015-08-21 09:12:39 +00:00
#include "spells.hpp"
#include "creaturestats.hpp"
#include "actorutil.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.
inline void diseaseContact (MWWorld::Ptr actor, MWWorld::Ptr carrier)
{
2015-08-21 09:12:39 +00:00
if (!carrier.getClass().isActor() || actor != getPlayer())
return;
float fDiseaseXferChance =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
2018-08-29 15:38:12 +00:00
"fDiseaseXferChance")->mValue.getFloat();
MagicEffects& actorEffects = actor.getClass().getCreatureStats(actor).getMagicEffects();
Spells& spells = carrier.getClass().getCreatureStats(carrier).getSpells();
for (Spells::TIterator it = spells.begin(); it != spells.end(); ++it)
{
const ESM::Spell* spell = it->first;
if (actor.getClass().getCreatureStats(actor).getSpells().hasSpell(spell->mId))
continue;
float resist = 0.f;
if (spells.hasCorprusEffect(spell))
resist = 1.f - 0.01f * (actorEffects.get(ESM::MagicEffect::ResistCorprusDisease).getMagnitude()
- actorEffects.get(ESM::MagicEffect::WeaknessToCorprusDisease).getMagnitude());
else if (spell->mData.mType == ESM::Spell::ST_Disease)
resist = 1.f - 0.01f * (actorEffects.get(ESM::MagicEffect::ResistCommonDisease).getMagnitude()
- actorEffects.get(ESM::MagicEffect::WeaknessToCommonDisease).getMagnitude());
else if (spell->mData.mType == ESM::Spell::ST_Blight)
resist = 1.f - 0.01f * (actorEffects.get(ESM::MagicEffect::ResistBlightDisease).getMagnitude()
- actorEffects.get(ESM::MagicEffect::WeaknessToBlightDisease).getMagnitude());
else
continue;
int x = static_cast<int>(fDiseaseXferChance * 100 * resist);
2015-04-22 15:58:55 +00:00
if (Misc::Rng::rollDice(10000) < x)
{
// Contracted disease!
actor.getClass().getCreatureStats(actor).getSpells().add(it->first);
std::string msg = "sMagicContractDisease";
2018-08-29 15:38:12 +00:00
msg = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(msg)->mValue.getString();
Misc::StringUtils::replace(msg, "%s", spell->mName.c_str(), 2);
MWBase::Environment::get().getWindowManager()->messageBox(msg);
}
}
}
}
#endif