from math import trunc
from commands import add


def handicap(self, value):
    if float(value) > 1 or float(value) < -1: return "Nah dont cheat and set your damage multiplier between -1 and 1 :P"
    self.handicap_value = float(value)
    u = trunc(self.handicap_value*100)
    if float(value) < 0: self.send_chat("lol wanna heal the enemy eh?")
    return "Damage output set to %i%%" % u
add(handicap)


def apply_script(protocol, connection, config):


    class Handiconnection(connection):

        handicap_value = 1.0

        def on_hit(self, hit_amount, hit_player, type, grenade):
            if hit_player != self: return trunc(hit_amount * self.handicap_value)
            else: return abs(trunc(hit_amount * self.handicap_value)) # so ya dont heal yourself with nadies
    

    return protocol, Handiconnection
