Added option to fight with energy bars, count small energy bars more precisely
This commit is contained in:
parent
47f5142837
commit
bff4183cb6
@ -341,6 +341,9 @@ class BaseCitizen(access_points.CitizenAPI):
|
|||||||
elif q == 15:
|
elif q == 15:
|
||||||
self.eb_small += amount
|
self.eb_small += amount
|
||||||
item_data.update(token='energy_bar')
|
item_data.update(token='energy_bar')
|
||||||
|
elif q == 16:
|
||||||
|
self.eb_small += amount
|
||||||
|
item_data.update(token='energy_bar')
|
||||||
kind = re.sub(r'_q\d\d*', "", item_data.get('token'))
|
kind = re.sub(r'_q\d\d*', "", item_data.get('token'))
|
||||||
|
|
||||||
if item_data.get('token', "") == "house_q100":
|
if item_data.get('token', "") == "house_q100":
|
||||||
@ -690,6 +693,10 @@ class BaseCitizen(access_points.CitizenAPI):
|
|||||||
self.eb_double -= amount
|
self.eb_double -= amount
|
||||||
elif q == "12":
|
elif q == "12":
|
||||||
self.eb_small -= amount
|
self.eb_small -= amount
|
||||||
|
elif q == "15":
|
||||||
|
self.eb_small -= amount
|
||||||
|
elif q == "16":
|
||||||
|
self.eb_small -= amount
|
||||||
next_recovery = r_json.get("food_remaining_reset").split(":")
|
next_recovery = r_json.get("food_remaining_reset").split(":")
|
||||||
self.energy.set_reference_time(
|
self.energy.set_reference_time(
|
||||||
utils.good_timedelta(self.now, timedelta(seconds=int(next_recovery[1]) * 60 + int(next_recovery[2])))
|
utils.good_timedelta(self.now, timedelta(seconds=int(next_recovery[1]) * 60 + int(next_recovery[2])))
|
||||||
@ -1364,7 +1371,7 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
self.update_money()
|
self.update_money()
|
||||||
cur = "g" if currency == 62 else "cc"
|
cur = "g" if currency == 62 else "cc"
|
||||||
if success:
|
if success:
|
||||||
self._report_action("DONATE_MONEY", f"Successfully donated {amount}{cur} to citizen with id {citizen_id}!")
|
self.report_money_donation(citizen_id, amount, currency == 1)
|
||||||
else:
|
else:
|
||||||
self._report_action("DONATE_MONEY", f"Unable to donate {amount}{cur}!")
|
self._report_action("DONATE_MONEY", f"Unable to donate {amount}{cur}!")
|
||||||
return success
|
return success
|
||||||
@ -1448,6 +1455,16 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
f" treasury", kwargs=r.json())
|
f" treasury", kwargs=r.json())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def report_money_donation(self, citizen_id: int, amount: float, is_currency: bool = True):
|
||||||
|
self.reporter.report_money_donation(citizen_id, amount, is_currency)
|
||||||
|
if self.config.telegram:
|
||||||
|
self.telegram.report_money_donation(citizen_id, amount, is_currency)
|
||||||
|
|
||||||
|
def report_item_donation(self, citizen_id: int, amount: float, quality: int, industry: str):
|
||||||
|
self.reporter.report_item_donation(citizen_id, amount, quality, industry)
|
||||||
|
if self.config.telegram:
|
||||||
|
self.telegram.report_item_donation(citizen_id, amount, f"{industry} q{quality}")
|
||||||
|
|
||||||
|
|
||||||
class CitizenLeaderBoard(BaseCitizen):
|
class CitizenLeaderBoard(BaseCitizen):
|
||||||
def get_aircraft_damage_rankings(self, country: int, weeks: int = 0, mu: int = 0) -> Dict[str, any]:
|
def get_aircraft_damage_rankings(self, country: int, weeks: int = 0, mu: int = 0) -> Dict[str, any]:
|
||||||
@ -1807,19 +1824,21 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
|
|
||||||
@utils.wait_for_lock
|
@utils.wait_for_lock
|
||||||
def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None,
|
def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None,
|
||||||
count: int = None) -> Optional[int]:
|
count: int = None, use_ebs: bool = False) -> Optional[int]:
|
||||||
"""Fight in a battle.
|
"""Fight in a battle.
|
||||||
|
|
||||||
Will auto activate booster and travel if allowed to do it.
|
Will auto activate booster and travel if allowed to do it.
|
||||||
:param battle: Battle battle to fight in
|
:param battle: Battle battle to fight in
|
||||||
:type battle: Battle
|
:type battle: Battle
|
||||||
|
:param division: Division number to fight in available choices
|
||||||
|
:type division: BattleDivision
|
||||||
:param side: BattleSide or None. Battle side to fight in, If side not == invader id or not in invader deployed
|
:param side: BattleSide or None. Battle side to fight in, If side not == invader id or not in invader deployed
|
||||||
allies list, then defender's side is chosen
|
allies list, then defender's side is chosen
|
||||||
:type side: BattleSide
|
:type side: BattleSide
|
||||||
:param count: How many hits to do, if not specified self.should_fight() is called.
|
:param count: How many hits to do, if not specified self.should_fight() is called.
|
||||||
:type count: int
|
:type count: int
|
||||||
:param division: Division number to fight in available choices
|
:param use_ebs: Should use energy bars if count > 0 and not enough food_fights
|
||||||
:type division: BattleDivision
|
:type use_ebs: bool
|
||||||
:return: None if no errors while fighting, otherwise error count.
|
:return: None if no errors while fighting, otherwise error count.
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
@ -1849,15 +1868,13 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
error_count += error
|
error_count += error
|
||||||
else:
|
else:
|
||||||
self._eat('blue')
|
self._eat('blue')
|
||||||
|
if count > 0 and self.energy.recovered < 50 and use_ebs:
|
||||||
|
self._eat('orange')
|
||||||
if self.energy.recovered < 50 or error_count >= 10 or count <= 0:
|
if self.energy.recovered < 50 or error_count >= 10 or count <= 0:
|
||||||
self.write_log(f"Hits: {total_hits:>4} | Damage: {total_damage}")
|
self.write_log(f"Hits: {total_hits:>4} | Damage: {total_damage}")
|
||||||
ok_to_fight = False
|
ok_to_fight = False
|
||||||
if total_damage:
|
if total_damage:
|
||||||
self.report_fighting(battle, not side.is_defender, division, total_damage, total_hits)
|
self.report_fighting(battle, not side.is_defender, division, total_damage, total_hits)
|
||||||
# self.reporter.report_action('FIGHT', dict(battle_id=battle.id, side=side, dmg=total_damage,
|
|
||||||
# air=battle.has_air, hits=total_hits,
|
|
||||||
# round=battle.zone_id,
|
|
||||||
# extra=dict(battle=battle, side=side)))
|
|
||||||
return error_count
|
return error_count
|
||||||
|
|
||||||
def _shoot(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide):
|
def _shoot(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide):
|
||||||
|
@ -650,6 +650,16 @@ class Reporter:
|
|||||||
air=battle.has_air, hits=hits,
|
air=battle.has_air, hits=hits,
|
||||||
round=battle.zone_id, extra=dict(battle=battle, side=side, division=division)))
|
round=battle.zone_id, extra=dict(battle=battle, side=side, division=division)))
|
||||||
|
|
||||||
|
def report_money_donation(self, citizen_id: int, amount: float, is_currency: bool = True):
|
||||||
|
cur = 'cc' if is_currency else 'gold'
|
||||||
|
self.report_action('DONATE_MONEY', dict(citizen_id=citizen_id, amount=amount, currency=cur),
|
||||||
|
f"Successfully donated {amount}{cur} to citizen with id {citizen_id}!")
|
||||||
|
|
||||||
|
def report_item_donation(self, citizen_id: int, amount: float, quality: int, industry: str):
|
||||||
|
self.report_action('DONATE_ITEMS',
|
||||||
|
dict(citizen_id=citizen_id, amount=amount, quality=quality, industry=industry),
|
||||||
|
f"Successfully donated {amount} x {industry} q{quality} to citizen with id {citizen_id}!")
|
||||||
|
|
||||||
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))
|
||||||
|
|
||||||
@ -1008,15 +1018,23 @@ class TelegramReporter:
|
|||||||
f" [battle {battle.id} for {battle.region_name[:16]}]({battle.link}) in d{division.div} on "
|
f" [battle {battle.id} for {battle.region_name[:16]}]({battle.link}) in d{division.div} on "
|
||||||
f"{side_txt} side")
|
f"{side_txt} side")
|
||||||
|
|
||||||
|
def report_item_donation(self, citizen_id: int, amount: float, product: str):
|
||||||
|
self.send_message(f"*Donation*: {amount} x {product} to citizen "
|
||||||
|
f"[{citizen_id}](https://www.erepublik.com/en/citizen/profile/{citizen_id})")
|
||||||
|
|
||||||
|
def report_money_donation(self, citizen_id: int, amount: float, is_currency: bool = True):
|
||||||
|
self.send_message(f"*Donation*: {amount}{'cc' if is_currency else 'gold'} to citizen "
|
||||||
|
f"[{citizen_id}](https://www.erepublik.com/en/citizen/profile/{citizen_id})")
|
||||||
|
|
||||||
def __send_messages(self):
|
def __send_messages(self):
|
||||||
while self._next_time > utils.now():
|
while self._next_time > utils.now():
|
||||||
if self.__thread_stopper.is_set():
|
if self.__thread_stopper.is_set():
|
||||||
break
|
break
|
||||||
self.__thread_stopper.wait(utils.get_sleep_seconds(self._next_time))
|
self.__thread_stopper.wait(utils.get_sleep_seconds(self._next_time))
|
||||||
|
|
||||||
message = "\n––––––––––––––––––––––\n\n".join(self.__queue)
|
message = "\n\n".join(self.__queue)
|
||||||
if self.player_name:
|
if self.player_name:
|
||||||
message = f"Player *{self.player_name}*\n" + message
|
message = f"Player *{self.player_name}*\n\n" + message
|
||||||
response = post(self.api_url, json=dict(chat_id=self.chat_id, text=message, parse_mode="Markdown"))
|
response = post(self.api_url, json=dict(chat_id=self.chat_id, text=message, parse_mode="Markdown"))
|
||||||
self._last_time = utils.now()
|
self._last_time = utils.now()
|
||||||
if response.json().get('ok'):
|
if response.json().get('ok'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user