You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.6 KiB
C++
64 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;
|
|
}
|