Bomb deploy bugfix
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
__author__ = """Eriks Karls"""
|
__author__ = """Eriks Karls"""
|
||||||
__email__ = 'eriks@72.lv'
|
__email__ = 'eriks@72.lv'
|
||||||
__version__ = '0.20.0'
|
__version__ = '0.20.0'
|
||||||
__commit_id__ = "4e33717"
|
__commit_id__ = "845cd8d"
|
||||||
|
|
||||||
from erepublik import classes, utils
|
from erepublik import classes, utils
|
||||||
from erepublik.citizen import Citizen
|
from erepublik.citizen import Citizen
|
||||||
|
@ -887,7 +887,11 @@ class CitizenCompanies(BaseCitizen):
|
|||||||
|
|
||||||
Storage={1000: 1, 2000: 2} <- Building_type 2
|
Storage={1000: 1, 2000: 2} <- Building_type 2
|
||||||
"""
|
"""
|
||||||
company_name = self.factories[industry_id]
|
company_name = {1: "Food", 2: "Weapons", 4: "House", 23: "Aircraft",
|
||||||
|
7: "FRM q1", 8: "FRM q2", 9: "FRM q3", 10: "FRM q4", 11: "FRM q5",
|
||||||
|
12: "WRM q1", 13: "WRM q2", 14: "WRM q3", 15: "WRM q4", 16: "WRM q5",
|
||||||
|
18: "HRM q1", 19: "HRM q2", 20: "HRM q3", 21: "HRM q4", 22: "HRM q5",
|
||||||
|
24: "ARM q1", 25: "ARM q2", 26: "ARM q3", 27: "ARM q4", 28: "ARM q5", }[industry_id]
|
||||||
if building_type == 2:
|
if building_type == 2:
|
||||||
company_name = f"Storage"
|
company_name = f"Storage"
|
||||||
self.write_log(f"{company_name} created!")
|
self.write_log(f"{company_name} created!")
|
||||||
@ -1383,7 +1387,7 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
if not battle.is_air:
|
if not battle.is_air:
|
||||||
for weapon in available_weapons:
|
for weapon in available_weapons:
|
||||||
try:
|
try:
|
||||||
if weapon['weaponQuantity'] > 30 and weapon['damage'] > weapon_damage:
|
if weapon['weaponQuantity'] > 30 and weapon['weaponInfluence'] > weapon_damage:
|
||||||
weapon_quality = int(weapon['weaponId'])
|
weapon_quality = int(weapon['weaponId'])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
@ -1700,6 +1704,8 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
deployed_count += 1
|
deployed_count += 1
|
||||||
elif r.get('message') == 'LOCKED':
|
elif r.get('message') == 'LOCKED':
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
|
else:
|
||||||
|
errors += 1
|
||||||
|
|
||||||
if has_traveled:
|
if has_traveled:
|
||||||
self.travel_to_residence()
|
self.travel_to_residence()
|
||||||
@ -2230,6 +2236,7 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
self.telegram.send_message(f"*Started* {utils.now():%F %T}")
|
self.telegram.send_message(f"*Started* {utils.now():%F %T}")
|
||||||
|
|
||||||
self.__last_full_update = utils.good_timedelta(self.now, - timedelta(minutes=5))
|
self.__last_full_update = utils.good_timedelta(self.now, - timedelta(minutes=5))
|
||||||
|
self.update_all(True)
|
||||||
|
|
||||||
def update_citizen_info(self, html: str = None):
|
def update_citizen_info(self, html: str = None):
|
||||||
"""
|
"""
|
||||||
@ -2279,7 +2286,7 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
|
|
||||||
if (title, reward) not in data:
|
if (title, reward) not in data:
|
||||||
data[(title, reward)] = {'about': about, 'kind': title, 'reward': reward, "count": count,
|
data[(title, reward)] = {'about': about, 'kind': title, 'reward': reward, "count": count,
|
||||||
"currency": currency, "params": params}
|
"currency": currency, "params": medal.get('details', {})}
|
||||||
else:
|
else:
|
||||||
data[(title, reward)]['count'] += count
|
data[(title, reward)]['count'] += count
|
||||||
self._post_main_global_alerts_close(medal.get('id'))
|
self._post_main_global_alerts_close(medal.get('id'))
|
||||||
@ -2521,3 +2528,22 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
|
|
||||||
self.update_companies()
|
self.update_companies()
|
||||||
return bool(self.my_companies.get_total_wam_count())
|
return bool(self.my_companies.get_total_wam_count())
|
||||||
|
|
||||||
|
def sorted_battles(self, sort_by_time: bool = True) -> List[int]:
|
||||||
|
battles = self.reporter.fetch_battle_priorities(self.details.current_country)
|
||||||
|
return battles + super().sorted_battles(sort_by_time)
|
||||||
|
|
||||||
|
def command_central(self):
|
||||||
|
while not self.stop_threads.is_set():
|
||||||
|
try:
|
||||||
|
tasks = self.reporter.fetch_tasks()
|
||||||
|
for task, args in tasks:
|
||||||
|
try:
|
||||||
|
fn = getattr(self, task)
|
||||||
|
if callable(fn):
|
||||||
|
fn(*args)
|
||||||
|
except AttributeError:
|
||||||
|
continue
|
||||||
|
self.stop_threads.wait(90)
|
||||||
|
except: # noqa
|
||||||
|
self.report_error("Command central has broken")
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import decimal
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import threading
|
import threading
|
||||||
from collections import defaultdict, deque
|
from collections import defaultdict, deque
|
||||||
from typing import Any, Dict, Iterable, List, NamedTuple, Tuple, Union
|
from decimal import Decimal
|
||||||
|
from typing import Any, Dict, Iterable, List, NamedTuple, Tuple, Union, Optional
|
||||||
|
|
||||||
from requests import Response, Session, post
|
from requests import Response, Session, post
|
||||||
|
|
||||||
@ -14,6 +14,12 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
INDUSTRIES = {1: "Food", 2: "Weapons", 4: "House", 23: "Aircraft",
|
||||||
|
7: "FRM q1", 8: "FRM q2", 9: "FRM q3", 10: "FRM q4", 11: "FRM q5",
|
||||||
|
12: "WRM q1", 13: "WRM q2", 14: "WRM q3", 15: "WRM q4", 16: "WRM q5",
|
||||||
|
18: "HRM q1", 19: "HRM q2", 20: "HRM q3", 21: "HRM q4", 22: "HRM q5",
|
||||||
|
24: "ARM q1", 25: "ARM q2", 26: "ARM q3", 27: "ARM q4", 28: "ARM q5", }
|
||||||
|
|
||||||
|
|
||||||
class ErepublikException(Exception):
|
class ErepublikException(Exception):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
@ -470,12 +476,27 @@ class Reporter:
|
|||||||
def report_promo(self, kind: str, time_until: datetime.datetime):
|
def report_promo(self, kind: str, time_until: datetime.datetime):
|
||||||
self._req.post(f"{self.url}/promos/add/", data=dict(kind=kind, time_untill=time_until))
|
self._req.post(f"{self.url}/promos/add/", data=dict(kind=kind, time_untill=time_until))
|
||||||
|
|
||||||
|
def fetch_battle_priorities(self, country_id: int) -> List[int]:
|
||||||
|
try:
|
||||||
|
battle_response = self._req.get(f'{self.url}/api/v1/battles/{country_id}')
|
||||||
|
return battle_response.json().get('battle_ids', [])
|
||||||
|
except: # noqa
|
||||||
|
return []
|
||||||
|
|
||||||
|
def fetch_tasks(self) -> Optional[Tuple[str, Tuple[Any]]]:
|
||||||
|
try:
|
||||||
|
task_response = self._req.get(f'{self.url}/api/v1/command',
|
||||||
|
params=dict(citizen=self.citizen_id, key=self.key))
|
||||||
|
return task_response.json().get('task_collection')
|
||||||
|
except: # noqa
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class MyJSONEncoder(json.JSONEncoder):
|
class MyJSONEncoder(json.JSONEncoder):
|
||||||
def default(self, o):
|
def default(self, o):
|
||||||
from erepublik.citizen import Citizen
|
from erepublik.citizen import Citizen
|
||||||
if isinstance(o, decimal.Decimal):
|
if isinstance(o, Decimal):
|
||||||
return float("{:.02f}".format(o))
|
return float(f"{o:.02f}")
|
||||||
elif isinstance(o, datetime.datetime):
|
elif isinstance(o, datetime.datetime):
|
||||||
return dict(__type__='datetime', date=o.strftime("%Y-%m-%d"), time=o.strftime("%H:%M:%S"),
|
return dict(__type__='datetime', date=o.strftime("%Y-%m-%d"), time=o.strftime("%H:%M:%S"),
|
||||||
tzinfo=o.tzinfo.tzname if o.tzinfo else None)
|
tzinfo=o.tzinfo.tzname if o.tzinfo else None)
|
||||||
|
Reference in New Issue
Block a user