#include "nw_i0_generic"
#include "NW_I0_SPELLS"

#include "jx_inc_magic"
#include "x2_inc_spellhook"

void mainSpell();
void main()
{
	AssignCommand(JXGetCaster(), mainSpell());
}

void mainSpell()
{
	if (!X2PreSpellCastCode()) { JXPostSpellCastCode(); return; }



    object oTarget = JXGetSpellTargetObject();
    effect eImpact = EffectVisualEffect(VFX_IMP_BIGBYS_FORCEFUL_HAND);
    JXApplyEffectToObject(DURATION_TYPE_INSTANT, eImpact, oTarget);
    int nDamage = Random(30) + 30;
    effect eDamage;
    ActionCastFakeSpellAtObject(SPELL_BIGBYS_FORCEFUL_HAND, oTarget);
    if (!MySavingThrow(SAVING_THROW_REFLEX, oTarget, 32, SAVING_THROW_TYPE_NONE))
    {
        effect eKnock = EffectKnockdown();
        int nDur = d6(1) + 1;
        JXApplyEffectToObject(DURATION_TYPE_TEMPORARY, eKnock, oTarget);
        eDamage = EffectDamage(nDamage, DAMAGE_TYPE_BLUDGEONING);
    }
    else // half damage and no knockdown
    {
        nDamage /= 2;
    }
    eDamage = EffectDamage(nDamage, DAMAGE_TYPE_BLUDGEONING);
    JXApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oTarget);

	JXPostSpellCastCode();
}
