mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-30 16:17:46 +00:00
update rng to RandGenerator
This commit is contained in:
parent
5fb62b75ec
commit
123dad2e23
2 changed files with 20 additions and 13 deletions
|
@ -85,9 +85,7 @@ const int levelTable[61][6] =
|
||||||
{ 218, 354, 858, 2600, 282, 215 },
|
{ 218, 354, 858, 2600, 282, 215 },
|
||||||
};
|
};
|
||||||
|
|
||||||
std::random_device CalcStats::dev;
|
std::unique_ptr< RandGenerator< float > > CalcStats::rnd = nullptr;
|
||||||
std::mt19937 CalcStats::rng( dev() );
|
|
||||||
std::uniform_int_distribution< std::mt19937::result_type > CalcStats::range100( 0, 99 );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Class used for battle-related formulas and calculations.
|
Class used for battle-related formulas and calculations.
|
||||||
|
@ -570,13 +568,13 @@ std::pair< float, Sapphire::Common::ActionHitSeverityType > CalcStats::calcAutoA
|
||||||
|
|
||||||
factor = std::floor( factor * speed( chara ) );
|
factor = std::floor( factor * speed( chara ) );
|
||||||
|
|
||||||
if( criticalHitProbability( chara ) > range100( rng ) )
|
if( criticalHitProbability( chara ) > getRandomNumber0To100() )
|
||||||
{
|
{
|
||||||
factor *= criticalHitBonus( chara );
|
factor *= criticalHitBonus( chara );
|
||||||
hitType = Sapphire::Common::ActionHitSeverityType::CritDamage;
|
hitType = Sapphire::Common::ActionHitSeverityType::CritDamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
factor *= 1.0f + ( ( range100( rng ) - 50.0f ) / 1000.0f );
|
factor *= 1.0f + ( ( getRandomNumber0To100() - 50.0f ) / 1000.0f );
|
||||||
|
|
||||||
// todo: buffs
|
// todo: buffs
|
||||||
|
|
||||||
|
@ -607,13 +605,13 @@ std::pair< float, Sapphire::Common::ActionHitSeverityType > CalcStats::calcActio
|
||||||
auto factor = Common::Util::trunc( pot * wd * ap * det, 0 );
|
auto factor = Common::Util::trunc( pot * wd * ap * det, 0 );
|
||||||
Sapphire::Common::ActionHitSeverityType hitType = Sapphire::Common::ActionHitSeverityType::NormalDamage;
|
Sapphire::Common::ActionHitSeverityType hitType = Sapphire::Common::ActionHitSeverityType::NormalDamage;
|
||||||
|
|
||||||
if( criticalHitProbability( chara ) > range100( rng ) )
|
if( criticalHitProbability( chara ) > getRandomNumber0To100() )
|
||||||
{
|
{
|
||||||
factor *= criticalHitBonus( chara );
|
factor *= criticalHitBonus( chara );
|
||||||
hitType = Sapphire::Common::ActionHitSeverityType::CritDamage;
|
hitType = Sapphire::Common::ActionHitSeverityType::CritDamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
factor *= 1.0f + ( ( range100( rng ) - 50.0f ) / 1000.0f );
|
factor *= 1.0f + ( ( getRandomNumber0To100() - 50.0f ) / 1000.0f );
|
||||||
|
|
||||||
// todo: buffs
|
// todo: buffs
|
||||||
|
|
||||||
|
@ -640,13 +638,13 @@ std::pair< float, Sapphire::Common::ActionHitSeverityType > CalcStats::calcActio
|
||||||
auto factor = std::floor( ( wepDmg * ( mnd / 200 ) + ( det / 10 ) ) * ( ptc / 100 ) * 1.3f );
|
auto factor = std::floor( ( wepDmg * ( mnd / 200 ) + ( det / 10 ) ) * ( ptc / 100 ) * 1.3f );
|
||||||
Sapphire::Common::ActionHitSeverityType hitType = Sapphire::Common::ActionHitSeverityType::NormalHeal;
|
Sapphire::Common::ActionHitSeverityType hitType = Sapphire::Common::ActionHitSeverityType::NormalHeal;
|
||||||
|
|
||||||
if( criticalHitProbability( chara ) > range100( rng ) )
|
if( criticalHitProbability( chara ) > getRandomNumber0To100() )
|
||||||
{
|
{
|
||||||
factor *= criticalHitBonus( chara );
|
factor *= criticalHitBonus( chara );
|
||||||
hitType = Sapphire::Common::ActionHitSeverityType::CritHeal;
|
hitType = Sapphire::Common::ActionHitSeverityType::CritHeal;
|
||||||
}
|
}
|
||||||
|
|
||||||
factor *= 1.0f + ( ( range100( rng ) - 50.0f ) / 1000.0f );
|
factor *= 1.0f + ( ( getRandomNumber0To100() - 50.0f ) / 1000.0f );
|
||||||
|
|
||||||
return std::pair( factor, hitType );
|
return std::pair( factor, hitType );
|
||||||
}
|
}
|
||||||
|
@ -654,4 +652,13 @@ std::pair< float, Sapphire::Common::ActionHitSeverityType > CalcStats::calcActio
|
||||||
uint32_t CalcStats::primaryStatValue( const Sapphire::Entity::Chara& chara )
|
uint32_t CalcStats::primaryStatValue( const Sapphire::Entity::Chara& chara )
|
||||||
{
|
{
|
||||||
return chara.getStatValue( chara.getPrimaryStat() );
|
return chara.getStatValue( chara.getPrimaryStat() );
|
||||||
|
}
|
||||||
|
|
||||||
|
float CalcStats::getRandomNumber0To100()
|
||||||
|
{
|
||||||
|
if( !rnd )
|
||||||
|
{
|
||||||
|
rnd = std::make_unique< RandGenerator< float > >( Common::Service< RNGMgr >::ref().getRandGenerator< float >( 0, 100 ) );
|
||||||
|
}
|
||||||
|
return rnd->next();
|
||||||
}
|
}
|
|
@ -1,11 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <random>
|
|
||||||
#include <Common.h>
|
#include <Common.h>
|
||||||
#include "Forwards.h"
|
#include "Forwards.h"
|
||||||
|
#include "Manager/RNGMgr.h"
|
||||||
|
|
||||||
namespace Sapphire::Math
|
namespace Sapphire::Math
|
||||||
{
|
{
|
||||||
|
using namespace Sapphire::World::Manager;
|
||||||
|
|
||||||
class CalcStats
|
class CalcStats
|
||||||
{
|
{
|
||||||
|
@ -151,9 +152,8 @@ namespace Sapphire::Math
|
||||||
*/
|
*/
|
||||||
static float calcAttackPower( const Sapphire::Entity::Chara& chara, uint32_t attackPower );
|
static float calcAttackPower( const Sapphire::Entity::Chara& chara, uint32_t attackPower );
|
||||||
|
|
||||||
static std::random_device dev;
|
static float getRandomNumber0To100();
|
||||||
static std::mt19937 rng;
|
static std::unique_ptr< RandGenerator< float > > rnd;
|
||||||
static std::uniform_int_distribution< std::mt19937::result_type > range100;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue