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

Add John Wick Award badge #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions django/stats/migrations/0021_add_john_wick_award.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.db import migrations


def forwards(apps, schema_editor):
MatchBadgeType = apps.get_model('stats', 'MatchBadgeType')
MatchBadgeType.objects.using(schema_editor.connection.alias).bulk_create(
[
MatchBadgeType(pk='john-wick-award', name='John Wick Award'),
]
)


def backwards(apps, schema_editor):
MatchBadgeType = apps.get_model('stats', 'MatchBadgeType')
MatchBadgeType.objects.using(schema_editor.connection.alias).filter(pk='john-wick-award').delete()


class Migration(migrations.Migration):
dependencies = [
('stats', '0020_rename_completed_timestamp_updatetask_completion_timestamp'),
]

operations = [
migrations.RunPython(forwards, backwards),
]
17 changes: 17 additions & 0 deletions django/stats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ def award(participation, **kwargs):
MatchBadge.award_margin_badge(
participation, 'peach', order = 'adr', margin = 0.67, emoji = '🍑', max_adr = 50, max_kd = 0.5, **kwargs,
)
MatchBadge.award_john_wick_award(participation, **kwargs)

@staticmethod
def award_with_history(participation, old_participations):
Expand Down Expand Up @@ -1142,6 +1143,22 @@ def award_margin_badge(participation, badge_type_slug, order, margin, emoji, mut
for m in participation.player.squad_memberships.all():
m.squad.notify_on_discord(text)

@staticmethod
def award_john_wick_award(participation, mute_discord = False):
badge_type = MatchBadgeType.objects.get(slug = 'john-wick-award')
kostrykin marked this conversation as resolved.
Show resolved Hide resolved
if MatchBadge.objects.filter(badge_type=badge_type, participation=participation).exists():
return
if participation.kd > 2 * participation.adr / 100:
log.info(f'{participation.player.name} received the {badge_type.name}')
MatchBadge.objects.create(badge_type = badge_type, participation = participation)
text = (
f'☠️ <{participation.player.steamid}> bagged the **{badge_type.name}** '
f'on *{participation.pmatch.map_name}*!'
)
if not mute_discord:
for m in participation.player.squad_memberships.all():
m.squad.notify_on_discord(text)

class Meta:
verbose_name = 'Match-based badge'
verbose_name_plural = 'Match-based badges'
Expand Down
6 changes: 6 additions & 0 deletions django/stats/templates/stats/squads.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
<div class="legend-item-description">Be the red lantern of your team with <span class="nowrap">K/D &leq;0.5</span>, <span class="nowrap">ADR &leq;50</span>, and a substantial deficit in ADR.</div>
</div>

<div class="legend-item">
<div style="background-image: url('{% static 'badges' %}/john-wick-award.png');" class="badge"></div>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add the missing image file john-wick-award.png

<div class="legend-item-label">John Wick Award</div>
<div class="legend-item-description">Gain a surprisingly high K/D ratio, compared to the ADR.</div>
</div>

</div>

</div>
Expand Down
24 changes: 24 additions & 0 deletions django/stats/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,30 @@ def test_peach_price__kd_and_adr_too_high(self):
models.MatchBadge.award(self.mp5)
self.assertEqual(len(models.MatchBadge.objects.filter(badge_type = 'peach', participation = self.mp5)), 0)

def test_john_wick_award(self):
"""
Test the 🏅 John Wick Award when the constraint ✅ "K/D > 2 * ADR / 100" is met.
"""
mp1 = self.pmatch.get_participation('76561197967680028')
mp1.kills = 10
mp1.deaths = 1
mp1.adr = 400
mp1.save()
models.MatchBadge.award(mp1)
self.assertEqual(len(models.MatchBadge.objects.filter(badge_type = 'john-wick-award', participation = mp1)), 1)

def test_john_wick_award_not_met(self):
"""
Test the 🏅 John Wick Award when the constraint ❌ "K/D > 2 * ADR / 100" is not met.
"""
mp1 = self.pmatch.get_participation('76561197967680028')
mp1.kills = 10
mp1.deaths = 1
mp1.adr = 600
mp1.save()
models.MatchBadge.award(mp1)
self.assertEqual(len(models.MatchBadge.objects.filter(badge_type = 'john-wick-award', participation = mp1)), 0)


class MatchBadge__award_with_history(TestCase):

Expand Down
1 change: 1 addition & 0 deletions django/stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
'rising-star',
'ace',
'quad-kill',
'john-wick-award',
]


Expand Down
Loading