forked from arturzxc/myapex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoRecoil.cpp
67 lines (62 loc) · 1.94 KB
/
NoRecoil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include <vector>
#include "LocalPlayer.cpp"
#include "Player.cpp"
#include "Math.cpp"
#include "Level.cpp"
#include "X11Utils.cpp"
#include "ConfigLoader.cpp"
class NoRecoil
{
private:
ConfigLoader *m_configLoader;
Level *m_level;
LocalPlayer *m_localPlayer;
std::vector<Player *> *m_players;
X11Utils *m_x11Utils;
double m_previousPunchPitch = 0;
double m_previousPunchYaw = 0;
public:
NoRecoil(ConfigLoader *configLoader,
Level *level,
LocalPlayer *localPlayer,
std::vector<Player *> *players,
X11Utils *x11Utils)
{
m_configLoader = configLoader;
m_level = level;
m_localPlayer = localPlayer;
m_players = players;
m_x11Utils = x11Utils;
}
void update()
{
// validations
if (!m_level->isPlayable())
return;
if (m_localPlayer->isDead())
return;
if (m_localPlayer->isKnocked())
return;
// adjust pitch
const double norecoilPitchStrength = m_configLoader->getNorecoilPitchStrength();
const double punchPitch = m_localPlayer->getPunchPitch();
if (punchPitch != 0)
{
const double pitch = m_localPlayer->getPitch();
const double punchPitchDelta = (punchPitch - m_previousPunchPitch) * norecoilPitchStrength;
m_localPlayer->setPitch(pitch - punchPitchDelta);
m_previousPunchPitch = punchPitch;
}
// adjust yaw
const double norecoilYawStrength = m_configLoader->getNorecoilYawStrength();
const double punchYaw = m_localPlayer->getPunchYaw();
if (punchYaw != 0)
{
const double yaw = m_localPlayer->getYaw();
const double punchYawDelta = (punchYaw - m_previousPunchYaw) * norecoilYawStrength;
m_localPlayer->setYaw(yaw - punchYawDelta);
m_previousPunchYaw = punchYaw;
}
}
};