#include "jump_include"
#include "jump_inc_pattern"

void main()
{
    float fDelay = 1.0;
    int bTurnToTarget = TRUE;

    // Check if the jumper can be activated.
    if (ActivateJumper(fDelay, bTurnToTarget))
    {
        //Pull variables and add to use count
        int nUseCount = GetLocalInt(oJumper,"Use Count")+1;
        int nSeenScarecrow = GetLocalInt(oJumper,"Seen Scarecrow");
        int nSeenDummy = GetLocalInt(oJumper,"Seen Dummy");
        int nSeenToy = GetLocalInt(oJumper,"Seen Toy");
        int nSeenBox = GetLocalInt(oJumper,"Seen Box");
        int nSeenCutout = GetLocalInt(oJumper,"Seen Cutout");
        int nSeenFrog = GetLocalInt(oJumper,"Seen Frog");
        int nSeenCake = GetLocalInt(oJumper,"Seen Cake");
        SetLocalInt(oJumper,"Use Count",nUseCount);
        if(nUseCount==5 || nUseCount==25 || nUseCount==50 || nUseCount==100 || nUseCount==200 || nUseCount==300)
        {
            SendMessageToPC(oPC,"You've unlocked a new replacement object for your jumper!");
        }
        if(nUseCount==500)
        {
            SendMessageToPC(oPC,"Congratulations! You've unlocked the final replacement object for this jumper! Keep using it until you see it!");
        }

        
        // Visual effects
        ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectVisualEffect(355), oPC, 1.0); //Cutscene invisibility
        ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(460), lPC); //Smoke cloud
        ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(319), lPC, 10.0); //Caltrops


        //Roll for replacement object
        int nObjectRoll = d100();

        //Assign and Spawn Replacement Object
        object oReplacementObject;
        if(nObjectRoll<=50)
        {
            oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjalog", lPC); //The replacement object is a log.
        }

        if(nObjectRoll >=51 && nObjectRoll <= 70)
        {
            if(nUseCount >=5)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjadum", lPC); //The replacement object is a scarecrow.
                if(nSeenScarecrow==0)
                {
                    SendMessageToPC(oPC, "You left behind a replacement object you've never used before.");
                }
                nSeenScarecrow=1;
                SetLocalInt(oJumper,"Seen Scarecrow", 1);
            }
            if(nUseCount <5)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjalog", lPC); //The replacement object is a log.
            }
        }

        if(nObjectRoll >=71 && nObjectRoll <= 90)
        {
            if(nUseCount >= 25)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjadu2", lPC); //The replacement object is a dummy.
                if(nSeenDummy==0)
                {
                    SendMessageToPC(oPC, "You left behind a replacement object you've never used before.");
                }
                nSeenDummy=1;
                SetLocalInt(oJumper,"Seen Dummy", 1);
            }
            if(nUseCount <25)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjalog", lPC); //The replacement object is a log.
            }
        }

        if(nObjectRoll >=91 && nObjectRoll <= 93)
        {
            if(nUseCount>= 50)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjatoy", lPC); //The replacement object is a stuffed animal.
                if(nSeenToy==0)
                {
                    SendMessageToPC(oPC, "You left behind a replacement object you've never used before.");
                }
                nSeenToy=1;
                SetLocalInt(oJumper,"Seen Toy", 1);
            }
            if(nUseCount <50)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjalog", lPC); //The replacement object is a log.
            }
        }

        if(nObjectRoll >=94 && nObjectRoll <= 95)
        {
            if(nUseCount>= 100)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjabox", lPC); //The replacement object is a cardboard box.
                if(nSeenBox==0)
                {
                    SendMessageToPC(oPC, "You left behind a replacement object you've never used before.");
                }
                nSeenBox=1;
                SetLocalInt(oJumper,"Seen Box", 1);
            }
            if(nUseCount <100)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjalog", lPC); //The replacement object is a log.
            }
        }

        if(nObjectRoll >=96 && nObjectRoll <= 97)
        {
            if(nUseCount>= 200)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_CREATURE, "cas_ninjajumpfrg", lPC); //The replacement object is a frog.
                DelayCommand(5.0,(AssignCommand(oReplacementObject, ActionSpeakString("Ribbit?"))));
                if(nSeenFrog==0)
                {
                    SendMessageToPC(oPC, "You left behind a replacement object you've never used before.");
                }
                nSeenFrog=1;
                SetLocalInt(oJumper,"Seen Frog", 1);
            }
            if(nUseCount <200)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjalog", lPC); //The replacement object is a log.
            }
        }        

        if(nObjectRoll >=98 && nObjectRoll <= 99)
        {
            if(nUseCount>= 300)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjacut", lPC); //The replacement object is a cardboard cutout of a tree.
                if(nSeenCutout==0)
                {
                    SendMessageToPC(oPC, "You left behind a replacement object you've never used before.");
                }
                nSeenCutout=1;
                SetLocalInt(oJumper,"Seen Cutout", 1);
            }
            if(nUseCount <300)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjalog", lPC); //The replacement object is a log.
            }
        } 

        if(nObjectRoll == 100)
        {
            if(nUseCount>= 500)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjacak", lPC); //The replacement object is a birthday cake.
                if(nSeenCake==0)
                {
                    SendMessageToPC(oPC, "You left behind a replacement object you've never used before.");
                }
                nSeenCake=1;
                SetLocalInt(oJumper,"Seen Cake", 1);
            }
            if(nUseCount <500)
            {
                oReplacementObject = CreateObject(OBJECT_TYPE_PLACEABLE, "cas_jumpninjalog", lPC); //The replacement object is a log.
            }
        } 

        //Update the item's description
        string sUseCount = IntToString(nUseCount);
        string sUnlocked = "1";
        string sUnlockMessage = "Keep using the jumper to unlock the rest!";
        if(nUseCount>=5)
        {
            sUnlocked="2";
        }
        if(nUseCount>=25)
        {
            sUnlocked="3";
        }
        if(nUseCount>=50)
        {
            sUnlocked="4";
        }
        if(nUseCount>=100)
        {
            sUnlocked="5";
        }
        if(nUseCount>=200)
        {
            sUnlocked="6";
        }
        if(nUseCount>=300)
        {
            sUnlocked="7";
        }
        if(nUseCount>=500)
        {
            sUnlocked="8";
            sUnlockMessage="That's all of them! Great job!";
        }


        string sReplacementsSeen = "Log";
        if(nSeenScarecrow==1)
        {
            sReplacementsSeen=sReplacementsSeen+", scarecrow";
        }
        if(nSeenDummy==1)
        {
            sReplacementsSeen=sReplacementsSeen+", dummy";
        }
        if(nSeenToy==1)
        {
            sReplacementsSeen=sReplacementsSeen+", stuffed animal";
        }
        if(nSeenBox==1)
        {
            sReplacementsSeen=sReplacementsSeen+", cardboard box";
        }
        if(nSeenFrog==1)
        {
            sReplacementsSeen=sReplacementsSeen+", confused frog";
        }
        if(nSeenCutout==1)
        {
            sReplacementsSeen=sReplacementsSeen+", cardboard cutout";
        }
        if(nSeenCake==1)
        {
            sReplacementsSeen=sReplacementsSeen+", cake";
        }
        sReplacementsSeen=sReplacementsSeen+".";
        if(nSeenScarecrow==1 && nSeenDummy==1 && nSeenToy==1 && nSeenBox==1 && nSeenFrog==1 && nSeenCutout==1 && nSeenCake==1)
        {
           sReplacementsSeen="Log (50%), scarecrow (20%), dummy (20%), stuffed animal (3%), cardboard box (2%), confused frog (2%), cardboard cutout (2%), birthday cake (1%)."; 
        }

        string sFullDescription = "Disappear in a cloud of smoke, leaving one of several replacement objects and illusory caltrops in your wake.\n\nThe more times the jumper is used, the more different types of objects are unlocked and may be left in your wake. Replacement objects are selected randomly from among all of the ones that have been unlocked, with later objects also being less likely to appear.\n\nThis jumper has been used <cÿÃ>"+sUseCount+"</c> times.\n\n<cææ>Replacement Objects Unlocked:</c> "+sUnlocked+" of 8.\n"+sUnlockMessage+"\n\n<cææ>Replacement Objects Seen:</c> "+sReplacementsSeen;

        SetDescription(oJumper,sFullDescription);


        //Destroy the replacement object.
        DelayCommand(12.0,DestroyObject(oReplacementObject));


        // Force the PC into stealth
        DelayCommand(0.1, SetActionMode(oPC, ACTION_MODE_STEALTH, TRUE));
    }
}
