fix distance

This commit is contained in:
Alberto Xamin 2020-11-25 09:59:49 +01:00
parent 83cc69811e
commit f5095b9f6f
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
2 changed files with 18 additions and 16 deletions

View File

@ -21,6 +21,7 @@ class Game:
self.turn = 0
self.readyCount = 0
self.waiting_for = 0
self.initial_players = 0
def add_player(self, player: players.Player):
if player in self.players or len(self.players) >= 7:
@ -233,23 +234,24 @@ class Game:
sight = player.get_sight()
return [{
'name': self.players[j].name,
'dist': min(abs(i - j), (i+ abs(j-len(self.players))), (j+ abs(i-len(self.players)))) + self.players[j].get_visibility(),
'dist': min(abs(i - j), (i+ abs(j-len(self.players))), (j+ abs(i-len(self.players)))) + self.players[j].get_visibility() - (player.get_sight(countWeapon=False)-1),
'lives': self.players[j].lives,
'max_lives': self.players[j].max_lives,
'is_sheriff': isinstance(self.players[j].role, roles.Sheriff),
} for j in range(len(self.players)) if i != j]
def notify_all(self):
data = [{
'name': p.name,
'ncards': len(p.hand),
'equipment': [e.__dict__ for e in p.equipment],
'lives': p.lives,
'max_lives': p.max_lives,
'is_sheriff': isinstance(p.role, roles.Sheriff),
'is_my_turn': p.is_my_turn,
'pending_action': p.pending_action,
'character': p.character.__dict__,
'icon': p.role.icon if self.initial_players == 3 and p.role else '🤠'
} for p in self.players]
self.sio.emit('players_update', room=self.name, data=data)
if self.started:
data = [{
'name': p.name,
'ncards': len(p.hand),
'equipment': [e.__dict__ for e in p.equipment],
'lives': p.lives,
'max_lives': p.max_lives,
'is_sheriff': isinstance(p.role, roles.Sheriff),
'is_my_turn': p.is_my_turn,
'pending_action': p.pending_action,
'character': p.character.__dict__ if p.character else None,
'icon': p.role.icon if self.initial_players == 3 and p.role else '🤠'
} for p in self.players]
self.sio.emit('players_update', room=self.name, data=data)

View File

@ -466,13 +466,13 @@ class Player:
self.game.responders_did_respond_resume_turn()
self.attacker = None
def get_sight(self):
def get_sight(self, countWeapon=True):
if not self.character:
return 0
aim = 0
range = 0
for card in self.equipment:
if card.is_weapon:
if card.is_weapon and countWeapon:
range += card.range
else:
aim += card.sight_mod