Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor analyze command #463

Merged
merged 1 commit into from Feb 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 24 additions & 23 deletions piqueserver/scripts/analyze.py
Expand Up @@ -4,8 +4,8 @@
Commands
^^^^^^^^

* ``/analyze or /an <target>`` to show a detailed analysis of a players shots if they hit someone.
Shows hit player, distance, dT in milliseconds (Delta Time- Time since previous shot that hit someone.
* ``/analyze or /an <target>`` to show a detailed analysis of a players shots if they hit someone.
Shows hit player, distance, dT in milliseconds (Delta Time- Time since previous shot that hit someone.
Useful for detecting multiple bullet or rapid hacks), weapon, which body part it hit, and a basic counter that displays the number of hits of that type.

* ``/analyze or /an`` to disable it
Expand All @@ -27,27 +27,28 @@ def analyze_shot(connection, player=None):
if player is None:
if connection.name in protocol.analyzers:
del protocol.analyzers[connection.name]
connection.send_chat('You are no longer analyzing anyone.')
else:
connection.send_chat('Please enter a target player to analyze.')
elif player is not None:
player = get_player(protocol, player)
if player not in protocol.players:
raise ValueError()
else:
if connection.name in protocol.analyzers and player.name == protocol.analyzers[connection.name]:
del protocol.analyzers[connection.name]
connection.send_chat('You are no longer analyzing anyone.')
elif connection.name in protocol.analyzers and player.name != protocol.analyzers[connection.name]:
connection.send_chat('You are no longer analyzing %s. You are now analyzing %s.' % (
protocol.analyzers[connection.name], player.name))
protocol.analyzers[connection.name] = player.name
connection.hs, connection.bs, connection.ls = 0, 0, 0
elif not connection.name in protocol.analyzers:
protocol.analyzers[connection.name] = player.name
connection.send_chat(
'You are now analyzing %s' % (player.name))
connection.hs, connection.bs, connection.ls = 0, 0, 0
return 'You are no longer analyzing anyone.'

return 'Please enter a target player to analyze.'

player = get_player(protocol, player)
if player not in protocol.players:
raise ValueError() # FIXME: proper error

if connection.name in protocol.analyzers:
if player.name == protocol.analyzers[connection.name]:
del protocol.analyzers[connection.name]
return 'You are no longer analyzing anyone.'

protocol.analyzers[connection.name] = player.name
connection.hs, connection.bs, connection.ls = 0, 0, 0
return (
'You are no longer analyzing {}. You are now analyzing {}.'.format(
protocol.analyzers[connection.name], player.name))

protocol.analyzers[connection.name] = player.name
connection.hs, connection.bs, connection.ls = 0, 0, 0
return 'You are now analyzing {}'.format(player.name)

body_damage_values = [49, 29, 27]
limb_damage_values = [33, 18, 16]
Expand Down