Compare commits

...

8 Commits

Author SHA1 Message Date
9df9c1cd87 Bump version: 0.20.3.9 → 0.20.3.10 2020-07-10 00:47:42 +03:00
1b004f163a bugfix 2020-07-10 00:47:36 +03:00
72bd2787d3 Bump version: 0.20.3.8 → 0.20.3.9 2020-07-09 19:11:04 +03:00
bfa6cb1e78 bugfix 2020-07-09 19:10:55 +03:00
1db7c98b47 Bump version: 0.20.3.7 → 0.20.3.8 2020-07-09 18:51:09 +03:00
1f21a71c74 bugfix 2020-07-09 18:51:00 +03:00
0531c8997b Bump version: 0.20.3.6 → 0.20.3.7 2020-07-09 17:42:24 +03:00
5a8a0a3920 mavericks 2020-07-09 17:42:15 +03:00
8 changed files with 49 additions and 41 deletions

View File

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

View File

@ -22,12 +22,13 @@ class BaseCitizen(access_points.CitizenAPI):
ot_points: int = 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_double = 0
eb_small = 0
division = 0
eb_normal: int = 0
eb_double: int = 0
eb_small: int = 0
division: int = 0
maverick: bool = False
eday = 0
eday: int = 0
config: classes.Config = None
energy: classes.Energy = None
@ -40,12 +41,10 @@ class BaseCitizen(access_points.CitizenAPI):
r: Response = None
name: str = "Not logged in!"
logged_in: bool = False
commit_id: str = ""
restricted_ip: bool = False
def __init__(self, email: str = "", password: str = ""):
super().__init__()
self.commit_id = utils.COMMIT_ID
self.config = classes.Config()
self.energy = classes.Energy()
self.details = classes.Details()
@ -210,11 +209,12 @@ class BaseCitizen(access_points.CitizenAPI):
self.details.xp = citizen.get("currentExperiencePoints", 0)
self.details.daily_task_done = citizen.get("dailyTasksDone", 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):
self._post_military_group_missions()
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"])})
if citizen.get('party', []):
@ -380,9 +380,9 @@ class BaseCitizen(access_points.CitizenAPI):
def report_error(self, msg: str = "", is_warning: bool = False):
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:
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):
if seconds < 0:
@ -1491,16 +1491,18 @@ class CitizenMilitary(CitizenTravel):
for battle in reversed(self.sorted_battles(True, True)):
for division in battle.div.values():
if not division.terrain:
if division.is_air:
if division.is_air and self.config.air:
medal = self.get_battle_round_data(division)[
self.details.citizenship == division.battle.defender.id]
if not medal and division.battle.start:
return division
else:
air_divs.append((division, medal.get('1').get('raw_value')))
else:
medal = self.get_battle_round_data(division)[
self.details.citizenship == division.battle.defender.id]
elif self.config.ground:
if not division.div == self.division and not self.maverick:
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:
return division
else:
@ -1531,7 +1533,7 @@ class CitizenMilitary(CitizenTravel):
if self.config.air and div.is_air:
battle_zone = div
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
break
else:
@ -1572,11 +1574,11 @@ class CitizenMilitary(CitizenTravel):
if not self.travel_to_battle(battle, countries_to_travel):
break
self.change_division(battle, battle_zone)
self.set_default_weapon(battle, battle_zone)
self.fight(battle, battle_zone, side)
self.travel_to_residence()
break
if self.change_division(battle, battle_zone):
self.set_default_weapon(battle, battle_zone)
self.fight(battle, battle_zone, side)
self.travel_to_residence()
break
def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None, count: int = None) -> int:
"""Fight in a battle.
@ -1607,6 +1609,8 @@ class CitizenMilitary(CitizenTravel):
if count is None:
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_hits = 0
while ok_to_fight and error_count < 10 and count > 0:
@ -1647,6 +1651,9 @@ class CitizenMilitary(CitizenTravel):
pass
elif r_json.get("message") == "NOT_ENOUGH_WEAPONS":
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":
self._post_main_profile_update('options',
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}")
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.
:param battle: Battle
@ -1723,8 +1730,12 @@ class CitizenMilitary(CitizenTravel):
:type division: BattleDivision
:return:
"""
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}")
resp = self._post_main_battlefield_change_division(battle.id, division.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,
booster_50: bool = False, booster_100: bool = False, tp: bool = True) -> Decimal:

View File

@ -548,8 +548,10 @@ class Reporter:
if self.__to_update:
for unreported_data in self.__to_update:
unreported_data.update(player_id=self.citizen_id, key=self.key)
unreported_data = utils.json.load(utils.json.dumps(unreported_data, cls=MyJSONEncoder, sort_keys=True))
self._req.post("{}/bot/update".format(self.url), json=unreported_data)
self.__to_update.clear()
data = utils.json.loads(utils.json.dumps(data, cls=MyJSONEncoder, sort_keys=True))
r = self._req.post("{}/bot/update".format(self.url), json=data)
return r

View File

@ -47,15 +47,17 @@ class Country:
class Industries:
__by_name = {'food': 1, 'weapons': 2, 'house': 4, 'aircraft': 23,
'foodRaw': 7, 'weaponsRaw': 12, 'houseRaw': 18, 'aircraftRaw': 24,
'frm': 7, 'wrm': 12, 'hrm': 18, 'arm': 24,
'frm q1': 7, 'frm q2': 8, 'frm q3': 9, 'frm q4': 10, 'frm q5': 11,
'wrm q1': 12, 'wrm q2': 13, 'wrm q3': 14, 'wrm q4': 15, 'wrm q5': 16,
'hrm q1': 18, 'hrm q2': 19, 'hrm q3': 20, 'hrm q4': 21, 'hrm q5': 22,
'arm q1': 24, 'arm q2': 25, 'arm q3': 26, 'arm q4': 27, 'arm q5': 28}
__by_id = {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"}
7: "foodRaw", 8: "FRM q2", 9: "FRM q3", 10: "FRM q4", 11: "FRM q5",
12: "weaponsRaw", 13: "WRM q2", 14: "WRM q3", 15: "WRM q4", 16: "WRM q5",
18: "houseRaw", 19: "HRM q2", 20: "HRM q3", 21: "HRM q4", 22: "HRM q5",
24: "aircraftRaw", 25: "ARM q2", 26: "ARM q3", 27: "ARM q4", 28: "ARM q5"}
def __getitem__(self, item) -> Optional[Union[int, str]]:
if isinstance(item, int):

View File

@ -13,14 +13,14 @@ from typing import Any, List, Mapping, Optional, Union
import requests
from . import __commit_id__, __version__, constants
from . import __version__, constants
try:
import simplejson as json
except ImportError:
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',
'interactive_sleep', 'json', 'localize_dt', 'localize_timestamp', 'normalize_html_json', 'now',
'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'
'But Your version is v{}.{}.{}'.format(*sys.version_info))
COMMIT_ID: str = __commit_id__
VERSION: str = __version__
@ -238,7 +237,7 @@ def normalize_html_json(js: str) -> str:
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,
@ -260,7 +259,7 @@ def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commi
"""
type_, value_, traceback_ = exc_info
content = [log_info]
content += [f"eRepublik version {VERSION}, commit id {COMMIT_ID}"]
content += [f"eRepublik version {VERSION}"]
if commit_id:
content += [f"Commit id {commit_id}"]
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

View File

@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.20.3.6
current_version = 0.20.3.10
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?

View File

@ -43,6 +43,6 @@ setup(
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/eeriks/erepublik/',
version='0.20.3.6',
version='0.20.3.10',
zip_safe=False,
)