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.

61 lines
1.9 KiB

2 years ago
from geopy.geocoders import Nominatim
2 years ago
from ispoof.spoofer.location import Location
from ispoof.lists.playerhistory import PlayerHistory
from datetime import datetime, timedelta
from math import ceil
2 years ago
class Player:
def __init__(self, engine, location=None, cooldown=0):
self.location = location
self.cooldown = cooldown
self.history = PlayerHistory(engine=engine)
2 years ago
def set_location_with_query(self, query):
loc = Nominatim(user_agent="GetLoc")
get_loc = loc.geocode(query)
2 years ago
self.location = Location(get_loc.latitude, get_loc.longitude)
def get_last_activity(self):
return self.history.get_last_activity()
def set_location(self, location: Location):
2 years ago
self.location = location
def do_activity(self, location: Location):
return self.history.add_activity(location)
2 years ago
def get_location(self):
return self.location
def distance_to(self, other):
return self.location.distance(other)
def get_cooldown(self, location):
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):
self.cooldown = self.get_cooldown(self.location)
return self.cooldown
def change_gps_by_query(self, query: str, do_activity=False):
self.set_location_with_query(query)
if do_activity:
self.do_activity(self.location)
def change_gps_by_location(self, location: Location, do_activity=False):
self.set_location(location)
if do_activity:
self.do_activity(self.location)