mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 14:09:39 +00:00
Closes #1081: Implement disease contraction
This commit is contained in:
parent
2a7d610f87
commit
be2ebc5cac
4 changed files with 62 additions and 0 deletions
|
@ -74,6 +74,7 @@ add_openmw_dir (mwmechanics
|
||||||
mechanicsmanagerimp stat character creaturestats magiceffects movement actors objects
|
mechanicsmanagerimp stat character creaturestats magiceffects movement actors objects
|
||||||
drawstate spells activespells npcstats aipackage aisequence alchemy aiwander aitravel aifollow
|
drawstate spells activespells npcstats aipackage aisequence alchemy aiwander aitravel aifollow
|
||||||
aiescort aiactivate aicombat repair enchanting pathfinding security spellsuccess spellcasting
|
aiescort aiactivate aicombat repair enchanting pathfinding security spellsuccess spellcasting
|
||||||
|
disease
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwbase
|
add_openmw_dir (mwbase
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "../mwmechanics/npcstats.hpp"
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
#include "../mwmechanics/movement.hpp"
|
#include "../mwmechanics/movement.hpp"
|
||||||
#include "../mwmechanics/spellcasting.hpp"
|
#include "../mwmechanics/spellcasting.hpp"
|
||||||
|
#include "../mwmechanics/disease.hpp"
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
#include "../mwworld/actiontalk.hpp"
|
#include "../mwworld/actiontalk.hpp"
|
||||||
|
@ -604,6 +605,9 @@ namespace MWClass
|
||||||
ptr.getRefData().getLocals().setVarByInt(script, "onpchitme", 1);
|
ptr.getRefData().getLocals().setVarByInt(script, "onpchitme", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!attacker.isEmpty())
|
||||||
|
MWMechanics::diseaseContact(ptr, attacker);
|
||||||
|
|
||||||
if(damage > 0.0f)
|
if(damage > 0.0f)
|
||||||
{
|
{
|
||||||
// 'ptr' is losing health. Play a 'hit' voiced dialog entry if not already saying
|
// 'ptr' is losing health. Play a 'hit' voiced dialog entry if not already saying
|
||||||
|
|
53
apps/openmw/mwmechanics/disease.hpp
Normal file
53
apps/openmw/mwmechanics/disease.hpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#ifndef OPENMW_MECHANICS_DISEASE_H
|
||||||
|
#define OPENMW_MECHANICS_DISEASE_H
|
||||||
|
|
||||||
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
#include "../mwmechanics/spells.hpp"
|
||||||
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
|
|
||||||
|
namespace MWMechanics
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Call when \a actor has got in contact with \a carrier (e.g. hit by him, or loots him)
|
||||||
|
inline void diseaseContact (MWWorld::Ptr actor, MWWorld::Ptr carrier)
|
||||||
|
{
|
||||||
|
if (!carrier.getClass().isActor())
|
||||||
|
return;
|
||||||
|
|
||||||
|
float fDiseaseXferChance =
|
||||||
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
||||||
|
"fDiseaseXferChance")->getFloat();
|
||||||
|
|
||||||
|
Spells& spells = carrier.getClass().getCreatureStats(carrier).getSpells();
|
||||||
|
for (Spells::TIterator it = spells.begin(); it != spells.end(); ++it)
|
||||||
|
{
|
||||||
|
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(it->first);
|
||||||
|
if (spell->mData.mType == ESM::Spell::ST_Disease
|
||||||
|
|| spell->mData.mType == ESM::Spell::ST_Blight)
|
||||||
|
{
|
||||||
|
float roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99]
|
||||||
|
if (roll < fDiseaseXferChance)
|
||||||
|
{
|
||||||
|
// Contracted disease!
|
||||||
|
actor.getClass().getCreatureStats(actor).getSpells().add(it->first);
|
||||||
|
|
||||||
|
if (actor.getRefData().getHandle() == "player")
|
||||||
|
{
|
||||||
|
std::string msg = "sMagicContractDisease";
|
||||||
|
msg = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(msg)->getString();
|
||||||
|
if (msg.find("%s") != std::string::npos)
|
||||||
|
msg.replace(msg.find("%s"), 2, spell->mName);
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include "../mwgui/container.hpp"
|
#include "../mwgui/container.hpp"
|
||||||
|
|
||||||
|
#include "../mwmechanics/disease.hpp"
|
||||||
|
|
||||||
#include "class.hpp"
|
#include "class.hpp"
|
||||||
#include "containerstore.hpp"
|
#include "containerstore.hpp"
|
||||||
|
|
||||||
|
@ -21,6 +23,8 @@ namespace MWWorld
|
||||||
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
|
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
MWMechanics::diseaseContact(actor, getTarget());
|
||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Container);
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Container);
|
||||||
MWBase::Environment::get().getWindowManager()->getContainerWindow()->open(getTarget(), mLoot);
|
MWBase::Environment::get().getWindowManager()->getContainerWindow()->open(getTarget(), mLoot);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue