import es
import gamethread

import wcs
from wcs import wcs

itemName = 'Helmet of Protection'

wcs.Item(itemName).registerItem('defense', 3500, "You reflect all damage for the next 10 seconds", True)
        
def item_bought(ev):
    if ev['item'] == itemName:
        es.tell(ev['userid'], '#multi', '#greenHelmet of Protection #default- #lightgreenYou will reflect all damage for the next 10 seconds.')
        gamethread.delayedName(10, 'wcs_helmetOfProt_user%s' % ev['userid'], wcs.Command(ev['userid']).RemoveItem, itemName)
        gamethread.delayedName(10, 'wcs_helmetOfProt_user%s' % ev['userid'], es.tell, (ev['userid'], '#multi', '#greenHelmet of Protection #default- #lightgreenYou will not reflect any more damage.' ))
        
def player_hurt(ev):
    if ev['attacker'] != '0' and ev['es_attackerteam'] != ev['es_userteam']:
        count   = wcs.Command(ev['userid']).GetItemCount(itemName)
        if count:
            amount = int(ev['userid'])
            wcs.Command(ev['userid']).Heal(amount)
            wcs.Command(ev['attacker']).Damage(amount, 32, ev['userid'])
            es.tell(ev['userid'], '#multi', '#greenHelmet of Protection #default- #lightgreenYou have reflected #green%s #ligtgreendamage to #green%s' % (amount, ev['es_attackername']) )
            es.tell(ev['attacker'], '#multi', '#greenHelmet of Protection #default- #lightgreenYou have had %s damage reflected #ligtgreenby #green%s' % (amount, ev['es_username']) )
        
def player_death(ev):
    wcs.Command(ev['userid']).RemoveItem(itemName)
    gamethread.cancelDelayed('wcs_helmetOfProt_user%s' % ev['userid'])
