diff --git a/utils.py b/utils.py index f3bdef4..e7a3e73 100644 --- a/utils.py +++ b/utils.py @@ -11,6 +11,10 @@ class Vec: self.z = 0 def new(self, x: int | float, y: int | float | None, z: int | float | None) -> None: + """Change values of Vector""" + if y == None: + raise TypeError + # Determine type of class self.type = int if type(x) == float: @@ -19,13 +23,6 @@ class Vec: # Verify other type if type(y) != self.type: raise TypeError - if y != None: - if type(y) != self.type: - raise TypeError - - # At this point, they can't be None - if y == None: - raise TypeError self.x = self.type(x) self.y = self.type(y) @@ -35,6 +32,15 @@ class Vec: else: self.z = self.type(z) + def __str__(self): + max_precision = 3 + + x = round(self.x, max_precision) + y = round(self.y, max_precision) + z = None if self.z == None else round(self.z, max_precision) + + return f"{self.__class__.__name__}({x}, {y}{'' if z == None else f', {z}'})" + def plus(self, other: 'Vec') -> 'Vec': x = self.x + other.x y = self.y + other.y @@ -53,14 +59,14 @@ class Vec: return Vec(x, y, self.z - other.z) - def div(self, val: float) -> 'Vec': - x = self.x / val - y = self.y / val + def div(self, factor: float) -> 'Vec': + x = self.x / factor + y = self.y / factor if self.z == None: return Vec(x, y) - return Vec(x, y, self.z / val) + return Vec(x, y, self.z / factor) def to_angle(self): if self.z == None: @@ -70,8 +76,7 @@ class Vec: return Vec( atan2(-self.z, hypot(self.x, self.y)) * deg_to_rad, - atan2(self.y, self.x) * deg_to_rad, - 0 + atan2(self.y, self.x) * deg_to_rad ) def is_zero(self): @@ -85,3 +90,20 @@ class Vec: def calculate_angle(local_pos: Vec, ennemy_pos: Vec, angles: Vec) -> Vec: """Angle calculation for aimbot""" return ((ennemy_pos.minus(local_pos).to_angle().minus(angles))) + + +def angle_fixer(angle: Vec) -> Vec: + """Force the angle to respect game limitation""" + # Limit of pitch in game is ]-89; 180[ + if angle.x > 89.: + angle.x = 89. + if angle.x < -89.: + angle.x = -89 + + # Limit of yaw in game is ]-180; 360[ + while (angle.y > 180.): + angle.y -= 360. + while (angle.y < -180.): + angle.y += 360. + + return angle