//::///////////////////////////////////////////////
//:: Name(ASG_RULE) Setup Magic Items
//:: FileName
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Used for assembiling magic items Vol 1.
*/
//:://////////////////////////////////////////////
//:: Created By:    Donny Wilbanks
//:: Created On:    09/07/02
//:://////////////////////////////////////////////

//  asg_REQ1(object oPC,int vREQ, int vNUM);
#include "nw_i0_plot"
int asg_REQ1(object oPC,string sTag,int vNUM)
{
int TRUEFALSE = FALSE;
    if (sTag=="")
    {
        ActionSpeakString("ERROR: Test Resource Script Error NO VALID sTag.");
        return TRUEFALSE;
    }
    else
    {
        int vITEMTOBUILD = GetLocalInt(oPC,"ITEMTOBUILD");
        object oItem = GetFirstItemInInventory(oPC);
        int vCount;


        vCount =  GetNumItems(oPC,sTag);
        ActionSpeakString("Test: Resource ("+sTag+") Found ["+IntToString(vCount)+"]");
        if (vCount>=vNUM)
        {
            TRUEFALSE=TRUE;
            ActionSpeakString("Test: Found Required Resources found.");
        }
        else
        {
            ActionSpeakString("Test: Resources not found Required ["+IntToString(vNUM)+"].");
        }
        return TRUEFALSE;
    }
}
//

int StartingConditional()
{
    int iResult = FALSE;
    object oPC = GetPCSpeaker();
    // general religous stuff.
    int vGoodEvil = GetLocalInt(oPC,"GoodEvil");
    int vLawChaos = GetLocalInt(oPC,"LawChaos");
    string sDeity=GetLocalString(oPC,"INGAMEDEITY");
    string sName;
    // Set Shrine properties based on alignment
    if (sDeity=="")
    {
       SetLocalInt(oPC,"DeityOVERIDE",TRUE);
       sDeity = "Baccob";
       vGoodEvil = ALIGNMENT_NEUTRAL;
       vLawChaos = ALIGNMENT_NEUTRAL;
       SetLocalString(oPC,"INGAMEDEITY",sDeity);
       SetLocalInt(oPC,"GoodEvil",vGoodEvil);
       SetLocalInt(oPC,"LawChaos",vLawChaos);
    }

    // return to other stuff
    int vITEMTOBUILD = GetLocalInt(oPC,"ITEMTOBUILD");
    int vNUMBERGIVEN =1;
    string sREQ1;
    string sREQ2;
    string sREQ3;
    string sREQ4;
    int vNUM1 = 0;
    int vNUM2 = 0;
    int vNUM3 = 0;
    int vNUM4 = 0;
    int vNOERROR = TRUE;
    int vNEEDED = 0;
    int vTRUE = FALSE;
    int vREQUIRED = 0;
    string sItem;
    string sBluePrint;
    int vPLACE; // (1) = ITEM, goes on pc's inventory, (2) PLACEABLE, goes on ground at PC's FEET.
    // (3) PLACEABLE, goes near another object.
    // (4) Item is a Creature - needs a summoning point = again with the sDist_What
    string sDIST_WHAT; // If option 3 is selected then search for this object. Look for
    // this TAG.
    float vDIST; // (0) if option 3 is selected this tells us how far from this object
    // that this item can be built.

    switch(vITEMTOBUILD)
    {
        case(1000): // The Pandora's Box (unlit).
        {
            sItem = "Pandora's Box";
            sBluePrint = "pandorasbox";
            vPLACE = 1;
            // Items Required.
            sREQ1="MagicPowder";
            vNUM1 = 10; // 1 Units of Magic Powder
            // Items required.
            sREQ2="NW_IT_CONTAIN001";
            vNUM2 = 1;
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 20;
             // tells the true/false that there are "x" number of trues
        }
        break;
        // pandorasretuner
        case(1001): // Add On (unlit).
        {
            sItem = "Pandora's Box";
            sBluePrint = "pandorasretuner";
            vPLACE = 1;
            // Items Required.
            sREQ1="MagicPowder";
            vNUM1 = 1; // 1 Units of Magic Powder.
            // Items required.
            sREQ2="ASG_PUZZELBOX";
            vNUM2 = 1;
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 20;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        case(1002): // Add On (unlit).
        {
            sItem = "Pandora's Stableizer";
            sBluePrint = "pandorasstabalis";
            vPLACE = 1;
            // Items Required.
            sREQ1="MagicPowder";
            vNUM1 = 1; // 1 Units of Magic Powder
            // Items required.
            sREQ2="ASG_PUZZELBOX";
            vNUM2 = 1;
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 2;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        case(1003): // Build Returner (unlit).
        {
            sItem = "Pandora's Returner";
            sBluePrint = "pandorasretuner";
            vPLACE = 1;
            // Items Required.
            sREQ1="MagicPowder";
            vNUM1 = 1; // 1 Units of Magic Powder.
            // Items required.
            sREQ2="ASG_PUZZELBOX";
            vNUM2 = 1;
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 7;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        case(1004): // Build Locaalizer (unlit).
        {
            sItem = "Pandora's Localiser";
            sBluePrint = "pandorasloclaise";
            vPLACE = 1;
            // Items Required.
            sREQ1="MagicPowder";
            vNUM1 = 1; // 1 Units of Fairy Dust
            // Items required.
            sREQ2="ASG_PUZZELBOX";
            vNUM2 = 1;
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 10;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        case(1010): // Dhopper
        {
            sItem = "Dhopper";
            sBluePrint = "dhopper001";
            vPLACE = 1;
            // Items Required.
            sREQ1="MagicPowder";
            vNUM1 = 10; // 1 Units of Fairy Dust
            // Items required.
            sREQ2="ASG_EARTHGEM";
            vNUM2 = 1;
            //
            sREQ3="MetalRod";
            vNUM3 = 1;
            // Xp Requirement
            sREQ4="XP";
            vNUM4 = 100;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        case(1011): // Secyre Shelter
        {
            sItem = "Secure Shelter";
            sBluePrint = "secureshelter";
            vPLACE = 1;
            // Items Required.
            sREQ1="MagicPowder";
            vNUM1 = 10; // 1 Units of Fairy Dust
            // Items required.
            sREQ2="SmallHouseModel";
            vNUM2 = 1;
            // Xp Requirement
            sREQ4="XP";
            vNUM4 = 100;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        // ******* Cleric Stuff ****
        case(2000): // Potion of Cure Light Wounds (unlit).
        {
            sItem = "Potion of Cure Light Wounds";
            sBluePrint = "nw_it_mpotion001";
            vPLACE = 1;
            // Items Required.
            sREQ1="ASG_HOLYWATER";
            vNUM1 = 1; // 1 Units of Fairy Dust
            // Items required.
            sREQ2="NW_IT_THNMISC001";
            vNUM2 = 1; // 1 unit to build club
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 1;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        case(2001): // Potion of Moderate Light Wounds (unlit).
        {
            sItem = "Potion of Moderate Wounds";
            sBluePrint = "nw_it_mpotion020";
            vPLACE = 1;
            // Items Required.
            sREQ1="ASG_HOLYWATER";
            vNUM1 = 2; // 1 Units of Fairy Dust
            // Items required.
            sREQ2="NW_IT_THNMISC001";
            vNUM2 = 1; // 1 unit to build club
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 1;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        case(2002): // Potion of Serious Wounds (unlit).
        {
            sItem = "Potion of Serious Wounds";
            sBluePrint = "nw_it_mpotion002";
            vPLACE = 1;
            // Items Required.
            sREQ1="ASG_HOLYWATER";
            vNUM1 = 3; // 1 Units of Fairy Dust
            // Items required.
            sREQ2="NW_IT_THNMISC001";
            vNUM2 = 1; // 1 unit to build club
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 2;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        case(2003): // Potion of Critical Wounds (unlit).
        {
            sItem = "Potion of Critical Wounds";
            sBluePrint = "nw_it_mpotion003";
            vPLACE = 1;
            // Items Required.
            sREQ1="ASG_HOLYWATER";
            vNUM1 = 4; // 1 Units of Fairy Dust
            // Items required.
            sREQ2="NW_IT_THNMISC001";
            vNUM2 = 1; // 1 unit to build club
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 11;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;
        case(2004): // Potion of Serious Wounds (unlit).
        {
            sItem = "Potion of Heal";
            sBluePrint = "nw_it_mpotion012";
            vPLACE = 1;
            // Items Required.
            sREQ1="ASG_HOLYWATER";
            vNUM1 = 5; // 1 Units of Fairy Dust
            // Items required.
            sREQ2="NW_IT_THNMISC001";
            vNUM2 = 1; // 1 unit to build club
            // Items Requried - Last is always XP.
            sREQ4="XP";
            vNUM4 = 52;
             // tells the true/false that there are "x" number of trues pandorasstabalis
        }
        break;

        default:;

        ActionSpeakString("ERROR in ''asg_rul_testbsel'' script on finding item:"+IntToString(vITEMTOBUILD));
    }
    vNEEDED=0;
    object oCChest = GetNearestObjectByTag("ASG_CCHEST",OBJECT_SELF);
    if (vNOERROR==TRUE)
    {
        int vK;vTRUE=FALSE;
        if (vNUM1>0)
        {
            vTRUE = asg_REQ1(oCChest,sREQ1,vNUM1);
            vNEEDED++;
        }
        if (vTRUE==TRUE) vREQUIRED++;
        vTRUE=FALSE;
        if (vNUM2>0)
        {
            vTRUE = asg_REQ1(oCChest,sREQ2,vNUM2);
            vNEEDED++;
        }
        if (vTRUE==TRUE) vREQUIRED++;
        vTRUE=FALSE;
        if (vNUM3>0)
        {
            vTRUE = asg_REQ1(oCChest,sREQ3,vNUM3);
            vNEEDED++;
        }
        if (vTRUE==TRUE) vREQUIRED++;
        vTRUE=FALSE;
        if (vNUM4>0)
        {
            // Specail
            int vXP = GetXP(oPC);
            if (vXP>=vNUM4)vTRUE=TRUE;
            vNEEDED++;
        }
        if (vTRUE==TRUE) vREQUIRED++;
        vTRUE=FALSE;
    }
    if (vREQUIRED>=vNEEDED)
    {
    // last check for placement requirements
        int vResult = TRUE;
        if (vPLACE==5 || vPLACE==3)
        {
            object oPlace = GetNearestObjectByTag(sDIST_WHAT,oPC);
            float vHOWFAR = GetDistanceBetween(oPlace,oPC);
            if (vHOWFAR<=vDIST)
            {
                vResult=TRUE;
            }
            else
            {
                ActionSpeakString("ERROR: To Far from closest ["+GetName(oPlace)+"] Distance ["+FloatToString(vHOWFAR)+"]");
                vResult=FALSE;
            }
        }
        if (vResult==TRUE)
        {
            ActionSpeakString("All items for the "+sItem+" have been found.");
            SetLocalString(oPC,"BLUEPRINT",sBluePrint);
            SetLocalInt(oPC,"NUMBERGIVEN",vNUMBERGIVEN);
            object oPC = GetPCSpeaker();
            SetLocalString(oPC,"REQ1",sREQ1);
            SetLocalString(oPC,"REQ2",sREQ2);
            SetLocalString(oPC,"REQ3",sREQ3);
            SetLocalString(oPC,"REQ4",sREQ4);
            SetLocalInt(oPC,"NUM1",vNUM1);
            SetLocalInt(oPC,"NUM2",vNUM2);
            SetLocalInt(oPC,"NUM3",vNUM3);
            SetLocalInt(oPC,"NUM4",vNUM4);
            SetLocalInt(oPC,"PLACE",vPLACE);
            SetLocalString(oPC,"DIST_WHAT",sDIST_WHAT);
            iResult=TRUE;
        }

    }
    else
    {
        ActionSpeakString("TEST: Requirement have for the "+sItem+" have not been met.");

    }
    return iResult;
}