#Trap #2 - Poison Needles
# 2d2+2, poison 1d4/40 ticks, save vs. DX for half damage, save vs. CN for all poison
from eventAPI import *
from APIUtils import *

def fireEvent(e):
    lFlagS = getTag(e, "lFlagS")
    if (not issetany(lFlagS, 0x00000300)):
        return 1
    if (isclearall(lFlagS, 0x00000002)):
        showMessage(e, ["As you place your feet down, you hear a quiet \"Woosh!\" and are painfully pelted with needles!"], optionInput)
        for partyIdx in range(getPartyCount(e)):
            # Physical dmg
            dmg = dice(2, 2, 2)
            if (not savingThrow(e, "dex", partyIdx, 0)):
                dmg /= 2
            modifyHP(e, partyIdx, -dmg)
            # Poison
            if (not savingThrow(e, "con", partyIdx, 0)):
                poison(e, partyIdx, 1, 4, 0, 40, 1, dice(40, 6, 240))
    return 1
