-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
65 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,45 @@ | ||
from hearthstone.enums import GameTag | ||
|
||
from hslog.exceptions import ParsingError | ||
from hslog.player import PlayerManager | ||
|
||
|
||
class LivePlayerManager(PlayerManager): | ||
|
||
def register_player_name_on_tag_change(self, player, tag, value): | ||
""" | ||
Triggers on every TAG_CHANGE where the corresponding entity is a LazyPlayer. | ||
Will attempt to return a new value instead | ||
""" | ||
if tag == GameTag.ENTITY_ID: | ||
# This is the simplest check. When a player entity is declared, | ||
# its ENTITY_ID is not available immediately (in pre-6.0). | ||
# If we get a matching ENTITY_ID, then we can use that to match it. | ||
return self.register_player_name(player.name, value) | ||
elif tag == GameTag.LAST_CARD_PLAYED: | ||
# This is a fallback to register_player_name_mulligan in case the mulligan | ||
# phase is not available in this game (spectator mode, reconnects). | ||
if value not in self._entity_controller_map: | ||
raise ParsingError("Unknown entity ID on TAG_CHANGE: %r" % (value)) | ||
player_id = self._entity_controller_map[value] | ||
entity_id = int(self._players_by_player_id[player_id]) | ||
return self.register_player_name(player.name, entity_id) | ||
elif tag == GameTag.MULLIGAN_STATE: | ||
return None | ||
return player | ||
def __init__(self): | ||
super(LivePlayerManager, self).__init__() | ||
|
||
self.actual_player_names = set() | ||
self.names_used = set() | ||
self.name_assignment_done = False | ||
|
||
def register_player_name_on_tag_change(self, player, tag, value): | ||
if tag not in [GameTag.ENTITY_ID, GameTag.LAST_CARD_PLAYED]: | ||
return None | ||
super(LivePlayerManager, self).register_player_name_on_tag_change(player, tag, value) | ||
|
||
def set_initial_player_name(self, player_id, player_name, current_game): | ||
players = current_game.liveExporter.game.players | ||
for p in players: | ||
if p.player_id == int(player_id): | ||
p.name = player_name | ||
|
||
def complete_player_names(self, player_name, current_game): | ||
# populate names if they haven"t been used already | ||
if player_name not in self.names_used: | ||
self.actual_player_names.add(player_name) | ||
|
||
# if there are two names available we have enough to assign | ||
if len(self.actual_player_names) == 2 and not self.name_assignment_done: | ||
unnamed = None | ||
for p in current_game.liveExporter.game.players: | ||
if p.name in self.actual_player_names: | ||
self.names_used.add(p.name) | ||
self.actual_player_names.remove(p.name) | ||
else: | ||
unnamed = p | ||
if len(self.actual_player_names): | ||
other_player_name = self.actual_player_names.pop() | ||
self.names_used.add(other_player_name) | ||
unnamed.name = other_player_name | ||
|
||
self.name_assignment_done = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters