Updated fighting division chooser
This commit is contained in:
parent
d07334f602
commit
6c8dbcd99e
@ -5,7 +5,7 @@
|
|||||||
__author__ = """Eriks Karls"""
|
__author__ = """Eriks Karls"""
|
||||||
__email__ = 'eriks@72.lv'
|
__email__ = 'eriks@72.lv'
|
||||||
__version__ = '0.20.2'
|
__version__ = '0.20.2'
|
||||||
__commit_id__ = "bcb27da"
|
__commit_id__ = "d07334f"
|
||||||
|
|
||||||
from erepublik import classes, utils
|
from erepublik import classes, utils
|
||||||
from erepublik.citizen import Citizen
|
from erepublik.citizen import Citizen
|
||||||
|
@ -13,7 +13,7 @@ from requests import HTTPError, RequestException, Response
|
|||||||
from erepublik import utils
|
from erepublik import utils
|
||||||
from erepublik.access_points import CitizenAPI
|
from erepublik.access_points import CitizenAPI
|
||||||
from erepublik.classes import Battle, Config, Details, Energy, \
|
from erepublik.classes import Battle, Config, Details, Energy, \
|
||||||
ErepublikException, MyCompanies, MyJSONEncoder, OfferItem, Politics, Reporter, TelegramBot
|
ErepublikException, MyCompanies, MyJSONEncoder, OfferItem, Politics, Reporter, TelegramBot, BattleDivision
|
||||||
|
|
||||||
|
|
||||||
class BaseCitizen(CitizenAPI):
|
class BaseCitizen(CitizenAPI):
|
||||||
@ -1395,7 +1395,7 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
available_weapons = self._get_military_show_weapons(battle_id).json()
|
available_weapons = self._get_military_show_weapons(battle_id).json()
|
||||||
weapon_quality = -1
|
weapon_quality = -1
|
||||||
weapon_damage = 0
|
weapon_damage = 0
|
||||||
if not battle.div[battle_zone].div == 11:
|
if not battle.div[battle_zone].is_air:
|
||||||
for weapon in available_weapons:
|
for weapon in available_weapons:
|
||||||
try:
|
try:
|
||||||
if weapon['weaponQuantity'] > 30 and weapon['weaponInfluence'] > weapon_damage:
|
if weapon['weaponQuantity'] > 30 and weapon['weaponInfluence'] > weapon_damage:
|
||||||
@ -1540,17 +1540,21 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
battle = self.all_battles.get(battle_id)
|
battle = self.all_battles.get(battle_id)
|
||||||
if not isinstance(battle, Battle):
|
if not isinstance(battle, Battle):
|
||||||
continue
|
continue
|
||||||
battle_zone = 0
|
battle_zone: Optional[BattleDivision] = None
|
||||||
for div in battle.div.values():
|
for div in battle.div.values():
|
||||||
if div.terrain == 0:
|
if div.terrain == 0:
|
||||||
|
if div.div_end:
|
||||||
|
continue
|
||||||
if self.config.air and div.is_air:
|
if self.config.air and div.is_air:
|
||||||
battle_zone = div.id
|
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:
|
||||||
battle_zone = div.id
|
battle_zone = div
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return
|
continue
|
||||||
|
if not battle_zone:
|
||||||
|
continue
|
||||||
allies = battle.invader.deployed + battle.defender.deployed + [battle.invader.id, battle.defender.id]
|
allies = battle.invader.deployed + battle.defender.deployed + [battle.invader.id, battle.defender.id]
|
||||||
|
|
||||||
travel_needed = self.details.current_country not in allies
|
travel_needed = self.details.current_country not in allies
|
||||||
@ -1584,8 +1588,9 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
|
|
||||||
if not self.travel_to_battle(battle_id, country_ids_to_travel):
|
if not self.travel_to_battle(battle_id, country_ids_to_travel):
|
||||||
break
|
break
|
||||||
self.set_default_weapon(battle_id, battle_zone)
|
self.change_division(battle_id, battle_zone.id)
|
||||||
self.fight(battle_id, battle_zone, side_id)
|
self.set_default_weapon(battle_id, battle_zone.id)
|
||||||
|
self.fight(battle_id, battle_zone.id, side_id)
|
||||||
self.travel_to_residence()
|
self.travel_to_residence()
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -1734,8 +1739,9 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
battle = self.all_battles.get(battle_id)
|
battle = self.all_battles.get(battle_id)
|
||||||
self._post_main_battlefield_change_division(battle_id, battle.div[division_to].battle_zone_id)
|
division = battle.div[division_to]
|
||||||
self._report_action("MILITARY_DIV_SWITCH", f"Switched to d{division_to} in battle {battle_id}")
|
self._post_main_battlefield_change_division(battle_id, division_to)
|
||||||
|
self._report_action("MILITARY_DIV_SWITCH", f"Switched to d{division.div} in battle {battle_id}")
|
||||||
|
|
||||||
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:
|
||||||
|
@ -621,8 +621,10 @@ class BattleSide:
|
|||||||
points: int
|
points: int
|
||||||
deployed: List[int] = None
|
deployed: List[int] = None
|
||||||
allies: List[int] = None
|
allies: List[int] = None
|
||||||
|
battle: "Battle"
|
||||||
|
|
||||||
def __init__(self, country_id: int, points: int, allies: List[int], deployed: List[int]):
|
def __init__(self, battle: "Battle", country_id: int, points: int, allies: List[int], deployed: List[int]):
|
||||||
|
self.battle = battle
|
||||||
self.id = country_id
|
self.id = country_id
|
||||||
self.points = points
|
self.points = points
|
||||||
self.allies = [int(ally) for ally in allies]
|
self.allies = [int(ally) for ally in allies]
|
||||||
@ -639,6 +641,7 @@ class BattleDivision:
|
|||||||
inv_medal: Dict[str, int]
|
inv_medal: Dict[str, int]
|
||||||
terrain: int
|
terrain: int
|
||||||
div: int
|
div: int
|
||||||
|
battle: "Battle"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_air(self):
|
def is_air(self):
|
||||||
@ -648,7 +651,7 @@ class BattleDivision:
|
|||||||
def div_end(self) -> bool:
|
def div_end(self) -> bool:
|
||||||
return utils.now() >= self.end
|
return utils.now() >= self.end
|
||||||
|
|
||||||
def __init__(self, div_id: int, end: datetime.datetime, epic: bool, div: int, wall_for: int, wall_dom: float,
|
def __init__(self, battle: "Battle", div_id: int, end: datetime.datetime, epic: bool, div: int, wall_for: int, wall_dom: float,
|
||||||
terrain_id: int = 0):
|
terrain_id: int = 0):
|
||||||
"""Battle division helper class
|
"""Battle division helper class
|
||||||
|
|
||||||
@ -660,7 +663,7 @@ class BattleDivision:
|
|||||||
:type wall_for: int
|
:type wall_for: int
|
||||||
:type wall_dom: float
|
:type wall_dom: float
|
||||||
"""
|
"""
|
||||||
|
self.battle = battle
|
||||||
self.battle_zone_id = div_id
|
self.battle_zone_id = div_id
|
||||||
self.end = end
|
self.end = end
|
||||||
self.epic = epic
|
self.epic = epic
|
||||||
@ -713,12 +716,14 @@ class Battle:
|
|||||||
self.start = datetime.datetime.fromtimestamp(int(battle.get('start', 0)), tz=utils.erep_tz)
|
self.start = datetime.datetime.fromtimestamp(int(battle.get('start', 0)), tz=utils.erep_tz)
|
||||||
|
|
||||||
self.invader = BattleSide(
|
self.invader = BattleSide(
|
||||||
|
self,
|
||||||
battle.get('inv', {}).get('id'), battle.get('inv', {}).get('points'),
|
battle.get('inv', {}).get('id'), battle.get('inv', {}).get('points'),
|
||||||
[row.get('id') for row in battle.get('inv', {}).get('ally_list')],
|
[row.get('id') for row in battle.get('inv', {}).get('ally_list')],
|
||||||
[row.get('id') for row in battle.get('inv', {}).get('ally_list') if row['deployed']]
|
[row.get('id') for row in battle.get('inv', {}).get('ally_list') if row['deployed']]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.defender = BattleSide(
|
self.defender = BattleSide(
|
||||||
|
self,
|
||||||
battle.get('def', {}).get('id'), battle.get('def', {}).get('points'),
|
battle.get('def', {}).get('id'), battle.get('def', {}).get('points'),
|
||||||
[row.get('id') for row in battle.get('def', {}).get('ally_list')],
|
[row.get('id') for row in battle.get('def', {}).get('ally_list')],
|
||||||
[row.get('id') for row in battle.get('def', {}).get('ally_list') if row['deployed']]
|
[row.get('id') for row in battle.get('def', {}).get('ally_list') if row['deployed']]
|
||||||
@ -726,13 +731,13 @@ class Battle:
|
|||||||
|
|
||||||
self.div = {}
|
self.div = {}
|
||||||
for div, data in battle.get('div', {}).items():
|
for div, data in battle.get('div', {}).items():
|
||||||
div = int(data.get('div'))
|
div = int(div)
|
||||||
if data.get('end'):
|
if data.get('end'):
|
||||||
end = datetime.datetime.fromtimestamp(data.get('end'), tz=utils.erep_tz)
|
end = datetime.datetime.fromtimestamp(data.get('end'), tz=utils.erep_tz)
|
||||||
else:
|
else:
|
||||||
end = utils.localize_dt(datetime.datetime.max - datetime.timedelta(days=1))
|
end = utils.localize_dt(datetime.datetime.max - datetime.timedelta(days=1))
|
||||||
|
|
||||||
battle_div = BattleDivision(div_id=data.get('id'), div=data.get('dev'), end=end,
|
battle_div = BattleDivision(self, div_id=data.get('id'), div=data.get('div'), end=end,
|
||||||
epic=data.get('epic_type') in [1, 5],
|
epic=data.get('epic_type') in [1, 5],
|
||||||
wall_for=data.get('wall').get("for"),
|
wall_for=data.get('wall').get("for"),
|
||||||
wall_dom=data.get('wall').get("dom"),
|
wall_dom=data.get('wall').get("dom"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user