/// <summary>
        /// Gets all the information from the form and makes it into a story node
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void finish_Click(object sender, EventArgs e)
        {
            #region Initial Checks
            if (storyNodeName.Text == String.Empty)
                {
                report("You need to give the story node a name");
                storyNodeName.Focus();
                return;
                }
            if (comboActor.SelectedItem == null)
                {
                report("You need to select an actor");
                comboActor.Focus();
                return;
                }
            if ((radioSimpPreReq.Checked || radioCastSpecPreReq.Checked) && comboPreRec.SelectedItem == null)
                {
                report("You need to choose a story node or choose to have no prerequisite");

                return;
                }

            // if either the journalCheck is disabled or the Journalbox is non-empty we continue
            if (checkJournal.Checked && JournalBox.Text == String.Empty)
                {
                report("You need to write something for the Journal entry");
                JournalBox.Focus();
                return;
                }
            #endregion

            // I create the story node
            sNode = new StoryNode(storyNodeName.Text, (Actor)comboActor.SelectedItem, (Actor)comboTriggers.SelectedItem, module);

            #region whatHappens
            // I set happens
            if (radioConvs.Checked)
                {
                sNode.happensEnum = EnumTypes.happens.Conv;
                }
            else if (radioVillian.Checked)
                {
                sNode.happensEnum = EnumTypes.happens.Conflict;
                sNode.villianTalk = checkVillianTalk.Checked;
                }
            else if (radioDoor.Checked)
                {
                sNode.happensEnum = EnumTypes.happens.OpenDoor;
                sNode.containerContains = checkContainerContains.Checked && checkContainerContains.Enabled;
                }
            else if (triggerRadio.Checked)
                {
                sNode.happensEnum = EnumTypes.happens.Trigger;
                }
            #endregion

            #region convType
            // I set the convType
            if (radioConvs.Checked || (radioVillian.Checked && checkVillianTalk.Checked) || radioDoor.Checked)
                {
                if (radioQuestInfo.Checked)
                    {
                    sNode.convEnum = EnumTypes.conv.QuestInfo;
                    }
                else
                    {
                    sNode.convEnum = EnumTypes.conv.Single;
                    }
                }

            // I set the type of the convTypeEnum (whatever the player has to escort/explore)
            if (checkEscort.Checked)
                {
                sNode.convHappens = StoryNode.convType.Escort;
                }
            else if (checkExplore.Checked)
                {
                sNode.convHappens = StoryNode.convType.Explore;
                }

            // I set whether the finish trigger is escort or Explore
            if (radioFinishEscort.Checked)
                {
                sNode.triggerHappens = StoryNode.convType.Escort;
                }
            else if (radioFinishExplore.Checked)
                {
                sNode.triggerHappens = StoryNode.convType.Explore;

                }
            #endregion

            #region Items
            // The Items

            bool end = false;
            if (checkTake.Checked && checkTake.Enabled)
                {
                if (comboTakeItem.SelectedItem != null && comboTakeItem.SelectedText.ToLower() != "nothing")
                    {
                    sNode.itemTake = (Actor)comboTakeItem.SelectedItem;
                    sNode.takeNumber = (int)takeItemNumber.Value;
                    debug("Take item: " + sNode.itemGive.ToString() + ", number: " + sNode.giveNumber);
                    }
                try
                    {
                    sNode.takeGold = int.Parse(takeGold.Text);
                    }
                catch //(Exception ex)
                    {
                    end = true;
                    report("You can only input integers");
                    }
                }

            if (checkGive.Checked && checkGive.Enabled)
                {

                if (comboGiveItem.SelectedItem != null && comboTakeItem.SelectedText.ToLower() != "nothing")
                    {
                    sNode.itemGive = (Actor)comboGiveItem.SelectedItem;
                    sNode.giveNumber = (int)giveItemNumber.Value;
                    debug("Give item: " + sNode.itemGive.ToString() + ", number: " + sNode.giveNumber);
                    }
                try
                    {
                    sNode.giveGold = int.Parse(giveGold.Text);
                    }
                catch// (Exception ex)
                    {
                    end = true;
                    report("You can only input integers");
                    }
                }

            // The villian part
            if (
                //(villianItem.Checked || containerContains.Checked) &&
                //  villianItem.Enabled
                comboDropItem.Enabled && comboDropItem.SelectedItem != null && comboDropItem.Text.ToLower() != "nothing")
                {
                //           System.Windows.Forms.report("Got item: " + ((Actor)dropItemCombo.SelectedItem).ToString());
                sNode.villianItem = (Actor)comboDropItem.SelectedItem;
                sNode.villianGotItem = true;
                }
            #endregion Items

            #region Conversation
            // The conversation
            // For there to be an conversation, the conv options only needs to be enabled
            if (radioQuestInfo.Enabled)
                {
                sNode.greeting = greetBox.Text;

                if (radioQuestInfo.Checked)
                    {
                    sNode.acceptence = acceptBox.Text;
                    sNode.action = actionBox.Text;
                    sNode.rejection = rejectBox.Text;
                    }
                }

            if (triggers.Count > 0 && comboTriggers.Enabled == true)
                {
                trigger = (NWN2TriggerBlueprint)((Actor)comboTriggers.SelectedItem).blueprint;
                }
            #endregion

            #region PreRec
            sNode.preReq = EnumTypes.prereq.NoPrereq;
            if (comboPreRec.SelectedItem != null && !radioNoPreReq.Checked)
                {
                sNode.preReqNode = (StoryNode)comboPreRec.SelectedItem;

                if (radioSimpPreReq.Checked)
                    {
                    sNode.preReq = EnumTypes.prereq.SimplePrereq;
                    }
                else
                    {
                    sNode.preReq = EnumTypes.prereq.CastSpecificPrereq;
                    }
                }
            #endregion

            #region Journal and XP
            /* I add the journal text - if there is no text I will not add a
             * journal entry, nor will I use it as prerequiste
             */
            sNode.journal = JournalBox.Text;
            sNode.journalCheck = checkJournal.Checked;

            //.. and the xp

            try
                {
                sNode.xp = int.Parse(XP.Text);
                if (sNode.xp < 0)
                    {
                    report("XP must be given as a nonnegative value");
                    return;
                    }
                }
            catch
                {
                end = true;
                report("You can only input integers");
                return;
                }

            sNode.endPoint = checkEndPoint.Checked;

            if (!end)
                {
                DialogResult = DialogResult.OK;
                this.Close();
                }
            #endregion
        }
Example #2
0
        /// <summary>
        /// Create a new blueprint
        /// </summary>
        /// <param name="objectType">The type of the blueprint that is about to be created</param>
        /// <param name="locationType">The location where the blueprint will be placed</param>
        /// <returns>The new blueprint</returns>
        private static INWN2Blueprint createNewBlueprint(NWN2ObjectType objectType, NWN2BlueprintLocationType locationType)
        {
            INWN2Blueprint cBlueprint = null;
            IResourceRepository userOverrideDirectory = null;
            NWN2Campaign activeCampaign = NWN2CampaignManager.Instance.ActiveCampaign;
            INWN2BlueprintSet instance = null;
            switch (locationType)
                {
                case NWN2BlueprintLocationType.Global:
                    userOverrideDirectory = NWN2ResourceManager.Instance.UserOverrideDirectory;
                    if (userOverrideDirectory != null)
                        {
                        userOverrideDirectory = NWN2ResourceManager.Instance.OverrideDirectory;
                        }
                    instance = NWN2GlobalBlueprintManager.Instance;
                    break;

                case NWN2BlueprintLocationType.Module:
                    instance = NWN2Toolset.NWN2ToolsetMainForm.App.Module;
                    userOverrideDirectory = NWN2Toolset.NWN2ToolsetMainForm.App.Module.Repository;
                    break;

                case NWN2BlueprintLocationType.Campaign:
                    userOverrideDirectory = (activeCampaign != null) ? activeCampaign.Repository : null;
                    instance = activeCampaign;
                    break;

                default:
                    throw new Exception("Unknown object type in CreateNewBlueprint()" + locationType.ToString());
                }

            if ((userOverrideDirectory == null) || (instance == null))
                {
                return null;
                }
            switch (objectType)
                {
                case NWN2ObjectType.Creature:
                    cBlueprint = new NWN2CreatureBlueprint();
                    createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Creature, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTC"));
                    break;

                case NWN2ObjectType.Door:
                    cBlueprint = new NWN2DoorBlueprint();
                    createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Door, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTD"));
                    break;

                case NWN2ObjectType.Item:
                    cBlueprint = new NWN2ItemBlueprint();
                    createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Item, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTI"));
                    break;

                case NWN2ObjectType.Placeable:
                    cBlueprint = new NWN2PlaceableBlueprint();
                    createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Placeable, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTP"));
                    break;

                case NWN2ObjectType.Trigger:
                    cBlueprint = new NWN2TriggerBlueprint();
                    createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Trigger, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTT"));
                    break;

                default:
                    throw new Exception("Unknown object type in CreateNewBlueprint()");
                }
            NWN2BlueprintCollection blueprintCollectionForType = instance.GetBlueprintCollectionForType(objectType);
            INWN2Object obj2 = cBlueprint as INWN2Object;
            obj2.Tag = cBlueprint.ResourceName.Value;
            obj2.LocalizedName[BWLanguages.CurrentLanguage] = cBlueprint.ResourceName.Value;
            cBlueprint.BlueprintLocation = instance.BlueprintLocation;
            blueprintCollectionForType.Add(cBlueprint);
            GFFFile file = new GFFFile();
            file.FileHeader.FileType = BWResourceTypes.GetFileExtension(cBlueprint.Resource.ResourceType);
            cBlueprint.SaveEverythingIntoGFFStruct(file.TopLevelStruct, true);
            using (Stream stream = cBlueprint.Resource.GetStream(true))
                {
                file.Save(stream);
                cBlueprint.Resource.Release();
                }
            return cBlueprint;
        }
        private void Validate(NWN2TriggerBlueprint trigger)
        {
            // Custom validation of only blueprints here.


            // Validation of all NWN2TriggerTemplates (in areas, blueprints).
            Validate((NWN2TriggerTemplate)trigger, trigger.ResourceName.ToString());
        }