mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-27 06:47:45 +00:00
Merge pull request #923 from collett8192/3.0_master
3.x crit, fix random generator and remove direct hit
This commit is contained in:
commit
9ba263da00
3 changed files with 26 additions and 51 deletions
|
@ -37,18 +37,18 @@ uint64_t ActionResult::getDelay()
|
|||
|
||||
void ActionResult::damage( uint32_t amount, Common::ActionHitSeverityType severity, Common::ActionResultFlag flag )
|
||||
{
|
||||
m_result.Arg0 = static_cast< uint8_t >( severity );
|
||||
//m_result.Arg0 = static_cast< uint8_t >( severity );
|
||||
m_result.Value = static_cast< int16_t >( amount );
|
||||
m_result.Flag = static_cast< uint8_t >( flag );
|
||||
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_DAMAGE_HP;
|
||||
m_result.Type = severity == Common::ActionHitSeverityType::CritDamage ? Common::ActionEffectType::CALC_RESULT_TYPE_CRITICAL_DAMAGE_HP : Common::ActionEffectType::CALC_RESULT_TYPE_DAMAGE_HP;
|
||||
}
|
||||
|
||||
void ActionResult::heal( uint32_t amount, Common::ActionHitSeverityType severity, Common::ActionResultFlag flag )
|
||||
{
|
||||
m_result.Arg1 = static_cast< uint8_t >( severity );
|
||||
//m_result.Arg1 = static_cast< uint8_t >( severity );
|
||||
m_result.Value = static_cast< int16_t >( amount );
|
||||
m_result.Flag = static_cast< uint8_t >( flag );
|
||||
m_result.Type = Common::ActionEffectType::CALC_RESULT_TYPE_RECOVER_HP;
|
||||
m_result.Type = severity == Common::ActionHitSeverityType::CritHeal ? Common::ActionEffectType::CALC_RESULT_TYPE_CRITICAL_RECOVER_HP : Common::ActionEffectType::CALC_RESULT_TYPE_RECOVER_HP;
|
||||
}
|
||||
|
||||
void ActionResult::restoreMP( uint32_t amount, Common::ActionResultFlag flag )
|
||||
|
@ -119,12 +119,14 @@ void ActionResult::execute()
|
|||
switch( m_result.Type )
|
||||
{
|
||||
case Common::ActionEffectType::CALC_RESULT_TYPE_DAMAGE_HP:
|
||||
case Common::ActionEffectType::CALC_RESULT_TYPE_CRITICAL_DAMAGE_HP:
|
||||
{
|
||||
m_target->takeDamage( m_result.Value );
|
||||
break;
|
||||
}
|
||||
|
||||
case Common::ActionEffectType::CALC_RESULT_TYPE_RECOVER_HP:
|
||||
case Common::ActionEffectType::CALC_RESULT_TYPE_CRITICAL_RECOVER_HP:
|
||||
{
|
||||
m_target->heal( m_result.Value );
|
||||
break;
|
||||
|
|
|
@ -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.
|
||||
|
@ -287,19 +285,6 @@ float CalcStats::blockProbability( const Chara& chara )
|
|||
return std::floor( ( 30 * blockRate ) / levelVal + 10 );
|
||||
}
|
||||
|
||||
float CalcStats::directHitProbability( const Chara& chara )
|
||||
{
|
||||
const auto& baseStats = chara.getStats();
|
||||
auto level = chara.getLevel();
|
||||
|
||||
auto dhRate = chara.getStatValueFloat( Common::BaseParam::Accuracy );
|
||||
|
||||
auto divVal = static_cast< float >( levelTable[ level ][ Common::LevelTableEntry::DIV ] );
|
||||
auto subVal = static_cast< float >( levelTable[ level ][ Common::LevelTableEntry::SUB ] );
|
||||
|
||||
return std::floor( 550.f * ( dhRate - subVal ) / divVal ) / 10.f;
|
||||
}
|
||||
|
||||
float CalcStats::criticalHitProbability( const Chara& chara )
|
||||
{
|
||||
const auto& baseStats = chara.getStats();
|
||||
|
@ -583,21 +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;
|
||||
}
|
||||
|
||||
if( directHitProbability( chara ) > range100( rng ) )
|
||||
{
|
||||
factor *= 1.25f;
|
||||
hitType = hitType == Sapphire::Common::ActionHitSeverityType::CritDamage ?
|
||||
Sapphire::Common::ActionHitSeverityType::CritDirectHitDamage :
|
||||
Sapphire::Common::ActionHitSeverityType::DirectHitDamage;
|
||||
}
|
||||
|
||||
factor *= 1.0f + ( ( range100( rng ) - 50.0f ) / 1000.0f );
|
||||
factor *= 1.0f + ( ( getRandomNumber0To100() - 50.0f ) / 1000.0f );
|
||||
|
||||
// todo: buffs
|
||||
|
||||
|
@ -628,21 +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;
|
||||
}
|
||||
|
||||
if( directHitProbability( chara ) > range100( rng ) )
|
||||
{
|
||||
factor *= 1.25f;
|
||||
hitType = hitType == Sapphire::Common::ActionHitSeverityType::CritDamage ?
|
||||
Sapphire::Common::ActionHitSeverityType::CritDirectHitDamage :
|
||||
Sapphire::Common::ActionHitSeverityType::DirectHitDamage;
|
||||
}
|
||||
|
||||
factor *= 1.0f + ( ( range100( rng ) - 50.0f ) / 1000.0f );
|
||||
factor *= 1.0f + ( ( getRandomNumber0To100() - 50.0f ) / 1000.0f );
|
||||
|
||||
// todo: buffs
|
||||
|
||||
|
@ -669,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 );
|
||||
}
|
||||
|
@ -683,4 +652,13 @@ std::pair< float, Sapphire::Common::ActionHitSeverityType > CalcStats::calcActio
|
|||
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
|
||||
{
|
||||
|
@ -34,11 +35,6 @@ namespace Sapphire::Math
|
|||
*/
|
||||
static float blockProbability( const Sapphire::Entity::Chara& chara );
|
||||
|
||||
/*!
|
||||
* @brief Calculates the probability of a direct hit happening
|
||||
*/
|
||||
static float directHitProbability( const Sapphire::Entity::Chara& chara );
|
||||
|
||||
/*!
|
||||
* @brief Calculates the probability of a critical hit happening
|
||||
*/
|
||||
|
@ -156,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