Skip to content

Commit

Permalink
Merge pull request #3 from gmdvieira/bounties.bonds
Browse files Browse the repository at this point in the history
Count bounties claimed at fleet carriers.
  • Loading branch information
anthonylangsworth authored Jan 12, 2022
2 parents 4b16c96 + 5150de7 commit 0c7e6ab
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 40 deletions.
44 changes: 26 additions & 18 deletions edmfs/event_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,42 @@ def process(self, event:Dict[str, Any], pilot_state:PilotState, galaxy_state:Gal
class RedeemVoucherEventProcessor(EventProcessor):
def _process_bounty(self, event:Dict[str, Any], system_name:str, system_minor_factions:list) -> List[EventSummary]:
result = []
# Redeems at interstellar factors never have a local minor faction name, being ignored.
# Redeems at fleet carriers do list minor factions names and do count for influence at
# the final cashed amount.
for x in event["Factions"]:
pro, anti = _get_event_minor_faction_impact(x["Faction"], system_minor_factions)
result.append(RedeemVoucherEventSummary(system_name, pro, anti, event["Type"], x["Amount"]))
if x["Faction"] != "":
pro, anti = _get_event_minor_faction_impact(x["Faction"], system_minor_factions)
result.append(RedeemVoucherEventSummary(system_name, pro, anti, event["Type"], x["Amount"]))
return result

def _process_combat_bond(self, event:Dict[str, Any], system_name:str, system_minor_factions:list) -> List[EventSummary]:
pro, anti = _get_event_minor_faction_impact(event["Faction"], system_minor_factions)
# Remove any broker percentage. We want the full amount to approximate work done in a war.
amount = event["Amount"]
if "BrokerPercentage" in event:
try:
broker_percentage = float(event["BrokerPercentage"])
if broker_percentage > 0 and broker_percentage < 100:
amount = int(round(float(amount) * 100.0/(100.0 - broker_percentage), 0))
except ValueError:
pass
return [RedeemVoucherEventSummary(system_name, pro, anti, event["Type"], amount)]
result = []
# Redeems at interstellar factors never have a local minor faction name, being ignored.
# Redeems at fleet carriers do list minor factions names and do count for influence at
# the final cashed amount. However, consider the full amount because this is the best way to
# approximate the work in a war, at least until conflict zone wins and losses are added to the
# journal file.
if event["Faction"] != "":
pro, anti = _get_event_minor_faction_impact(event["Faction"], system_minor_factions)
# Remove any broker percentage. We want the full amount to approximate work done in a war.
amount = event["Amount"]
if "BrokerPercentage" in event:
try:
broker_percentage = float(event["BrokerPercentage"])
if broker_percentage > 0 and broker_percentage < 100:
amount = int(round(float(amount) * 100.0/(100.0 - broker_percentage), 0))
except ValueError:
pass
result = [RedeemVoucherEventSummary(system_name, pro, anti, event["Type"], amount)]
return result

def process(self, event:Dict[str, Any], pilot_state:PilotState, galaxy_state:GalaxyState) -> List[EventSummary]:
star_system = _get_system(galaxy_state, pilot_state.system_address)

result = []
# Exclude interstellar factors (and carriers) for bounties
if event["Type"] == "bounty" and event.get("BrokerPercentage", None) == None:
if event["Type"] == "bounty":
result.extend(self._process_bounty(event, star_system.name, star_system.minor_factions))
# Include interstellar factors (and carriers) for combat bonds because this is the best way to
# approximate the work in a war, at least until conflict zone wins and losses are added to the
# journal file.
elif event["Type"] == "CombatBond":
result.extend(self._process_combat_bond(event, star_system.name, star_system.minor_factions))

Expand Down
39 changes: 19 additions & 20 deletions tests/test_event_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ def test_location_sequence(location_events: Tuple, expected_station: Station):
[RedeemVoucherEventSummary("Fuelum", {"Findja Empire Assembly"}, {"The Fuel Rats Mischief"}, "bounty", 25490)]
),
(
# Interstellar factors
StarSystem("Findja", 1000, ("The Fuel Rats Mischief",)),
Station("Station", 1000, "The Fuel Rats Mischief"),
{"timestamp": "2020-05-09T03:42:31Z", "event": "RedeemVoucher", "Type": "bounty", "Amount": 13338, "Factions":[ { "Faction":"", "Amount":13338 } ], "BrokerPercentage": 25.000000 },
[]
),
(
# Fleet carrier redemption office
StarSystem("CPD-59 314", 1000, ("The Fuel Rats Mischief", "CPD-59 314 Imperial Society")),
Station("Station", 1000, "The Fuel Rats Mischief"),
{"timestamp": "2020-10-15T14:45:16Z", "event": "RedeemVoucher", "Type": "bounty", "Amount": 1779467, "Factions": [ { "Faction": "CPD-59 314 Imperial Society", "Amount": 1779467 } ], "BrokerPercentage":25.000000 },
[]
[RedeemVoucherEventSummary("CPD-59 314", {"CPD-59 314 Imperial Society"}, {"The Fuel Rats Mischief"}, "bounty", 1779467)]
),
(
StarSystem("Fuelum", 1000, ("The Fuel Rats Mischief", "Rabh Empire Pact", "Kacomam Empire Group", "Trumuye Emperor's Grace", "EDA Kunti League")),
Expand Down Expand Up @@ -156,46 +158,43 @@ def test_location_sequence(location_events: Tuple, expected_station: Station):
[RedeemVoucherEventSummary("", {"CPD-59 314 Imperial Society"}, {"The Fuel Rats Mischief"}, "CombatBond", 1177365)]
),
(
StarSystem("", 1000, ("The Fuel Rats Mischief",)),
Station("", 1000, "The Fuel Rats Mischief"),
{"timestamp":"2020-10-18T11:23:57Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1127126, "Faction":"HR 1597 & Co", "BrokerPercentage":25.000000 },
[RedeemVoucherEventSummary("", {"HR 1597 & Co"}, set(), "CombatBond", 1502835)]
),
(
# Interstellar factors
StarSystem("", 1000, ("The Fuel Rats Mischief",)),
Station("", 1000, "The Fuel Rats Mischief"),
{"timestamp":"2020-07-17T15:21:20Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":46026, "Faction":"", "BrokerPercentage":25.000000 },
[RedeemVoucherEventSummary("", {""}, set(), "CombatBond", 61368)]
[]
),
(
# Fleet carrier redemption office
StarSystem("", 1000, ("The Fuel Rats Mischief", "HR 1597 & Co")),
Station("", 1000, "The Fuel Rats Mischief"),
{"timestamp":"2020-10-18T11:23:57Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1127126, "Faction":"HR 1597 & Co", "BrokerPercentage":25.000000 },
[RedeemVoucherEventSummary("", {"HR 1597 & Co"}, {"The Fuel Rats Mischief"}, "CombatBond", 1502835)]
),
# Redemption office percentages; this should not happen in game.
(
StarSystem("", 1000, ("The Fuel Rats Mischief",)),
StarSystem("", 1000, ("The Fuel Rats Mischief", "HR 1597 & Co")),
Station("", 1000, "The Fuel Rats Mischief"),
{"timestamp":"2020-07-17T15:21:20Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1000, "Faction":"", "BrokerPercentage":0.000000 },
[RedeemVoucherEventSummary("", {""}, set(), "CombatBond", 1000)]
{"timestamp":"2020-07-17T15:21:20Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1000, "Faction":"HR 1597 & Co", "BrokerPercentage":0.000000 },
[RedeemVoucherEventSummary("", {"HR 1597 & Co"}, {"The Fuel Rats Mischief"}, "CombatBond", 1000)]
),
(
StarSystem("", 1000, ("The Fuel Rats Mischief",)),
StarSystem("", 1000, ("The Fuel Rats Mischief", "HR 1597 & Co")),
Station("", 1000, "The Fuel Rats Mischief"),
{"timestamp":"2020-07-17T15:21:20Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1000, "Faction":"", "BrokerPercentage":1.000000 },
[RedeemVoucherEventSummary("", {""}, set(), "CombatBond", 1010)]
{"timestamp":"2020-07-17T15:21:20Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1000, "Faction":"HR 1597 & Co", "BrokerPercentage":1.000000 },
[RedeemVoucherEventSummary("", {"HR 1597 & Co"}, {"The Fuel Rats Mischief"}, "CombatBond", 1010)]
),
(
StarSystem("", 1000, ("The Fuel Rats Mischief",)),
StarSystem("", 1000, ("The Fuel Rats Mischief", "HR 1597 & Co")),
Station("", 1000, "The Fuel Rats Mischief"),
{"timestamp":"2020-07-17T15:21:20Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1000, "Faction":"", "BrokerPercentage":99.000000 },
[RedeemVoucherEventSummary("", {""}, set(), "CombatBond", 100000)]
{"timestamp":"2020-07-17T15:21:20Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1000, "Faction":"HR 1597 & Co", "BrokerPercentage":99.000000 },
[RedeemVoucherEventSummary("", {"HR 1597 & Co"}, {"The Fuel Rats Mischief"}, "CombatBond", 100000)]
),
(
StarSystem("", 1000, ("The Fuel Rats Mischief",)),
StarSystem("", 1000, ("The Fuel Rats Mischief", "HR 1597 & Co")),
Station("", 1000, "The Fuel Rats Mischief"),
{"timestamp":"2020-07-17T15:21:20Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1000, "Faction":"", "BrokerPercentage":100.000000 },
[RedeemVoucherEventSummary("", {""}, set(), "CombatBond", 1000)]
{"timestamp":"2020-07-17T15:21:20Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":1000, "Faction":"HR 1597 & Co", "BrokerPercentage":100.000000 },
[RedeemVoucherEventSummary("", {"HR 1597 & Co"}, {"The Fuel Rats Mischief"}, "CombatBond", 1000)]
),
# Scannable (Not sure what this is)
Expand Down
7 changes: 5 additions & 2 deletions tests/test_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_tracker_init():
{"HR 1597 & Co"},
"Journal.201019220908.01.log",
("HR 1597 - ANTI HR 1597 & Co\n"
"1,852,906 CR of Bounty Vouchers\n"
"1,916,227 CR of Bounty Vouchers\n"
"\n"
"HR 1597 - PRO HR 1597 & Co\n"
"1 INF++ mission(s)\n"
Expand Down Expand Up @@ -301,7 +301,10 @@ def test_tracker_init():
"Journal.210817213224.01.log",
("Naualam - ANTI Extra Corporation\n"
"5 INF+ mission(s)\n"
"1 INF++ mission(s)")
"1 INF++ mission(s)\n"
"\n"
"Naualam - PRO Extra Corporation\n"
"1,278,672 CR of Bounty Vouchers")
),
(
{"EDA Kunti League"},
Expand Down

0 comments on commit 0c7e6ab

Please sign in to comment.