-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into increase-wheel-types
- Loading branch information
Showing
14 changed files
with
334 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
#include <stdafx.h> | ||
|
||
#include "Components/EffectDispatchTimer.h" | ||
#include "Components/EffectDispatcher.h" | ||
#include "Components/MetaModifiers.h" | ||
|
||
#include "Util/OptionsManager.h" | ||
|
||
EffectDispatchTimer::EffectDispatchTimer(const std::array<BYTE, 3> &timerColor) : Component() | ||
{ | ||
m_TimerColor = timerColor; | ||
|
||
m_EffectSpawnTime = g_OptionsManager.GetConfigValue({ "NewEffectSpawnTime" }, OPTION_DEFAULT_EFFECT_SPAWN_TIME); | ||
|
||
m_DistanceChaosState.EnableDistanceBasedEffectDispatch = g_OptionsManager.GetConfigValue( | ||
{ "EnableDistanceBasedEffectDispatch" }, OPTION_DEFAULT_DISTANCE_BASED_DISPATCH_ENABLED); | ||
m_DistanceChaosState.DistanceToActivateEffect = | ||
g_OptionsManager.GetConfigValue({ "DistanceToActivateEffect" }, OPTION_DEFAULT_EFFECT_SPAWN_DISTANCE); | ||
m_DistanceChaosState.DistanceType = static_cast<DistanceChaosState::TravelledDistanceType>( | ||
g_OptionsManager.GetConfigValue({ "DistanceType" }, OPTION_DEFAULT_DISTANCE_TYPE)); | ||
} | ||
|
||
void EffectDispatchTimer::UpdateTimer(int deltaTime) | ||
{ | ||
if (!m_EnableTimer || (ComponentExists<MetaModifiers>() && GetComponent<MetaModifiers>()->DisableChaos)) | ||
{ | ||
return; | ||
} | ||
|
||
m_TimerPercentage += deltaTime | ||
* (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->TimerSpeedModifier : 1.f) | ||
/ m_EffectSpawnTime / 1000; | ||
|
||
if (m_TimerPercentage >= 1.f && m_DispatchEffectsOnTimer && ComponentExists<EffectDispatcher>()) | ||
{ | ||
GetComponent<EffectDispatcher>()->DispatchRandomEffect(); | ||
|
||
if (ComponentExists<MetaModifiers>()) | ||
{ | ||
for (std::uint8_t i = 0; i < GetComponent<MetaModifiers>()->AdditionalEffectsToDispatch; i++) | ||
{ | ||
GetComponent<EffectDispatcher>()->DispatchRandomEffect(); | ||
} | ||
} | ||
|
||
m_TimerPercentage = 0.f; | ||
} | ||
} | ||
|
||
void EffectDispatchTimer::UpdateTravelledDistance() | ||
{ | ||
auto player = PLAYER_PED_ID(); | ||
auto position = GET_ENTITY_COORDS(player, false); | ||
|
||
if (ComponentExists<MetaModifiers>() && GetComponent<MetaModifiers>()->DisableChaos) | ||
{ | ||
m_DistanceChaosState.SavedPosition = position; | ||
return; | ||
} | ||
|
||
if (IS_ENTITY_DEAD(player, false)) | ||
{ | ||
m_DistanceChaosState.DeadFlag = true; | ||
return; | ||
} | ||
|
||
if (m_DistanceChaosState.DeadFlag) | ||
{ | ||
m_DistanceChaosState.DeadFlag = false; | ||
m_DistanceChaosState.SavedPosition = GET_ENTITY_COORDS(player, false); | ||
return; | ||
} | ||
|
||
auto distance = | ||
GET_DISTANCE_BETWEEN_COORDS(position.x, position.y, position.z, m_DistanceChaosState.SavedPosition.x, | ||
m_DistanceChaosState.SavedPosition.y, m_DistanceChaosState.SavedPosition.z, true); | ||
|
||
if (m_DistanceChaosState.DistanceType == DistanceChaosState::TravelledDistanceType::Displacement) | ||
{ | ||
if (distance * (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->TimerSpeedModifier : 1.f) | ||
>= m_DistanceChaosState.DistanceToActivateEffect) | ||
{ | ||
if (m_DispatchEffectsOnTimer && ComponentExists<EffectDispatcher>()) | ||
{ | ||
GetComponent<EffectDispatcher>()->DispatchRandomEffect(); | ||
|
||
if (ComponentExists<MetaModifiers>()) | ||
{ | ||
for (std::uint8_t i = 0; i < GetComponent<MetaModifiers>()->AdditionalEffectsToDispatch; i++) | ||
{ | ||
GetComponent<EffectDispatcher>()->DispatchRandomEffect(); | ||
} | ||
} | ||
} | ||
|
||
m_DistanceChaosState.SavedPosition = position; | ||
} | ||
|
||
m_TimerPercentage = | ||
(distance * (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->TimerSpeedModifier : 1.f)) | ||
/ m_DistanceChaosState.DistanceToActivateEffect; | ||
} | ||
else if (m_DistanceChaosState.DistanceType == DistanceChaosState::TravelledDistanceType::Distance) | ||
{ | ||
m_DistanceChaosState.SavedPosition = position; | ||
m_TimerPercentage += | ||
(distance * (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->TimerSpeedModifier : 1.f)) | ||
/ m_DistanceChaosState.DistanceToActivateEffect; | ||
|
||
if (m_TimerPercentage >= 1.f && m_DispatchEffectsOnTimer && ComponentExists<EffectDispatcher>()) | ||
{ | ||
GetComponent<EffectDispatcher>()->DispatchRandomEffect(); | ||
|
||
if (ComponentExists<MetaModifiers>()) | ||
{ | ||
for (std::uint8_t i = 0; i < GetComponent<MetaModifiers>()->AdditionalEffectsToDispatch; i++) | ||
{ | ||
GetComponent<EffectDispatcher>()->DispatchRandomEffect(); | ||
} | ||
} | ||
|
||
m_TimerPercentage = 0; | ||
} | ||
} | ||
} | ||
|
||
bool EffectDispatchTimer::IsTimerEnabled() const | ||
{ | ||
return m_EnableTimer; | ||
} | ||
|
||
void EffectDispatchTimer::SetTimerEnabled(bool state) | ||
{ | ||
m_EnableTimer = state; | ||
} | ||
|
||
std::uint64_t EffectDispatchTimer::GetTimer() const | ||
{ | ||
return m_Timer; | ||
} | ||
|
||
void EffectDispatchTimer::ResetTimer() | ||
{ | ||
m_TimerPercentage = 0.f; | ||
m_Timer = GetTickCount64(); | ||
} | ||
|
||
int EffectDispatchTimer::GetRemainingTimerTime() const | ||
{ | ||
return std::ceil(m_EffectSpawnTime | ||
/ (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->TimerSpeedModifier : 1.f) | ||
* (1 - m_TimerPercentage)); | ||
} | ||
|
||
bool EffectDispatchTimer::ShouldDispatchEffectNow() const | ||
{ | ||
return GetRemainingTimerTime() <= 0; | ||
} | ||
|
||
void EffectDispatchTimer::SetShouldDispatchEffects(bool state) | ||
{ | ||
m_DispatchEffectsOnTimer = state; | ||
} | ||
|
||
void EffectDispatchTimer::SetFakeTimerPercentage(float percentage) | ||
{ | ||
m_FakeTimerPercentage = std::clamp(percentage, 0.f, 1.f); | ||
} | ||
|
||
void EffectDispatchTimer::ResetFakeTimerPercentage() | ||
{ | ||
m_FakeTimerPercentage = 0.f; | ||
} | ||
|
||
void EffectDispatchTimer::OnRun() | ||
{ | ||
if (!m_EnableTimer | ||
|| (ComponentExists<MetaModifiers>() | ||
&& (GetComponent<MetaModifiers>()->HideChaosUI || GetComponent<MetaModifiers>()->DisableChaos))) | ||
{ | ||
return; | ||
} | ||
|
||
float percentage = m_FakeTimerPercentage != 0.f ? m_FakeTimerPercentage : m_TimerPercentage; | ||
|
||
// New Effect Bar | ||
DRAW_RECT(.5f, .01f, 1.f, .021f, 0, 0, 0, 127, false); | ||
|
||
if (ComponentExists<MetaModifiers>() && GetComponent<MetaModifiers>()->FlipChaosUI) | ||
{ | ||
DRAW_RECT(1.f - percentage * .5f, .01f, percentage, .018f, m_TimerColor[0], m_TimerColor[1], m_TimerColor[2], | ||
255, false); | ||
} | ||
else | ||
{ | ||
DRAW_RECT(percentage * .5f, .01f, percentage, .018f, m_TimerColor[0], m_TimerColor[1], m_TimerColor[2], 255, | ||
false); | ||
} | ||
|
||
auto currentUpdateTime = GetTickCount64(); | ||
int deltaTime = currentUpdateTime | ||
- (ComponentExists<EffectDispatchTimer>() ? GetComponent<EffectDispatchTimer>()->GetTimer() : 0); | ||
|
||
// the game was paused | ||
if (deltaTime > 1000) | ||
{ | ||
deltaTime = 0; | ||
} | ||
|
||
if (!m_PauseTimer) | ||
{ | ||
if (m_DistanceChaosState.EnableDistanceBasedEffectDispatch) | ||
{ | ||
UpdateTravelledDistance(); | ||
} | ||
else | ||
{ | ||
UpdateTimer(deltaTime); | ||
} | ||
} | ||
|
||
m_Timer = currentUpdateTime; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
|
||
#include "Components/Component.h" | ||
|
||
class EffectDispatchTimer : public Component | ||
{ | ||
private: | ||
bool m_EnableTimer = true; | ||
bool m_PauseTimer = false; | ||
bool m_DispatchEffectsOnTimer = true; | ||
std::uint16_t m_EffectSpawnTime = 0; | ||
std::array<std::uint8_t, 3> m_TimerColor; | ||
float m_TimerPercentage = 0.f; | ||
float m_FakeTimerPercentage = 0.f; | ||
std::uint64_t m_Timer = 0; | ||
|
||
struct DistanceChaosState | ||
{ | ||
bool DeadFlag = true; | ||
bool EnableDistanceBasedEffectDispatch = false; | ||
float DistanceToActivateEffect = 500.f; | ||
enum class TravelledDistanceType | ||
{ | ||
Distance, | ||
Displacement | ||
} DistanceType = TravelledDistanceType::Distance; | ||
Vector3 SavedPosition = { 0.f, 0.f, 0.f }; | ||
} m_DistanceChaosState; | ||
|
||
protected: | ||
EffectDispatchTimer(const std::array<BYTE, 3> &timerColor); | ||
|
||
private: | ||
void UpdateTimer(int deltaTime); | ||
void UpdateTravelledDistance(); | ||
|
||
public: | ||
bool IsTimerEnabled() const; | ||
void SetTimerEnabled(bool state); | ||
|
||
std::uint64_t GetTimer() const; | ||
void ResetTimer(); | ||
|
||
int GetRemainingTimerTime() const; | ||
bool ShouldDispatchEffectNow() const; | ||
|
||
void SetShouldDispatchEffects(bool state); | ||
|
||
void SetFakeTimerPercentage(float percentage); | ||
void ResetFakeTimerPercentage(); | ||
|
||
virtual void OnRun() override; | ||
|
||
template <class T> | ||
requires std::is_base_of_v<Component, T> | ||
friend struct ComponentHolder; | ||
}; |
Oops, something went wrong.