//#include "inc_misc_tools"
#include "inc_gen_enc"
void main()
    {
    if (GetLocalInt(OBJECT_SELF,"DoOnce"))
        return;
    object oPC = GetLastUsedBy();
    int iLevel = GetHitDice(oPC);
    object oTemp;
    int iRoll = d20();
    switch(iRoll)
        {
        case 1:
            {
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_FNF_MYSTICAL_EXPLOSION),oPC,6.0);
            GenerateEncounter(PartyLevel(oPC),OBJECT_SELF,FALSE);
            break;
            }
        case 2:
            {
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectPoison(POISON_ARSENIC),oPC);
            break;
            }
        case 3:
            {
            ActionCastSpellAtLocation(SPELL_BESTOW_CURSE,GetLocation(oPC),METAMAGIC_ANY,TRUE);
            break;
            }
        case 4:
            {
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_FNF_MYSTICAL_EXPLOSION),oPC,6.0);
            ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectCurse(d10()-5,d10()-5,d10()-5,d10()-5,d10()-5,d10()-5)),oPC,HoursToSeconds(1));
            break;
            }
        case 5:
            {
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectBeam(VFX_BEAM_EVIL,OBJECT_SELF,BODY_NODE_CHEST),oPC,6.0);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectAbilityDecrease(GetRandomAbility(),d6()),oPC,HoursToSeconds(1));
            break;
            }
        case 6:
            {
            SetXP(oPC,GetXP(oPC)+(d10()*100*-1)*iLevel);
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_IMP_TORNADO),oPC,6.0);
            break;
            }
        case 7:
            {
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamage(d4(iLevel)),oPC);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_FNF_PWSTUN),oPC,6.0);
            break;
            }
        case 9:
        case 10:
        case 11:
            {
            ClearAllTransitions();
            ResetMonsterSpawns();
            ResetHiddenWaypoints();
            object oPC = GetFirstPC();
            while(GetIsObjectValid(oPC))
                {
                if (!GetLocalInt(GetArea(oPC),"Town"))
                    {
                    AssignCommand(oPC,PlaySound("as_na_rockfallg1"));
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_FNF_SCREEN_SHAKE),oPC);
                    }
                oPC = GetNextPC();
                }
            break;
            }
        case 8:
        case 12:
            {
            ResetMonsterSpawns();
            PlaySound("as_an_dragonror3");
            break;
            }

        case 13:
            {
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(d8(iLevel)),oPC);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_IMP_RESTORATION_LESSER),oPC,6.0);
            break;
            }
        case 14:
            {
            SetXP(oPC,GetXP(oPC)+(d10()*100)*iLevel);
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_IMP_TORNADO),oPC,6.0);
            break;
            }
        case 15:
            {
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectBeam(VFX_BEAM_HOLY,OBJECT_SELF,BODY_NODE_CHEST),oPC,6.0);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectAbilityIncrease(GetRandomAbility(),d6()),oPC,HoursToSeconds(1));
            break;
            }
        case 16:
            {
            ActionCastSpellAtObject(SPELL_REMOVE_CURSE,oPC,METAMAGIC_ANY,TRUE);
            break;
            }
        case 17:
            {
            ActionCastSpellAtLocation(SPELL_BLESS,GetLocation(oPC),METAMAGIC_EXTEND,TRUE);
            break;
            }
        case 18:
            {
            oTemp = GetFirstFactionMember(oPC,FALSE);
            while(GetIsObjectValid(oTemp))
                {
                ForceRest(oPC);
                ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_FNF_TIME_STOP),oPC,6.0);
                oTemp = GetNextFactionMember(oPC,FALSE);
                }
            break;
            }
        case 19:
            {
            ForceRest(oPC);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_FNF_TIME_STOP),oPC,6.0);
            break;
            }
        case 20:
            {
            ExecuteScript("restartmodule",GetModule());
            break;
            }
        };
    SetLocalInt(OBJECT_SELF,"DoOnce",TRUE);
    }
