Updated wars list, added default weapon choosing (q7 - ground, bare hands - air)
This commit is contained in:
parent
fd56c6c389
commit
f294506a2d
@ -544,7 +544,7 @@ class Citizen(CitizenAPI):
|
||||
if not self.details.current_country:
|
||||
self.update_citizen_info()
|
||||
|
||||
resp_json = self._get_military_campaigns().json()
|
||||
resp_json = self._get_military_campaigns_json_list().json()
|
||||
if resp_json.get("countries"):
|
||||
self.all_battles = {}
|
||||
self.countries = {}
|
||||
@ -653,8 +653,7 @@ class Citizen(CitizenAPI):
|
||||
break
|
||||
error_count = 0
|
||||
while self.energy.food_fights > 5 and error_count < 20:
|
||||
errors = self.fight(battle_id, side_id=side, is_air=False,
|
||||
count=self.energy.food_fights - 5)
|
||||
errors = self.fight(battle_id, side_id=side, count=self.energy.food_fights - 5)
|
||||
if errors:
|
||||
error_count += errors
|
||||
if self.config.epic_hunt_ebs:
|
||||
@ -790,15 +789,17 @@ class Citizen(CitizenAPI):
|
||||
|
||||
if not self.travel_to_battle(battle_id, country_ids_to_travel):
|
||||
break
|
||||
self.fight(battle_id, side_id, battle.is_air)
|
||||
self.fight(battle_id, side_id)
|
||||
self.travel_to_residence()
|
||||
self.collect_weekly_reward()
|
||||
break
|
||||
|
||||
def fight(self, battle_id: int, side_id: int, is_air: bool = False, count: int = None):
|
||||
if not is_air and self.config.boosters:
|
||||
def fight(self, battle_id: int, side_id: int, count: int = None):
|
||||
battle = self.all_battles[battle_id]
|
||||
zone_id = battle.div[11 if battle.is_air else self.division].battle_zone_id
|
||||
if not battle.is_air and self.config.boosters:
|
||||
self.activate_dmg_booster()
|
||||
data = dict(sideId=side_id, battleId=battle_id)
|
||||
self.set_default_weapon(battle_id)
|
||||
error_count = 0
|
||||
ok_to_fight = True
|
||||
if count is None:
|
||||
@ -809,7 +810,7 @@ class Citizen(CitizenAPI):
|
||||
|
||||
while ok_to_fight and error_count < 10 and count > 0:
|
||||
while all((count > 0, error_count < 10, self.energy.recovered >= 50)):
|
||||
hits, error, damage = self._shoot(is_air, data)
|
||||
hits, error, damage = self._shoot(battle.is_air, battle_id, side_id, zone_id)
|
||||
count -= hits
|
||||
total_hits += hits
|
||||
total_damage += damage
|
||||
@ -821,15 +822,15 @@ class Citizen(CitizenAPI):
|
||||
ok_to_fight = False
|
||||
if total_damage:
|
||||
self.reporter.report_action(json_val=dict(battle=battle_id, side=side_id, dmg=total_damage,
|
||||
air=is_air, hits=total_hits), action="FIGHT")
|
||||
air=battle.is_air, hits=total_hits), action="FIGHT")
|
||||
if error_count:
|
||||
return error_count
|
||||
|
||||
def _shoot(self, air: bool, data: dict):
|
||||
def _shoot(self, air: bool, battle_id: int, side_id: int, zone_id: int):
|
||||
if air:
|
||||
response = self._post_military_fight_air(data['battleId'], data['sideId'])
|
||||
response = self._post_military_fight_air(battle_id, side_id, zone_id)
|
||||
else:
|
||||
response = self._post_military_fight_ground(data['battleId'], data['sideId'])
|
||||
response = self._post_military_fight_ground(battle_id, side_id, zone_id)
|
||||
|
||||
if "Zone is not meant for " in response.text:
|
||||
self.sleep(5)
|
||||
@ -844,9 +845,11 @@ class Citizen(CitizenAPI):
|
||||
if j_resp.get("error"):
|
||||
if j_resp.get("message") == "SHOOT_LOCKOUT" or j_resp.get("message") == "ZONE_INACTIVE":
|
||||
pass
|
||||
elif j_resp.get("message") == "NOT_ENOUGH_WEAPONS":
|
||||
self.set_default_weapon(battle_id)
|
||||
else:
|
||||
if j_resp.get("message") == "UNKNOWN_SIDE":
|
||||
self._rw_choose_side(data["battleId"], data["sideId"])
|
||||
self._rw_choose_side(battle_id, side_id)
|
||||
err = True
|
||||
elif j_resp.get("message") == "ENEMY_KILLED":
|
||||
hits = (self.energy.recovered - j_resp["details"]["wellness"]) // 10
|
||||
@ -2040,3 +2043,24 @@ class Citizen(CitizenAPI):
|
||||
def speedup_map_quest_node(self, node_id: int):
|
||||
node = self.get_anniversary_quest_data().get('cities', {}).get(str(node_id), {})
|
||||
return self._post_map_rewards_speedup(node_id, node.get("skipCost", 0))
|
||||
|
||||
def get_available_weapons(self, battle_id: int):
|
||||
return self._get_military_show_weapons(battle_id).json()
|
||||
|
||||
def set_default_weapon(self, battle_id: int) -> int:
|
||||
battle = self.all_battles[battle_id]
|
||||
battle_zone = battle.div[11 if battle.is_air else self.division].battle_zone_id
|
||||
available_weapons = self._get_military_show_weapons(battle_id).json()
|
||||
weapon_quality = -1
|
||||
if not battle.is_air:
|
||||
for weapon in available_weapons:
|
||||
if weapon['weaponId'] == 7 and weapon['weaponQuantity'] > 30:
|
||||
weapon_quality = 7
|
||||
break
|
||||
return self.change_weapon(battle_id, weapon_quality)
|
||||
|
||||
def change_weapon(self, battle_id: int, weapon_quality: int) -> int:
|
||||
battle = self.all_battles[battle_id]
|
||||
battle_zone = battle.div[11 if battle.is_air else self.division].battle_zone_id
|
||||
r = self._post_military_change_weapon(battle_id, battle_zone, weapon_quality)
|
||||
return r.json().get('weaponInfluence')
|
||||
|
@ -452,8 +452,8 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
"""
|
||||
self._req = SlowRequests()
|
||||
|
||||
def post(self, url: str, *args, **kwargs) -> Response:
|
||||
return self._req.post(url, *args, **kwargs)
|
||||
def post(self, url: str, data=None, json=None, **kwargs) -> Response:
|
||||
return self._req.post(url, data, json, **kwargs)
|
||||
|
||||
def get(self, url: str, **kwargs) -> Response:
|
||||
return self._req.get(url, **kwargs)
|
||||
@ -464,6 +464,9 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
def _get_military_battlefield_choose_side(self, battle: int, side: int) -> Response:
|
||||
return self.get("{}/military/battlefield-choose-side/{}/{}".format(self.url, battle, side))
|
||||
|
||||
def _get_military_show_weapons(self, battle: int) -> Response:
|
||||
return self.get("{}/military/show-weapons".format(self.url), params={'_token': self.token, 'battleId': battle})
|
||||
|
||||
def _get_candidate_party(self, party_slug: str) -> Response:
|
||||
return self.post("{}/candidate/{}".format(self.url, party_slug))
|
||||
|
||||
@ -529,6 +532,9 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
def _get_military_campaigns(self) -> Response:
|
||||
return self.get("{}/military/campaigns-new/".format(self.url))
|
||||
|
||||
def _get_military_campaigns_json_list(self) -> Response:
|
||||
return self.get("{}/military/campaignsJson/list".format(self.url))
|
||||
|
||||
def _get_military_show_weapons(self, battle_id: int) -> Response:
|
||||
params = {"_token": self.token, "battleId": battle_id}
|
||||
return self.get("{}/military/show-weapons".format(self.url), params=params)
|
||||
@ -757,6 +763,10 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data = dict(type=kind, quality=quality, duration=duration, battleId=battle, _token=self.token)
|
||||
return self.post("{}/military/fight-activateBooster".format(self.url), data=data)
|
||||
|
||||
def _post_military_change_weapon(self, battle: int, battle_zone: int, weapon_level: int,) -> Response:
|
||||
data = dict(battleId=battle, _token=self.token, battleZoneId=battle_zone, customizationLevel=weapon_level)
|
||||
return self.post("{}/military/change-weapon".format(self.url), data=data)
|
||||
|
||||
def _post_login(self, email: str, password: str) -> Response:
|
||||
data = dict(csrf_token=self.token, citizen_email=email, citizen_password=password, remember='on')
|
||||
return self.post("{}/login".format(self.url), data=data)
|
||||
@ -789,12 +799,12 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data = dict(battleId=battle_id, bombId=bomb_id, _token=self.token)
|
||||
return self.post("{}/military/deploy-bomb".format(self.url), data=data)
|
||||
|
||||
def _post_military_fight_air(self, battle_id: int, side_id: int) -> Response:
|
||||
data = dict(sideId=side_id, battleId=battle_id, _token=self.token)
|
||||
def _post_military_fight_air(self, battle_id: int, side_id: int, zone_id: int) -> Response:
|
||||
data = dict(sideId=side_id, battleId=battle_id, _token=self.token, battleZoneId=zone_id)
|
||||
return self.post("{}/military/fight-shoooot/{}".format(self.url, battle_id), data=data)
|
||||
|
||||
def _post_military_fight_ground(self, battle_id: int, side_id: int) -> Response:
|
||||
data = dict(sideId=side_id, battleId=battle_id, _token=self.token)
|
||||
def _post_military_fight_ground(self, battle_id: int, side_id: int, zone_id: int) -> Response:
|
||||
data = dict(sideId=side_id, battleId=battle_id, _token=self.token, battleZoneId=zone_id)
|
||||
return self.post("{}/military/fight-shooot/{}".format(self.url, battle_id), data=data)
|
||||
|
||||
def _post_military_group_missions(self) -> Response:
|
||||
@ -1035,16 +1045,25 @@ class BattleDivision:
|
||||
epic: bool
|
||||
dom_pts: Dict[str, int] = None
|
||||
wall: Dict[str, Union[int, float]] = None
|
||||
battle_zone_id: int
|
||||
def_medal: Dict[str, int]
|
||||
inv_medal: Dict[str, int]
|
||||
|
||||
@property
|
||||
def div_end(self) -> bool:
|
||||
return utils.now() >= self.end
|
||||
|
||||
def __init__(self, end: datetime.datetime, epic: bool, inv_pts: int, def_pts: int, wall_for: int, wall_dom: float):
|
||||
def __init__(
|
||||
self, div_id: int, end: datetime.datetime, epic: bool, inv_pts: int, def_pts: int,
|
||||
wall_for: int, wall_dom: float, def_medal: Tuple[int, int], inv_medal: Tuple[int, int]
|
||||
):
|
||||
self.battle_zone_id = div_id
|
||||
self.end = end
|
||||
self.epic = epic
|
||||
self.dom_pts = dict({"inv": inv_pts, "def": def_pts})
|
||||
self.wall = dict({"for": wall_for, "dom": wall_dom})
|
||||
self.def_medal = {"id": def_medal[0], "dmg": def_medal[1]}
|
||||
self.inv_medal = {"id": inv_medal[0], "dmg": inv_medal[1]}
|
||||
|
||||
|
||||
class Battle:
|
||||
@ -1087,11 +1106,18 @@ class Battle:
|
||||
else:
|
||||
end = utils.localize_dt(datetime.datetime.max - datetime.timedelta(days=1))
|
||||
|
||||
battle_div = BattleDivision(
|
||||
end=end, epic=data.get('epic_type') in [1, 5],
|
||||
if not data['stats']['def']:
|
||||
def_medal = (0, 0)
|
||||
else:
|
||||
def_medal = (data['stats']['def']['citizenId'], data['stats']['def']['damage'])
|
||||
if not data['stats']['inv']:
|
||||
inv_medal = (0, 0)
|
||||
else:
|
||||
inv_medal = (data['stats']['inv']['citizenId'], data['stats']['inv']['damage'])
|
||||
battle_div = BattleDivision(end=end, epic=data.get('epic_type') in [1, 5], div_id=data.get('id'),
|
||||
inv_pts=data.get('dom_pts').get("inv"), def_pts=data.get('dom_pts').get("def"),
|
||||
wall_for=data.get('wall').get("for"), wall_dom=data.get('wall').get("dom")
|
||||
)
|
||||
wall_for=data.get('wall').get("for"), wall_dom=data.get('wall').get("dom"),
|
||||
def_medal=def_medal, inv_medal=inv_medal)
|
||||
|
||||
self.div.update({div: battle_div})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user