You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.6 KiB

2 years ago
from geopy.geocoders import Nominatim
2 years ago
from ispoof.spoofer.location import Location
2 years ago
from ispoof.spoofer.device import Device
from ispoof.lists.playerhistory import PlayerHistory
from datetime import datetime, timedelta
from typing import Tuple, Optional
from pathlib import Path
from math import ceil
2 years ago
import gpxpy
import time
TIME = 1
2 years ago
class Player:
2 years ago
def __init__(self, engine, speed=1.4, location=None, cooldown=0):
self.location = location
self.cooldown = cooldown
2 years ago
self.speed = speed
self.history = PlayerHistory(engine=engine)
2 years ago
self.device = Device()
def prepare_device(self) -> None:
2 years ago
self.device.mount_image()
2 years ago
def set_location_with_query(self, query: str) -> None:
2 years ago
loc = Nominatim(user_agent="GetLoc")
get_loc = loc.geocode(query)
2 years ago
self.location = Location(get_loc.latitude, get_loc.longitude)
2 years ago
self.device.spoof_gps(self.location)
def get_last_activity(self) -> Optional[Tuple[datetime, Location]]:
return self.history.get_last_activity()
def set_location(self, location: Location) -> None:
2 years ago
self.location = location
2 years ago
self.device.spoof_gps(self.location)
2 years ago
def do_activity(self, location: Location) -> None:
self.history.add_activity(location)
def get_location(self) -> Location:
2 years ago
return self.location
def distance_to(self, other: Location) -> float:
return self.location.distance(other)
def get_cooldown(self, location: Location) -> int:
_time, history_location = self.get_last_activity()
if time and history_location:
cooldown = history_location.get_cooldown(location)
current_cooldown = ceil((_time + timedelta(minutes=cooldown) - datetime.now()).total_seconds() / 60)
if current_cooldown < 0:
current_cooldown = 0
else:
current_cooldown = 0
return current_cooldown
def get_current_cooldown(self) -> int:
self.cooldown = self.get_cooldown(self.location)
return self.cooldown
def change_gps_by_query(self, query: str, do_activity: bool = False) -> None:
self.set_location_with_query(query)
if do_activity:
self.do_activity(self.location)
def change_gps_by_location(self, location: Location, do_activity: bool = False) -> None:
self.set_location(location)
if do_activity:
self.do_activity(self.location)
def set_last_location(self) -> None:
2 years ago
_, location = self.get_last_activity()
self.set_location(location)
def set_speed(self, speed: float) -> None:
2 years ago
self.speed = speed
def gpx_walking(self, gpx_file: Path) -> None:
2 years ago
with open(gpx_file) as f:
gpx = gpxpy.parse(f)
gpx_points = []
for track in gpx.tracks:
for segment in track.segments:
for point in segment.points:
gpx_points.append(Location(point.latitude, point.longitude))
num_location_points = len(gpx_points)
point_lst = []
for i in range(num_location_points - 1):
start = gpx_points[i]
end = gpx_points[i+1]
distance = start.calculate_distance(end)
_time = distance / self.speed
num_points = int((distance * 1000) / self.speed) + 1
intermediate_points = start.generate_intermediate_points(end, num_points)
point_lst = point_lst + intermediate_points
print("HERE")
print(point_lst[:5])
for point in point_lst:
self.set_location(point)
time.sleep(TIME)