#!/usr/bin/env bash

play() {

    if [[ -r "/usr/share/mkill/sounds/$1" ]]; then
        aplay "/usr/share/mkill/sounds/$1" 2>/dev/null
        return
    fi

    if [[ -r "sounds/$1" ]]; then
        aplay "sounds/$1" 2>/dev/null
        return
    fi
}

count=$(pgrep -c "$1")

pkill "$1"
exit_code=$?

if [[ $exit_code -eq 0 ]]; then

    case $count in
        1) play firstblood.wav   ; exit $exit_code ;;
        2) play doublekill.wav   ; exit $exit_code ;;
        3) play triplekill.wav   ; exit $exit_code ;;
        4) play multikill.wav    ; exit $exit_code ;;
        5) play ultrakill.wav    ; exit $exit_code ;;
        6) play monsterkill.wav  ; exit $exit_code ;;

    esac

    if [[ $count -ge 25 ]]; then
        play godlike.wav         ; exit $exit_code
    fi

    if [[ $count -ge 20 ]]; then
        play unstoppable.wav     ; exit $exit_code
    fi

    if [[ $count -ge 15 ]]; then
        play dominating.wav      ; exit $exit_code
    fi

    if [[ $count -ge 10 ]]; then
        play rampage.wav         ; exit $exit_code
    fi

    if [[ $count -gt 6 ]]; then
        play killingspree.wav    ; exit $exit_code
    fi

fi

