@@ -196,8 +196,10 @@ def _handle_turn_kings(self, msg):
196196 for king_msg in msg :
197197 self .get_player_by_id (king_msg ["playerId" ]).king .is_alive = king_msg ["isAlive" ]
198198 self .get_player_by_id (king_msg ["playerId" ]).king .hp = king_msg ["hp" ]
199- self .get_player_by_id (king_msg ["playerId" ]).king .target = king_msg ["target" ] if king_msg [
200- "target" ] != - 1 else None
199+ if king_msg ["target" ] != - 1 :
200+ self .get_player_by_id (king_msg ["playerId" ]).king .target = self .get_unit_by_id (king_msg ["target" ])
201+ else :
202+ self .get_player_by_id (king_msg ["playerId" ]).king .target = None
201203
202204 def _handle_turn_units (self , msg , is_dead_unit = False ):
203205 if not is_dead_unit :
@@ -224,7 +226,6 @@ def _handle_turn_units(self, msg, is_dead_unit=False):
224226 target_cell = Cell (row = unit_msg ["targetCell" ]["row" ], col = unit_msg ["targetCell" ]["col" ])
225227 else :
226228 target_cell = None
227-
228229 unit = Unit (unit_id = unit_id , base_unit = base_unit ,
229230 cell = self ._map .get_cell (unit_msg ["cell" ]["row" ], unit_msg ["cell" ]["col" ]),
230231 path = self ._map .get_path_by_id (unit_msg ["pathId" ]),
@@ -235,21 +236,22 @@ def _handle_turn_units(self, msg, is_dead_unit=False):
235236 is_hasted = unit_msg ["isHasted" ],
236237 range = unit_msg ["range" ],
237238 attack = unit_msg ["attack" ],
238- target = None , # will be set later when all units are in set
239+ target = None , # will be set later when all units are in set
239240 target_cell = target_cell ,
240241 affected_spells = [self .get_cast_spell_by_id (cast_spell_id ) for cast_spell_id in
241242 unit_msg ["affectedSpells" ]],
242243 target_if_king = None if self .get_player_by_id (
243244 unit_msg ["target" ]) is None else self .get_player_by_id (unit_msg ["target" ]).king ,
244245 player_id = unit_msg ["playerId" ])
245-
246246 unit_input_list .append (unit )
247247
248248 if unit .path is not None :
249- if self .get_player_by_id (unit .player_id ).king .center in unit .path .cells and unit .path .cells [0 ] != self .get_player_by_id (unit .player_id ).king .center :
249+ if self .get_player_by_id (unit .player_id ).king .center in unit .path .cells and unit .path .cells [
250+ 0 ] != self .get_player_by_id (unit .player_id ).king .center :
250251 unit .path = Path (path = unit .path )
251252 unit .path .cells .reverse ()
252- if self ._get_friend_by_id (unit .player_id ).king .center in unit .path .cells and unit .path .cells [0 ] != self ._get_friend_by_id (unit .player_id ).king .center :
253+ if self ._get_friend_by_id (unit .player_id ).king .center in unit .path .cells and unit .path .cells [
254+ 0 ] != self ._get_friend_by_id (unit .player_id ).king .center :
253255 unit .path = Path (path = unit .path )
254256 unit .path .cells .reverse ()
255257
@@ -310,10 +312,10 @@ def _handle_turn_message(self, msg):
310312 self ._current_turn = msg ['currTurn' ]
311313 self ._player .deck = [self ._get_base_unit_by_id (deck_type_id ) for deck_type_id in msg ["deck" ]]
312314 self ._player .hand = [self ._get_base_unit_by_id (hand_type_id ) for hand_type_id in msg ["hand" ]]
313- self ._handle_turn_kings (msg ["kings" ])
314315 self ._handle_turn_units (msg = msg ["diedUnits" ], is_dead_unit = True )
315- self ._handle_turn_units (msg ["units" ])
316316 self ._handle_turn_cast_spells (msg ["castSpells" ])
317+ self ._handle_turn_units (msg ["units" ])
318+ self ._handle_turn_kings (msg ["kings" ])
317319 self ._turn_updates = TurnUpdates (received_spell = msg ["receivedSpell" ],
318320 friend_received_spell = msg ["friendReceivedSpell" ],
319321 got_range_upgrade = msg ["gotRangeUpgrade" ],
0 commit comments