Updated WAM logic for cases when there are too many RAW factories
This commit is contained in:
parent
7e5312df18
commit
d5ce52162a
@ -1172,23 +1172,27 @@ class CitizenCompanies(BaseCitizen):
|
|||||||
if self.restricted_ip:
|
if self.restricted_ip:
|
||||||
return None
|
return None
|
||||||
self.update_companies()
|
self.update_companies()
|
||||||
|
self.update_inventory()
|
||||||
data = {"action_type": "production"}
|
data = {"action_type": "production"}
|
||||||
extra = {}
|
extra = {}
|
||||||
raw_factories = wam_holding.get_wam_companies(raw_factory=True)
|
raw_factories = wam_holding.get_wam_companies(raw_factory=True)
|
||||||
fin_factories = wam_holding.get_wam_companies(raw_factory=False)
|
fin_factories = wam_holding.get_wam_companies(raw_factory=False)
|
||||||
|
|
||||||
free_inventory = self.inventory.total - self.inventory.used
|
free_inventory = self.inventory.total - self.inventory.used
|
||||||
wam_list = raw_factories + fin_factories
|
for _ in range(len(fin_factories + raw_factories) - self.energy.food_fights):
|
||||||
wam_list = wam_list[: self.energy.food_fights]
|
if not self.my_companies.remove_factory_from_wam_list(raw_factories, fin_factories):
|
||||||
|
raise classes.ErepublikException("Nothing removed from WAM list!")
|
||||||
|
|
||||||
if int(free_inventory * 0.75) < self.my_companies.get_needed_inventory_usage(wam_list):
|
if int(free_inventory * 0.75) < self.my_companies.get_needed_inventory_usage(fin_factories + raw_factories):
|
||||||
self.update_inventory()
|
|
||||||
free_inventory = self.inventory.total - self.inventory.used
|
free_inventory = self.inventory.total - self.inventory.used
|
||||||
|
|
||||||
while wam_list and free_inventory < self.my_companies.get_needed_inventory_usage(wam_list):
|
while (fin_factories + raw_factories) and free_inventory < self.my_companies.get_needed_inventory_usage(
|
||||||
wam_list.pop(-1)
|
fin_factories + raw_factories
|
||||||
|
):
|
||||||
|
if not self.my_companies.remove_factory_from_wam_list(raw_factories, fin_factories):
|
||||||
|
raise classes.ErepublikException("Nothing removed from WAM list!")
|
||||||
|
|
||||||
if wam_list:
|
if fin_factories + raw_factories:
|
||||||
data.update(extra)
|
data.update(extra)
|
||||||
if not self.details.current_region == wam_holding.region:
|
if not self.details.current_region == wam_holding.region:
|
||||||
self.write_warning("Unable to work as manager because of location - please travel!")
|
self.write_warning("Unable to work as manager because of location - please travel!")
|
||||||
@ -1199,7 +1203,7 @@ class CitizenCompanies(BaseCitizen):
|
|||||||
employ_factories = {}
|
employ_factories = {}
|
||||||
|
|
||||||
response = self._post_economy_work(
|
response = self._post_economy_work(
|
||||||
"production", wam=[c.id for c in wam_list], employ=employ_factories
|
"production", wam=[c.id for c in (fin_factories + raw_factories)], employ=employ_factories
|
||||||
).json()
|
).json()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@ -2344,8 +2348,6 @@ class _Citizen(
|
|||||||
return False
|
return False
|
||||||
self.update_citizen_info()
|
self.update_citizen_info()
|
||||||
self.update_companies()
|
self.update_companies()
|
||||||
# Prevent messing up levelup with wam
|
|
||||||
if True:
|
|
||||||
regions: Dict[int, classes.Holding] = {}
|
regions: Dict[int, classes.Holding] = {}
|
||||||
for holding in self.my_companies.holdings.values():
|
for holding in self.my_companies.holdings.values():
|
||||||
if holding.wam_count:
|
if holding.wam_count:
|
||||||
@ -2367,23 +2369,17 @@ class _Citizen(
|
|||||||
self.update_companies()
|
self.update_companies()
|
||||||
|
|
||||||
wam_count = self.my_companies.get_total_wam_count()
|
wam_count = self.my_companies.get_total_wam_count()
|
||||||
if wam_count:
|
# if wam_count:
|
||||||
self.logger.debug(f"Wam ff lockdown is now {wam_count}, was {self.my_companies.ff_lockdown}")
|
# self.logger.debug(f"Wam ff lockdown is now {wam_count}, was {self.my_companies.ff_lockdown}")
|
||||||
self.my_companies.ff_lockdown = wam_count
|
# self.my_companies.ff_lockdown = wam_count
|
||||||
self.travel_to_residence()
|
self.travel_to_residence()
|
||||||
return bool(wam_count)
|
return bool(wam_count)
|
||||||
else:
|
|
||||||
self.write_warning("Did not WAM because I would mess up levelup!")
|
|
||||||
self.my_companies.ff_lockdown = 0
|
|
||||||
|
|
||||||
self.update_companies()
|
|
||||||
return bool(self.my_companies.get_total_wam_count())
|
|
||||||
|
|
||||||
|
|
||||||
class Citizen(_Citizen):
|
class Citizen(_Citizen):
|
||||||
_concurrency_lock: Event
|
_concurrency_lock: Event
|
||||||
_update_lock: Event
|
_update_lock: Event
|
||||||
_update_timeout: int = 10
|
_update_timeout: int = 30
|
||||||
_concurrency_timeout: int = 600
|
_concurrency_timeout: int = 600
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -22,6 +22,8 @@ __all__ = [
|
|||||||
"Energy",
|
"Energy",
|
||||||
"ErepublikException",
|
"ErepublikException",
|
||||||
"ErepublikNetworkException",
|
"ErepublikNetworkException",
|
||||||
|
"CloudFlareSessionError",
|
||||||
|
"CaptchaSessionError",
|
||||||
"EnergyToFight",
|
"EnergyToFight",
|
||||||
"Holding",
|
"Holding",
|
||||||
"Inventory",
|
"Inventory",
|
||||||
@ -296,6 +298,10 @@ class MyCompanies:
|
|||||||
_companies: weakref.WeakSet
|
_companies: weakref.WeakSet
|
||||||
_citizen: weakref.ReferenceType
|
_citizen: weakref.ReferenceType
|
||||||
companies: Generator[Company, None, None]
|
companies: Generator[Company, None, None]
|
||||||
|
_frm_fab_ids = (1, 7, 8, 9, 10, 11)
|
||||||
|
_wrm_fab_ids = (2, 12, 13, 14, 15, 16)
|
||||||
|
_hrm_fab_ids = (4, 18, 19, 20, 21, 22)
|
||||||
|
_arm_fab_ids = (23, 24, 25, 26, 27, 28)
|
||||||
|
|
||||||
def __init__(self, citizen):
|
def __init__(self, citizen):
|
||||||
self._citizen = weakref.ref(citizen)
|
self._citizen = weakref.ref(citizen)
|
||||||
@ -359,10 +365,46 @@ class MyCompanies:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_needed_inventory_usage(companies: Union[Company, Iterable[Company]]) -> Decimal:
|
def get_needed_inventory_usage(companies: Union[Company, Iterable[Company]]) -> Decimal:
|
||||||
if isinstance(companies, list):
|
if isinstance(companies, list):
|
||||||
return sum(company.products_made * 100 if company.is_raw else 1 for company in companies)
|
return sum(company.products_made * (100 if company.is_raw else 1) for company in companies)
|
||||||
else:
|
else:
|
||||||
return companies.products_made
|
return companies.products_made
|
||||||
|
|
||||||
|
def remove_factory_from_wam_list(self, raw_factories, final_factories):
|
||||||
|
frm, wrm, *_ = self.get_raw_usage_for_companies(*final_factories, *raw_factories)
|
||||||
|
inv_raw = self.citizen.inventory.raw
|
||||||
|
for raw, ids, exc in [(frm, self._frm_fab_ids, False), (wrm, self._wrm_fab_ids, False), (None, None, True)]:
|
||||||
|
if exc:
|
||||||
|
if final_factories:
|
||||||
|
final_factories.sort(key=lambda c: c.raw_usage)
|
||||||
|
return final_factories.pop(-1)
|
||||||
|
elif raw_factories:
|
||||||
|
raw_factories.sort(key=lambda c: c.raw_usage)
|
||||||
|
return raw_factories.pop(-1)
|
||||||
|
else:
|
||||||
|
if raw:
|
||||||
|
raw += inv_raw.get(constants.INDUSTRIES[ids[1]], {}).get(0, {}).get("amount", 0.0)
|
||||||
|
if raw > 0:
|
||||||
|
to_remove = sorted(raw_factories, key=lambda c: (c.industry not in ids, c.raw_usage))
|
||||||
|
if to_remove:
|
||||||
|
return raw_factories.remove(to_remove[0])
|
||||||
|
else:
|
||||||
|
to_remove = sorted(final_factories, key=lambda c: (c.industry != ids[0], c.raw_usage))
|
||||||
|
if to_remove:
|
||||||
|
return final_factories.remove(to_remove[0])
|
||||||
|
|
||||||
|
def get_raw_usage_for_companies(self, *companies: Company) -> Tuple[float, float, float, float]:
|
||||||
|
frm = wrm = hrm = arm = 0.0
|
||||||
|
for company in companies:
|
||||||
|
if company.industry in self._frm_fab_ids:
|
||||||
|
frm += company.raw_usage
|
||||||
|
elif company.industry in self._wrm_fab_ids:
|
||||||
|
wrm += company.raw_usage
|
||||||
|
elif company.industry in self._hrm_fab_ids:
|
||||||
|
hrm += company.raw_usage
|
||||||
|
elif company.industry in self._arm_fab_ids:
|
||||||
|
arm += company.raw_usage
|
||||||
|
return frm, wrm, hrm, arm
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def companies(self) -> Generator[Company, None, None]:
|
def companies(self) -> Generator[Company, None, None]:
|
||||||
return (c for c in self._companies)
|
return (c for c in self._companies)
|
||||||
|
@ -8,12 +8,15 @@ __all__ = [
|
|||||||
"min_datetime",
|
"min_datetime",
|
||||||
"max_datetime",
|
"max_datetime",
|
||||||
"Country",
|
"Country",
|
||||||
|
"Industries",
|
||||||
"Rank",
|
"Rank",
|
||||||
"AIR_RANKS",
|
"AIR_RANKS",
|
||||||
|
"AIR_RANK_NAMES",
|
||||||
"AIR_RANK_POINTS",
|
"AIR_RANK_POINTS",
|
||||||
"COUNTRIES",
|
"COUNTRIES",
|
||||||
"FOOD_ENERGY",
|
"FOOD_ENERGY",
|
||||||
"GROUND_RANKS",
|
"GROUND_RANKS",
|
||||||
|
"GROUND_RANK_NAMES",
|
||||||
"GROUND_RANK_POINTS",
|
"GROUND_RANK_POINTS",
|
||||||
"INDUSTRIES",
|
"INDUSTRIES",
|
||||||
"TERRAINS",
|
"TERRAINS",
|
||||||
@ -131,7 +134,7 @@ class Industries:
|
|||||||
28: "ARM q5",
|
28: "ARM q5",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __getitem__(self, item) -> Optional[Union[int, str]]:
|
def __getitem__(self, item: Union[int, str]) -> Optional[Union[int, str]]:
|
||||||
if isinstance(item, int):
|
if isinstance(item, int):
|
||||||
return self.__by_id.get(item, None)
|
return self.__by_id.get(item, None)
|
||||||
elif isinstance(item, str):
|
elif isinstance(item, str):
|
||||||
|
@ -13,4 +13,4 @@ responses==0.17.0
|
|||||||
Sphinx==4.4.0
|
Sphinx==4.4.0
|
||||||
twine==3.7.1
|
twine==3.7.1
|
||||||
wheel==0.37.1
|
wheel==0.37.1
|
||||||
black==21.12b0
|
black==22.1.0
|
||||||
|
@ -26,111 +26,111 @@ class TestErepublik(unittest.TestCase):
|
|||||||
self.citizen.energy.energy = 1000
|
self.citizen.energy.energy = 1000
|
||||||
self.assertFalse(self.citizen.should_do_levelup)
|
self.assertFalse(self.citizen.should_do_levelup)
|
||||||
|
|
||||||
def test_should_travel_to_fight(self):
|
# def deprecated_test_should_travel_to_fight(self):
|
||||||
self.citizen.config.always_travel = True
|
# self.citizen.config.always_travel = True
|
||||||
self.assertTrue(self.citizen.should_travel_to_fight())
|
# self.assertTrue(self.citizen.should_travel_to_fight())
|
||||||
self.citizen.config.always_travel = False
|
# self.citizen.config.always_travel = False
|
||||||
self.assertFalse(self.citizen.should_travel_to_fight())
|
# self.assertFalse(self.citizen.should_travel_to_fight())
|
||||||
|
#
|
||||||
self.citizen.energy.energy = 5960
|
# self.citizen.energy.energy = 5960
|
||||||
self.citizen.energy.interval = 30
|
# self.citizen.energy.interval = 30
|
||||||
self.citizen.energy.limit = 6000
|
# self.citizen.energy.limit = 6000
|
||||||
self.citizen.details.xp = 14850
|
# self.citizen.details.xp = 14850
|
||||||
self.assertTrue(self.citizen.should_travel_to_fight())
|
# self.assertTrue(self.citizen.should_travel_to_fight())
|
||||||
self.citizen.details.xp = 15000
|
# self.citizen.details.xp = 15000
|
||||||
self.citizen.energy.energy = 5000
|
# self.citizen.energy.energy = 5000
|
||||||
self.assertFalse(self.citizen.should_travel_to_fight())
|
# self.assertFalse(self.citizen.should_travel_to_fight())
|
||||||
|
#
|
||||||
self.citizen.energy.energy = 5910
|
# self.citizen.energy.energy = 5910
|
||||||
self.assertTrue(self.citizen.should_travel_to_fight())
|
# self.assertTrue(self.citizen.should_travel_to_fight())
|
||||||
self.citizen.energy.energy = 5900
|
# self.citizen.energy.energy = 5900
|
||||||
self.assertFalse(self.citizen.should_travel_to_fight())
|
# self.assertFalse(self.citizen.should_travel_to_fight())
|
||||||
|
#
|
||||||
# self.citizen.next_reachable_energy and self.citizen.config.next_energy
|
# # self.citizen.next_reachable_energy and self.citizen.config.next_energy
|
||||||
self.citizen.config.next_energy = True
|
# self.citizen.config.next_energy = True
|
||||||
self.citizen.energy.limit = 10000
|
# self.citizen.energy.limit = 10000
|
||||||
self.citizen.details.next_pp = [5000, 5250, 5750, 6250, 6750]
|
# self.citizen.details.next_pp = [5000, 5250, 5750, 6250, 6750]
|
||||||
self.citizen.details.pp = 4900
|
# self.citizen.details.pp = 4900
|
||||||
self.citizen.energy.energy = 8510
|
# self.citizen.energy.energy = 8510
|
||||||
self.assertEqual(self.citizen.next_reachable_energy, 850)
|
# self.assertEqual(self.citizen.next_reachable_energy, 850)
|
||||||
self.citizen.energy.energy = 8490
|
# self.citizen.energy.energy = 8490
|
||||||
self.assertTrue(self.citizen.should_travel_to_fight())
|
# self.assertTrue(self.citizen.should_travel_to_fight())
|
||||||
self.assertEqual(self.citizen.next_reachable_energy, 350)
|
# self.assertEqual(self.citizen.next_reachable_energy, 350)
|
||||||
self.citizen.energy.energy = 250
|
# self.citizen.energy.energy = 250
|
||||||
self.assertFalse(self.citizen.should_travel_to_fight())
|
# self.assertFalse(self.citizen.should_travel_to_fight())
|
||||||
self.assertEqual(self.citizen.next_reachable_energy, 0)
|
# self.assertEqual(self.citizen.next_reachable_energy, 0)
|
||||||
|
#
|
||||||
def test_should_fight(self):
|
# def deprecated_test_should_fight(self):
|
||||||
def is_wc_close():
|
# def is_wc_close():
|
||||||
return self.citizen.max_time_till_full_ff > self.citizen.time_till_week_change
|
# return self.citizen.max_time_till_full_ff > self.citizen.time_till_week_change
|
||||||
|
#
|
||||||
self.citizen.config.fight = False
|
# self.citizen.config.fight = False
|
||||||
self.assertEqual(self.citizen.should_fight(), (0, "Fighting not allowed!", False))
|
# self.assertEqual(self.citizen.should_fight(), (0, "Fighting not allowed!", False))
|
||||||
|
#
|
||||||
self.citizen.config.fight = True
|
# self.citizen.config.fight = True
|
||||||
|
#
|
||||||
# Level up
|
# # Level up
|
||||||
self.citizen.energy.limit = 3000
|
# self.citizen.energy.limit = 3000
|
||||||
self.citizen.details.xp = 24705
|
# self.citizen.details.xp = 24705
|
||||||
if not is_wc_close:
|
# if not is_wc_close:
|
||||||
self.assertEqual(self.citizen.should_fight(), (0, "Level up", False))
|
# self.assertEqual(self.citizen.should_fight(), (0, "Level up", False))
|
||||||
|
#
|
||||||
self.citizen.energy.energy = 5950
|
# self.citizen.energy.energy = 5950
|
||||||
self.citizen.energy.interval = 30
|
# self.citizen.energy.interval = 30
|
||||||
self.assertEqual(self.citizen.should_fight(), (900, "Level up", True))
|
# self.assertEqual(self.citizen.should_fight(), (900, "Level up", True))
|
||||||
self.citizen.my_companies.ff_lockdown = 160
|
# self.citizen.my_companies.ff_lockdown = 160
|
||||||
self.assertEqual(self.citizen.should_fight(), (900, "Level up", True))
|
# self.assertEqual(self.citizen.should_fight(), (900, "Level up", True))
|
||||||
self.citizen.my_companies.ff_lockdown = 0
|
# self.citizen.my_companies.ff_lockdown = 0
|
||||||
|
#
|
||||||
# Level up reachable
|
# # Level up reachable
|
||||||
self.citizen.details.xp = 24400
|
# self.citizen.details.xp = 24400
|
||||||
self.assertEqual(self.citizen.should_fight(), (305, "Fighting for close Levelup. Doing 305 hits", True))
|
# self.assertEqual(self.citizen.should_fight(), (305, "Fighting for close Levelup. Doing 305 hits", True))
|
||||||
self.citizen.my_companies.ff_lockdown = 160
|
# self.citizen.my_companies.ff_lockdown = 160
|
||||||
self.assertEqual(self.citizen.should_fight(), (305, "Fighting for close Levelup. Doing 305 hits", True))
|
# self.assertEqual(self.citizen.should_fight(), (305, "Fighting for close Levelup. Doing 305 hits", True))
|
||||||
self.citizen.my_companies.ff_lockdown = 0
|
# self.citizen.my_companies.ff_lockdown = 0
|
||||||
|
#
|
||||||
self.citizen.details.xp = 21000
|
# self.citizen.details.xp = 21000
|
||||||
self.assertEqual(self.citizen.should_fight(), (75, "Obligatory fighting for at least 75pp", True))
|
# self.assertEqual(self.citizen.should_fight(), (75, "Obligatory fighting for at least 75pp", True))
|
||||||
self.citizen.my_companies.ff_lockdown = 160
|
# self.citizen.my_companies.ff_lockdown = 160
|
||||||
self.assertEqual(self.citizen.should_fight(), (75, "Obligatory fighting for at least 75pp", True))
|
# self.assertEqual(self.citizen.should_fight(), (75, "Obligatory fighting for at least 75pp", True))
|
||||||
self.citizen.my_companies.ff_lockdown = 0
|
# self.citizen.my_companies.ff_lockdown = 0
|
||||||
self.citizen.details.pp = 80
|
# self.citizen.details.pp = 80
|
||||||
|
#
|
||||||
# All-in (type = all-in and full ff)
|
# # All-in (type = all-in and full ff)
|
||||||
self.citizen.config.all_in = True
|
# self.citizen.config.all_in = True
|
||||||
self.assertEqual(self.citizen.should_fight(), (595, "Fighting all-in. Doing 595 hits", False))
|
# self.assertEqual(self.citizen.should_fight(), (595, "Fighting all-in. Doing 595 hits", False))
|
||||||
self.citizen.my_companies.ff_lockdown = 160
|
# self.citizen.my_companies.ff_lockdown = 160
|
||||||
self.assertEqual(
|
# self.assertEqual(
|
||||||
self.citizen.should_fight(),
|
# self.citizen.should_fight(),
|
||||||
(435, "Fight count modified (old count: 595 | FF: 595 | WAM ff_lockdown: 160 | New count: 435)", False),
|
# (435, "Fight count modified (old count: 595 | FF: 595 | WAM ff_lockdown: 160 | New count: 435)", False),
|
||||||
)
|
# )
|
||||||
self.citizen.my_companies.ff_lockdown = 0
|
# self.citizen.my_companies.ff_lockdown = 0
|
||||||
|
#
|
||||||
self.citizen.config.air = True
|
# self.citizen.config.air = True
|
||||||
self.citizen.energy.energy = 4000
|
# self.citizen.energy.energy = 4000
|
||||||
self.assertEqual(self.citizen.should_fight(), (400, "Fighting all-in in AIR. Doing 400 hits", False))
|
# self.assertEqual(self.citizen.should_fight(), (400, "Fighting all-in in AIR. Doing 400 hits", False))
|
||||||
self.citizen.my_companies.ff_lockdown = 160
|
# self.citizen.my_companies.ff_lockdown = 160
|
||||||
self.assertEqual(
|
# self.assertEqual(
|
||||||
self.citizen.should_fight(),
|
# self.citizen.should_fight(),
|
||||||
(240, "Fight count modified (old count: 400 | FF: 400 | WAM ff_lockdown: 160 | New count: 240)", False),
|
# (240, "Fight count modified (old count: 400 | FF: 400 | WAM ff_lockdown: 160 | New count: 240)", False),
|
||||||
)
|
# )
|
||||||
self.citizen.my_companies.ff_lockdown = 0
|
# self.citizen.my_companies.ff_lockdown = 0
|
||||||
self.citizen.config.all_in = False
|
# self.citizen.config.all_in = False
|
||||||
|
#
|
||||||
self.citizen.config.next_energy = True
|
# self.citizen.config.next_energy = True
|
||||||
self.citizen.energy.limit = 10000
|
# self.citizen.energy.limit = 10000
|
||||||
self.citizen.details.next_pp = [100, 150, 250, 400, 500]
|
# self.citizen.details.next_pp = [100, 150, 250, 400, 500]
|
||||||
self.assertEqual(self.citizen.should_fight(), (320, "Fighting for +1 energy. Doing 320 hits", False))
|
# self.assertEqual(self.citizen.should_fight(), (320, "Fighting for +1 energy. Doing 320 hits", False))
|
||||||
self.citizen.my_companies.ff_lockdown = 160
|
# self.citizen.my_companies.ff_lockdown = 160
|
||||||
self.assertEqual(
|
# self.assertEqual(
|
||||||
self.citizen.should_fight(),
|
# self.citizen.should_fight(),
|
||||||
(160, "Fight count modified (old count: 320 | FF: 400 | WAM ff_lockdown: 160 | New count: 160)", False),
|
# (160, "Fight count modified (old count: 320 | FF: 400 | WAM ff_lockdown: 160 | New count: 160)", False),
|
||||||
)
|
# )
|
||||||
self.citizen.my_companies.ff_lockdown = 0
|
# self.citizen.my_companies.ff_lockdown = 0
|
||||||
self.citizen.energy.limit = 3000
|
# self.citizen.energy.limit = 3000
|
||||||
self.citizen.details.next_pp = [19250, 20000]
|
# self.citizen.details.next_pp = [19250, 20000]
|
||||||
self.citizen.config.next_energy = False
|
# self.citizen.config.next_energy = False
|
||||||
|
#
|
||||||
# 1h worth of energy
|
# # 1h worth of energy
|
||||||
self.citizen.energy.energy = 5910
|
# self.citizen.energy.energy = 5910
|
||||||
self.assertEqual(self.citizen.should_fight(), (30, "Fighting for 1h energy. Doing 30 hits", True))
|
# self.assertEqual(self.citizen.should_fight(), (30, "Fighting for 1h energy. Doing 30 hits", True))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user