import es
import gamethread

import wcs
from wcs import wcs

itemName = 'Necklace of Protection'

wcs.Item(itemName).registerItem('defense', 3000, "You nullify all damage for the next 10 seconds", True)
        
def item_bought(ev):
    if ev['item'] == itemName:
        es.tell(ev['userid'], '#multi', '#greenNecklace of Protection #default- #lightgreenYou will reflect all damage for the next 10 seconds.')
        gamethread.delayedName(10, 'wcs_necklaceOfProt_user%s' % ev['userid'], wcs.Command(ev['userid']).RemoveItem, itemName)
        gamethread.delayedName(10, 'wcs_necklaceOfProt_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)
            es.tell(ev['userid'], '#multi', '#greenNecklace of Protection #default- #lightgreenYou have nullified #green%s #ligtgreendamage.' % (amount) )
        
def player_death(ev):
    wcs.Command(ev['userid']).RemoveItem(itemName)
    gamethread.cancelDelayed('wcs_necklaceOfProt_user%s' % ev['userid'])
