Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sc2reader/engine/plugins/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def handleSelectionEvent(self, event, replay):

def handleResourceTradeEvent(self, event, replay):
event.sender = event.player
event.recipient = replay.players[event.recipient_id]
event.recipient = replay.player[event.recipient_id]

def handleHijackReplayGameEvent(self, event, replay):
replay.resume_from_replay = True
Expand Down
10 changes: 7 additions & 3 deletions sc2reader/events/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,18 @@ def __init__(self, frame, pid, data):
self.vespene = self.resources[1] if len(self.resources) >= 2 else None

#: Amount terrazine sent
self.terrazon = self.resources[2] if len(self.resources) >= 3 else None
self.terrazine = self.resources[2] if len(self.resources) >= 3 else None

#: Amount custom resource sent
self.custom_resource = self.resources[3] if len(self.resources) >= 4 else None

def __str__(self):
return self._str_prefix() + " transfer {0} minerals, {1} gas, {2} terrazine, and {3} custom to {4}".format(
self.minerals, self.vespene, self.terrazine, self.custom, self.recipient
self.minerals,
self.vespene,
self.terrazine,
self.custom_resource,
self.recipient,
)


Expand Down Expand Up @@ -688,7 +692,7 @@ def __str__(self):
return (
self._str_prefix()
+ " requests {0} minerals, {1} gas, {2} terrazine, and {3} custom".format(
Copy link
Collaborator

@cclauss cclauss Dec 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The {0} {1} {2} {3} thing has not been needed since Python 2.6 unless you want substitutions to land out of order or you want substitutions to repeat.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it was originally written and how the other classes in this file are written as well. Maybe create a separate issue to change this more broadly?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

self.minerals, self.vespene, self.terrazine, self.custom
self.minerals, self.vespene, self.terrazine, self.custom_resource
)
)

Expand Down
2 changes: 1 addition & 1 deletion sc2reader/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def __init__(self):
28: (SelectionEvent, self.selection_delta_event),
29: (create_control_group_event, self.control_group_update_event),
30: (None, self.selection_sync_check_event),
31: (None, self.resource_trade_event),
31: (ResourceTradeEvent, self.resource_trade_event),
32: (None, self.trigger_chat_message_event),
33: (None, self.ai_communicate_event),
34: (None, self.set_absolute_game_speed_event),
Expand Down
9 changes: 9 additions & 0 deletions test_replays/test_replays.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ def test_send_resources(self):
replay = sc2reader.load_replay(
"test_replays/2.0.4.24944/Backwater Complex (15).SC2Replay"
)
trade_events = [
event for event in replay.events if event.name == "ResourceTradeEvent"
]
self.assertEqual(len(trade_events), 5)
self.assertEqual(trade_events[0].sender.name, "Guardian")
self.assertEqual(trade_events[0].recipient.name, "Sturmkind")
self.assertEqual(trade_events[0].recipient_id, 2)
self.assertEqual(trade_events[0].minerals, 0)
self.assertEqual(trade_events[0].vespene, 750)

def test_cn_replays(self):
replay = sc2reader.load_replay("test_replays/2.0.5.25092/cn1.SC2Replay")
Expand Down