1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 21:19:57 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/difficultyscaling.cpp
David Cernat 889bcec7f8 Add OpenMW commits up to 1 Sep 2018
# Conflicts:
#	apps/openmw/mwbase/world.hpp
#	apps/openmw/mwclass/creature.cpp
#	apps/openmw/mwclass/npc.cpp
#	apps/openmw/mwgui/jailscreen.cpp
#	apps/openmw/mwmechanics/actors.cpp
#	apps/openmw/mwmechanics/difficultyscaling.cpp
#	apps/openmw/mwscript/transformationextensions.cpp
#	apps/openmw/mwworld/worldimp.hpp
2019-08-20 11:31:51 +03:00

63 lines
1.6 KiB
C++

#include "difficultyscaling.hpp"
#include <components/settings/settings.hpp>
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
#include "../mwmp/Main.hpp"
#include "../mwmp/LocalPlayer.hpp"
/*
End of tes3mp addition
*/
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
#include "../mwworld/esmstore.hpp"
#include "actorutil.hpp"
float scaleDamage(float damage, const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim)
{
const MWWorld::Ptr& player = MWMechanics::getPlayer();
// [-500, 500]
int difficultySetting = Settings::Manager::getInt("difficulty", "Game");
difficultySetting = std::min(difficultySetting, 500);
difficultySetting = std::max(difficultySetting, -500);
/*
Start of tes3mp change (major)
Use difficulty setting received from server instead of basing it on client settings
*/
difficultySetting = mwmp::Main::get().getLocalPlayer()->difficulty;
/*
End of tes3mp change (major)
*/
static const float fDifficultyMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDifficultyMult")->mValue.getFloat();
float difficultyTerm = 0.01f * difficultySetting;
float x = 0;
if (victim == player)
{
if (difficultyTerm > 0)
x = fDifficultyMult * difficultyTerm;
else
x = difficultyTerm / fDifficultyMult;
}
else if (attacker == player)
{
if (difficultyTerm > 0)
x = -difficultyTerm / fDifficultyMult;
else
x = fDifficultyMult * (-difficultyTerm);
}
damage *= 1 + x;
return damage;
}