#include "in_g_cutscene"

void main()
{
object oMod = GetModule();
object oPC = GetLastUsedBy();
if (!GetIsPC(oPC)) return;

object oArea = GetArea(OBJECT_SELF);
object oTarget = GetWaypointByTag("fw_portal_wp");

int oS0 = GetLocalInt(oMod, "challenge");
int oS1 = GetLocalInt(oMod, "sw_hw");
int oS2 = GetLocalInt(oMod, "sw_dr");
int oS3 = GetLocalInt(oMod, "sw_bl");
int oS4 = GetLocalInt(oMod, "sw_pf");
int oS5 = GetLocalInt(oMod, "sw_df");
int oS6 = GetLocalInt(oMod, "sw_pm");
int oS7 = GetLocalInt(oMod, "sw_bm");
int oS8 = GetLocalInt(oMod, "sw_lm");
int oS9 = GetLocalInt(oMod, "sw_ll");
int oS10 = GetLocalInt(oMod, "sw_xx");
int nInt = GetLocalInt(oMod, "challenge");
int nInt2 = GetLocalInt(oMod, "duel_on");
int oChest = GetLocalInt(oMod, "chest_here");
int oGameMode = GetLocalInt(oMod, "gamemode");
int oModMode = GetLocalInt(oMod, "mod_mode");
int iHwar = GetLocalInt(oMod, "hwar_on");
int iStatus = GetLocalInt(oMod, "war_won");

effect eEffect = EffectVisualEffect(VFX_IMP_REMOVE_CONDITION);
effect eEffect3 = EffectVisualEffect(VFX_FNF_PWSTUN);
effect eEffect2 = EffectVisualEffect(VFX_IMP_ELEMENTAL_PROTECTION);
int Scene = GetLocalInt(oPC, "cutscene_on");

if (oModMode!=1)
   {
    if (iHwar==1)
    {
     if (iStatus!=1)
        {
         PlaySound("sim_cntresist");
         FloatingTextStringOnCreature("** Holy War in progress **", oPC);
         return;
        }
     else if (iStatus==1)
        {
         PlaySound("sim_cntresist");
         FloatingTextStringOnCreature("You must clear the arena first.", oPC);
         return;
        }
    }
    if (oChest!=1)
       {
        if ((nInt!=1)&&(nInt2!=1)&&(oS1!=1)&&(oS2!=1)&&(oS3!=1)
           &&(oS4!=1)&&(oS5!=1)&&(oS6!=1)&&(oS7!=1)&&(oS8!=1)
           &&(oS9!=1)&&(oS0!=1)&&(oS10!=1))
           {
            object oMonster = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC);
            if ((!GetIsEnemy(oPC, oMonster))||(oMonster==OBJECT_INVALID))
               {
                if (Scene!=1)
                   {
                    DelayCommand(0.0, ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
                    eEffect, GetLocation(oPC)));
                    DelayCommand(0.1, ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
                    eEffect2, GetLocation(oPC)));
                    DelayCommand(0.2, ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
                    eEffect3, GetLocation(oPC)));
                    GestaltPlayMusic(0.3, oArea, TRUE, TRACK_ORIGINAL);
                    GestaltPlayMusic(0.4, oArea, FALSE);
                    GestaltJump(1.5, oPC, OBJECT_INVALID, "lake_wp" );
                   }
                else
                   {
                    PlaySound("sim_cntresist");
                    FloatingTextStringOnCreature("The portal doesn't respond.", oPC);
                   }
               }
            else
               {
                PlaySound("sim_cntresist");
                FloatingTextStringOnCreature("You must finish your battle first.", oPC);
                return;
               }
           }
        else
           {
            if (nInt==1)
               {
                PlaySound("sim_cntresist");
                FloatingTextStringOnCreature("You must finish the super challenge first.", oPC);
               }
            else if (nInt2==1)
               {
                PlaySound("sim_cntresist");
                FloatingTextStringOnCreature("You must finish your duel first.", oPC);
               }
            else
               {
                PlaySound("sim_cntresist");
                FloatingTextStringOnCreature("You must finish your battle first.", oPC);
               }
           }
       }
    else
       {
        PlaySound("sim_cntresist");
        FloatingTextStringOnCreature("You must open the reward chest first.", oPC);
       }
    }
 else
    {
     PlaySound("sim_cntresist");
     FloatingTextStringOnCreature("This feature is univalible in campaign manager mode.", oPC);
    }
}