Skip to content

Commit

Permalink
The mission log now stores TargetFaction when it's present in `Miss…
Browse files Browse the repository at this point in the history
…ionAccepted` events.

`TargetFaction` now used when `Faction` is an empty string in `FactionEffects` on `MissionCompleted` events. Closes #135.
  • Loading branch information
aussig committed Sep 7, 2023
1 parent 25ae714 commit 640cab5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* It would cause your previously logged activity for the current tick to be lost and replaced by activity after the forced tick. Now, a 'proper' new tick is created so your earlier activity should be kept and available in the previous tick.
* If an automatic tick arrived with an earlier tick time than your forced tick, this could cause BGS-Tally to get confused. We now ignore any incoming ticks that have an older tick time than your forced tick.
* Forced ticks are now handled more elegantly when sending data via the BGS-Tally API, as we generate a fake `tickid` for the forced tick.
* Due to a game bug, some illegal massacre and assassination missions were not logging negative INF correctly against the target faction. Implemented a workaround for this.

### API Changes ([v1.2](https://studio-ws.apicur.io/sharing/281a84ad-dca9-42da-a08b-84e4b9af1b7e)):

Expand Down
15 changes: 10 additions & 5 deletions bgstally/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,21 @@ def system_entered(self, journal_entry: Dict, state: State):
state.system_tw_status = journal_entry.get('ThargoidWar', None)


def mission_completed(self, journal_entry: Dict, mission_log: MissionLog):
def mission_completed(self, journal_entry: dict, mission_log: MissionLog):
"""
Handle mission completed
"""
self.dirty = True
mission = mission_log.get_mission(journal_entry['MissionID'])
mission:dict = mission_log.get_mission(journal_entry['MissionID'])

# BGS
for faction_effect in journal_entry['FactionEffects']:
effect_faction_name = faction_effect['Faction']
effect_faction_name:str = faction_effect['Faction']
if effect_faction_name is None or effect_faction_name == "":
# A game bug means Faction can sometimes be an empty string in FactionEffects.
# Use the TargetFaction stored from the original MissionAccepted event in this case
effect_faction_name = mission.get('TargetFaction', "")

if faction_effect['Influence'] != []:
inf = len(faction_effect['Influence'][0]['Influence'])
inftrend = faction_effect['Influence'][0]['Trend']
Expand Down Expand Up @@ -402,11 +407,11 @@ def mission_completed(self, journal_entry: Dict, mission_log: MissionLog):
mission_log.delete_mission_by_id(journal_entry['MissionID'])


def mission_failed(self, journal_entry: Dict, mission_log: MissionLog):
def mission_failed(self, journal_entry: dict, mission_log: MissionLog):
"""
Handle mission failed
"""
mission = mission_log.get_mission(journal_entry['MissionID'])
mission:dict = mission_log.get_mission(journal_entry['MissionID'])
if mission is None: return
self.dirty = True

Expand Down
3 changes: 2 additions & 1 deletion bgstally/bgstally.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def journal_entry(self, cmdr, is_beta, system, station, entry, state):
case 'MissionAccepted':
self.mission_log.add_mission(entry.get('Name', ""), entry.get('Faction', ""), entry.get('MissionID', ""), entry.get('Expiry', ""),
entry.get('DestinationSystem', ""), entry.get('DestinationSettlement', ""), system, station,
entry.get('Count', -1), entry.get('PassengerCount', -1), entry.get('KillCount', -1))
entry.get('Count', -1), entry.get('PassengerCount', -1), entry.get('KillCount', -1),
entry.get('TargetFaction', ""))
dirty = True

case 'MissionCompleted':
Expand Down
6 changes: 4 additions & 2 deletions bgstally/missionlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ def get_mission(self, missionid: int):

def add_mission(self, name: str, faction: str, missionid: str, expiry: str,
destination_system: str, destination_settlement: str, system_name: str, station_name: str,
commodity_count: int, passenger_count: int, kill_count: int):
commodity_count: int, passenger_count: int, kill_count: int,
target_faction: str):
"""
Add a mission to the missionlog
"""
self.missionlog.append({'Name': name, 'Faction': faction, 'MissionID': missionid, 'Expiry': expiry,
'DestinationSystem': destination_system, 'DestinationSettlement': destination_settlement, 'System': system_name, 'Station': station_name,
'CommodityCount': commodity_count, 'PassengerCount': passenger_count, 'KillCount': kill_count})
'CommodityCount': commodity_count, 'PassengerCount': passenger_count, 'KillCount': kill_count,
'TargetFaction': target_faction})


def delete_mission_by_id(self, missionid: str):
Expand Down

0 comments on commit 640cab5

Please sign in to comment.