Example #1
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;
        }
Example #2
0
        /// <summary>
        /// Creates a blueprint and its resource for a given instance.
        /// Cf. ElectronPanel_.DuplicateBlueprint()
        /// </summary>
        /// <param name="iinstance"></param>
        /// <param name="irepo"></param>
        /// <returns></returns>
        static INWN2Blueprint CreateBlueprint(INWN2Instance iinstance, IResourceRepository irepo)
        {
            INWN2Blueprint iblueprint = new NWN2CreatureBlueprint();

            // NWN2Toolset.NWN2.Data.Instances.NWN2CreatureInstance.CreateBlueprintFromInstance()

            iblueprint.CopyFromTemplate(iinstance as INWN2Template);             // does not copy inventory or equipped!

            // workaround toolset glitch re. template resref string ->
            // Loading a module with an instance that doesn't have a template
            // resref string isn't the same as deleting that string. And vice
            // versa: loading a module with an instance that has an invalid
            // template resref string isn't the same as filling a blank string
            // with an invalid resref string.
            //
            // So basically go through things step by step to ensure that all
            // this resource crap exits the poop chute w/out constipation.

            OEIResRef resref;

            if (iinstance.Template == null ||
                iinstance.Template.ResRef == null ||
                iinstance.Template.ResRef.IsEmpty())
            {
                string tag = iinstance.Name.ToLower();                 // create a resref based on tag
                if (String.IsNullOrEmpty(tag))
                {
                    tag = "creature";
                }

                resref = new OEIResRef(tag);
            }
            else
            {
                resref = CommonUtils.SerializationClone(iinstance.Template.ResRef) as OEIResRef;
            }

            iblueprint.TemplateResRef = resref;


            if (iinstance.Template != null)
            {
                iblueprint.Resource = CommonUtils.SerializationClone(iinstance.Template) as IResourceEntry;
            }

            if (iblueprint.Resource == null)
            {
                iblueprint.Resource = new MissingResourceEntry(resref);
            }

            if (iblueprint.Resource.ResRef == null ||
                iblueprint.Resource.ResRef.IsEmpty())
            {
                iblueprint.Resource.ResRef = resref;
            }

            iblueprint.Resource.ResourceType = 2027;

            iblueprint.Comment = iinstance.Comment;

// copy equipped ->
            (iblueprint as NWN2CreatureTemplate).EquippedItems = new NWN2EquipmentSlotCollection();
            NWN2InventoryItem equipped;

            for (int i = 0; i != 18; ++i)
            {
                if ((equipped = (iinstance as NWN2CreatureTemplate).EquippedItems[i].Item) != null && equipped.ValidItem)
                {
                    (iblueprint as NWN2CreatureTemplate).EquippedItems[i].Item = (new NWN2BlueprintInventoryItem(equipped as NWN2InstanceInventoryItem)) as NWN2InventoryItem;
                }
            }

// copy inventory ->
            (iblueprint as NWN2CreatureBlueprint).Inventory = new NWN2BlueprintInventoryItemCollection();
            foreach (NWN2InstanceInventoryItem item in (iinstance as NWN2CreatureInstance).Inventory)
            {
                (iblueprint as NWN2CreatureBlueprint).Inventory.Add(new NWN2BlueprintInventoryItem(item));
            }

            return(iblueprint);            // a blueprint with a resource for an Instance
        }
        private void Validate(NWN2CreatureBlueprint creature)
        {
            // Custom validation of only blueprints here.


            // Validation of all NWN2CreatureTemplates (in areas, blueprints).
            Validate((NWN2CreatureTemplate)creature, creature.ResourceName.ToString());
        }