mavericks

This commit is contained in:
Eriks K 2020-07-09 17:42:15 +03:00
parent d938908986
commit 5a8a0a3920
4 changed files with 38 additions and 34 deletions

View File

@ -5,7 +5,6 @@
__author__ = """Eriks Karls""" __author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv' __email__ = 'eriks@72.lv'
__version__ = '0.20.3.6' __version__ = '0.20.3.6'
__commit_id__ = "ffbbd25"
from erepublik import classes, utils, constants from erepublik import classes, utils, constants
from erepublik.citizen import Citizen from erepublik.citizen import Citizen

View File

@ -22,12 +22,13 @@ class BaseCitizen(access_points.CitizenAPI):
ot_points: int = 0 ot_points: int = 0
food: Dict[str, int] = {"q1": 0, "q2": 0, "q3": 0, "q4": 0, "q5": 0, "q6": 0, "q7": 0, "total": 0} food: Dict[str, int] = {"q1": 0, "q2": 0, "q3": 0, "q4": 0, "q5": 0, "q6": 0, "q7": 0, "total": 0}
eb_normal = 0 eb_normal: int = 0
eb_double = 0 eb_double: int = 0
eb_small = 0 eb_small: int = 0
division = 0 division: int = 0
maverick: bool = False
eday = 0 eday: int = 0
config: classes.Config = None config: classes.Config = None
energy: classes.Energy = None energy: classes.Energy = None
@ -40,12 +41,10 @@ class BaseCitizen(access_points.CitizenAPI):
r: Response = None r: Response = None
name: str = "Not logged in!" name: str = "Not logged in!"
logged_in: bool = False logged_in: bool = False
commit_id: str = ""
restricted_ip: bool = False restricted_ip: bool = False
def __init__(self, email: str = "", password: str = ""): def __init__(self, email: str = "", password: str = ""):
super().__init__() super().__init__()
self.commit_id = utils.COMMIT_ID
self.config = classes.Config() self.config = classes.Config()
self.energy = classes.Energy() self.energy = classes.Energy()
self.details = classes.Details() self.details = classes.Details()
@ -210,11 +209,12 @@ class BaseCitizen(access_points.CitizenAPI):
self.details.xp = citizen.get("currentExperiencePoints", 0) self.details.xp = citizen.get("currentExperiencePoints", 0)
self.details.daily_task_done = citizen.get("dailyTasksDone", False) self.details.daily_task_done = citizen.get("dailyTasksDone", False)
self.details.daily_task_reward = citizen.get("hasReward", False) self.details.daily_task_reward = citizen.get("hasReward", False)
self.maverick = citizen.get("canSwitchDivisions", False)
if citizen.get("dailyOrderDone", False) and not citizen.get("hasDailyOrderReward", False): if citizen.get("dailyOrderDone", False) and not citizen.get("hasDailyOrderReward", False):
self._post_military_group_missions() self._post_military_group_missions()
self.details.next_pp.sort() self.details.next_pp.sort()
for skill in citizen.get("mySkills", {}).values(): for skill in citizen.get("terrainSkills", {}).values():
self.details.mayhem_skills.update({int(skill["terrain_id"]): int(skill["skill_points"])}) self.details.mayhem_skills.update({int(skill["terrain_id"]): int(skill["skill_points"])})
if citizen.get('party', []): if citizen.get('party', []):
@ -380,9 +380,9 @@ class BaseCitizen(access_points.CitizenAPI):
def report_error(self, msg: str = "", is_warning: bool = False): def report_error(self, msg: str = "", is_warning: bool = False):
if is_warning: if is_warning:
utils.process_warning(msg, self.name, sys.exc_info(), self, self.commit_id) utils.process_warning(msg, self.name, sys.exc_info(), self)
else: else:
utils.process_error(msg, self.name, sys.exc_info(), self, self.commit_id, None) utils.process_error(msg, self.name, sys.exc_info(), self, None, None)
def sleep(self, seconds: int): def sleep(self, seconds: int):
if seconds < 0: if seconds < 0:
@ -1491,16 +1491,18 @@ class CitizenMilitary(CitizenTravel):
for battle in reversed(self.sorted_battles(True, True)): for battle in reversed(self.sorted_battles(True, True)):
for division in battle.div.values(): for division in battle.div.values():
if not division.terrain: if not division.terrain:
if division.is_air: if division.is_air and self.config.air:
medal = self.get_battle_round_data(division)[ medal = self.get_battle_round_data(division)[
self.details.citizenship == division.battle.defender.id] self.details.citizenship == division.battle.defender.id]
if not medal and division.battle.start: if not medal and division.battle.start:
return division return division
else: else:
air_divs.append((division, medal.get('1').get('raw_value'))) air_divs.append((division, medal.get('1').get('raw_value')))
else: elif self.config.ground:
medal = self.get_battle_round_data(division)[ if not division.div == self.division and not self.maverick:
self.details.citizenship == division.battle.defender.id] continue
division_medals = self.get_battle_round_data(division)
medal = division_medals[self.details.citizenship == division.battle.defender.country]
if not medal and division.battle.start: if not medal and division.battle.start:
return division return division
else: else:
@ -1531,7 +1533,7 @@ class CitizenMilitary(CitizenTravel):
if self.config.air and div.is_air: if self.config.air and div.is_air:
battle_zone = div battle_zone = div
break break
elif self.config.ground and not div.is_air and div.div == self.division: elif self.config.ground and not div.is_air and (div.div == self.division or self.maverick):
battle_zone = div battle_zone = div
break break
else: else:
@ -1572,11 +1574,11 @@ class CitizenMilitary(CitizenTravel):
if not self.travel_to_battle(battle, countries_to_travel): if not self.travel_to_battle(battle, countries_to_travel):
break break
self.change_division(battle, battle_zone) if self.change_division(battle, battle_zone):
self.set_default_weapon(battle, battle_zone) self.set_default_weapon(battle, battle_zone)
self.fight(battle, battle_zone, side) self.fight(battle, battle_zone, side)
self.travel_to_residence() self.travel_to_residence()
break break
def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None, count: int = None) -> int: def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None, count: int = None) -> int:
"""Fight in a battle. """Fight in a battle.
@ -1607,6 +1609,8 @@ class CitizenMilitary(CitizenTravel):
if count is None: if count is None:
count = self.should_fight()[0] count = self.should_fight()[0]
self.write_log(f"Fighting in battle for {battle.region_name} on {side} side\n{battle}\n{str(division)}")
total_damage = 0 total_damage = 0
total_hits = 0 total_hits = 0
while ok_to_fight and error_count < 10 and count > 0: while ok_to_fight and error_count < 10 and count > 0:
@ -1647,6 +1651,9 @@ class CitizenMilitary(CitizenTravel):
pass pass
elif r_json.get("message") == "NOT_ENOUGH_WEAPONS": elif r_json.get("message") == "NOT_ENOUGH_WEAPONS":
self.set_default_weapon(battle, division) self.set_default_weapon(battle, division)
elif r_json.get("message") == "Cannot activate a zone with a non-native division":
self.write_log("Wrong division!!")
return 0, 10, 0
elif r_json.get("message") == "FIGHT_DISABLED": elif r_json.get("message") == "FIGHT_DISABLED":
self._post_main_profile_update('options', self._post_main_profile_update('options',
params='{"optionName":"enable_web_deploy","optionValue":"off"}') params='{"optionName":"enable_web_deploy","optionValue":"off"}')
@ -1714,7 +1721,7 @@ class CitizenMilitary(CitizenTravel):
self._report_action("MILITARY_BOMB", f"Deployed {deployed_count} bombs in battle {battle.id}") self._report_action("MILITARY_BOMB", f"Deployed {deployed_count} bombs in battle {battle.id}")
return deployed_count return deployed_count
def change_division(self, battle: classes.Battle, division: classes.BattleDivision): def change_division(self, battle: classes.Battle, division: classes.BattleDivision) -> bool:
"""Change division. """Change division.
:param battle: Battle :param battle: Battle
@ -1723,8 +1730,12 @@ class CitizenMilitary(CitizenTravel):
:type division: BattleDivision :type division: BattleDivision
:return: :return:
""" """
self._post_main_battlefield_change_division(battle.id, division.id) resp = self._post_main_battlefield_change_division(battle.id, division.id)
self._report_action("MILITARY_DIV_SWITCH", f"Switched to d{division.div} in battle {battle.id}") if resp.json().get('error'):
self.write_log(resp.json().get('message'))
return False
self._report_action("MILITARY_DIV_SWITCH", f"Switched to d{division.div} in battle {battle.id}", kwargs=resp.json())
return True
def get_ground_hit_dmg_value(self, rang: int = None, strength: float = None, elite: bool = None, ne: bool = False, def get_ground_hit_dmg_value(self, rang: int = None, strength: float = None, elite: bool = None, ne: bool = False,
booster_50: bool = False, booster_100: bool = False, tp: bool = True) -> Decimal: booster_50: bool = False, booster_100: bool = False, tp: bool = True) -> Decimal:

View File

@ -13,14 +13,14 @@ from typing import Any, List, Mapping, Optional, Union
import requests import requests
from . import __commit_id__, __version__, constants from . import __version__, constants
try: try:
import simplejson as json import simplejson as json
except ImportError: except ImportError:
import json import json
__all__ = ['COMMIT_ID', 'VERSION', 'calculate_hit', 'caught_error', 'date_from_eday', 'eday_from_date', __all__ = ['VERSION', 'calculate_hit', 'caught_error', 'date_from_eday', 'eday_from_date',
'get_air_hit_dmg_value', 'get_file', 'get_ground_hit_dmg_value', 'get_sleep_seconds', 'good_timedelta', 'get_air_hit_dmg_value', 'get_file', 'get_ground_hit_dmg_value', 'get_sleep_seconds', 'good_timedelta',
'interactive_sleep', 'json', 'localize_dt', 'localize_timestamp', 'normalize_html_json', 'now', 'interactive_sleep', 'json', 'localize_dt', 'localize_timestamp', 'normalize_html_json', 'now',
'process_error', 'process_warning', 'send_email', 'silent_sleep', 'slugify', 'write_file', 'process_error', 'process_warning', 'send_email', 'silent_sleep', 'slugify', 'write_file',
@ -30,7 +30,6 @@ if not sys.version_info >= (3, 7):
raise AssertionError('This script requires Python version 3.7 and higher\n' raise AssertionError('This script requires Python version 3.7 and higher\n'
'But Your version is v{}.{}.{}'.format(*sys.version_info)) 'But Your version is v{}.{}.{}'.format(*sys.version_info))
COMMIT_ID: str = __commit_id__
VERSION: str = __version__ VERSION: str = __version__
@ -238,7 +237,7 @@ def normalize_html_json(js: str) -> str:
def caught_error(e: Exception): def caught_error(e: Exception):
process_error(str(e), "Unclassified", sys.exc_info(), None, COMMIT_ID, False) process_error(str(e), "Unclassified", sys.exc_info(), interactive=False)
def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commit_id: str = None, def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commit_id: str = None,
@ -260,7 +259,7 @@ def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commi
""" """
type_, value_, traceback_ = exc_info type_, value_, traceback_ = exc_info
content = [log_info] content = [log_info]
content += [f"eRepublik version {VERSION}, commit id {COMMIT_ID}"] content += [f"eRepublik version {VERSION}"]
if commit_id: if commit_id:
content += [f"Commit id {commit_id}"] content += [f"Commit id {commit_id}"]
content += [str(value_), str(type_), ''.join(traceback.format_tb(traceback_))] content += [str(value_), str(type_), ''.join(traceback.format_tb(traceback_))]

View File

@ -1,5 +0,0 @@
#!/bin/bash
commit=$(git log -1 --pretty=format:%h)
sed -i.bak -E "s|__commit_id__ = \".+\"|__commit_id__ = \"${commit}\"|g" erepublik/__init__.py
rm erepublik/__init__.py.bak