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 },
|
||||
};
|
||||
|
||||
std::random_device CalcStats::dev;
|
||||
std::mt19937 CalcStats::rng( dev() );
|
||||
std::uniform_int_distribution< std::mt19937::result_type > CalcStats::range100( 0, 99 );
|
||||
std::unique_ptr< RandGenerator< float > > CalcStats::rnd = nullptr;
|
||||
|
||||
/*
|
||||
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 ) );
|
||||
|
||||
if( criticalHitProbability( chara ) > range100( rng ) )
|
||||
if( criticalHitProbability( chara ) > getRandomNumber0To100() )
|
||||
{
|
||||
factor *= criticalHitBonus( chara );
|
||||
hitType = Sapphire::Common::ActionHitSeverityType::CritDamage;
|
||||
}
|
||||
|
||||
factor *= 1.0f + ( ( range100( rng ) - 50.0f ) / 1000.0f );
|
||||
factor *= 1.0f + ( ( getRandomNumber0To100() - 50.0f ) / 1000.0f );
|
||||
|
||||
// todo: buffs
|
||||
|
||||
|
@ -607,13 +605,13 @@ std::pair< float, Sapphire::Common::ActionHitSeverityType > CalcStats::calcActio
|
|||
auto factor = Common::Util::trunc( pot * wd * ap * det, 0 );
|
||||
Sapphire::Common::ActionHitSeverityType hitType = Sapphire::Common::ActionHitSeverityType::NormalDamage;
|
||||
|
||||
if( criticalHitProbability( chara ) > range100( rng ) )
|
||||
if( criticalHitProbability( chara ) > getRandomNumber0To100() )
|
||||
{
|
||||
factor *= criticalHitBonus( chara );
|
||||
hitType = Sapphire::Common::ActionHitSeverityType::CritDamage;
|
||||
}
|
||||
|
||||
factor *= 1.0f + ( ( range100( rng ) - 50.0f ) / 1000.0f );
|
||||
factor *= 1.0f + ( ( getRandomNumber0To100() - 50.0f ) / 1000.0f );
|
||||
|
||||
// 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 );
|
||||
Sapphire::Common::ActionHitSeverityType hitType = Sapphire::Common::ActionHitSeverityType::NormalHeal;
|
||||
|
||||
if( criticalHitProbability( chara ) > range100( rng ) )
|
||||
if( criticalHitProbability( chara ) > getRandomNumber0To100() )
|
||||
{
|
||||
factor *= criticalHitBonus( chara );
|
||||
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 );
|
||||
}
|
||||
|
@ -655,3 +653,12 @@ uint32_t CalcStats::primaryStatValue( const Sapphire::Entity::Chara& chara )
|
|||
{
|
||||
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
|
||||
|
||||
#include <random>
|
||||
#include <Common.h>
|
||||
#include "Forwards.h"
|
||||
#include "Manager/RNGMgr.h"
|
||||
|
||||
namespace Sapphire::Math
|
||||
{
|
||||
using namespace Sapphire::World::Manager;
|
||||
|
||||
class CalcStats
|
||||
{
|
||||
|
@ -151,9 +152,8 @@ namespace Sapphire::Math
|
|||
*/
|
||||
static float calcAttackPower( const Sapphire::Entity::Chara& chara, uint32_t attackPower );
|
||||
|
||||
static std::random_device dev;
|
||||
static std::mt19937 rng;
|
||||
static std::uniform_int_distribution< std::mt19937::result_type > range100;
|
||||
static float getRandomNumber0To100();
|
||||
static std::unique_ptr< RandGenerator< float > > rnd;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue