예제 #1
0
        /// <summary>
        /// Raises an event indicating that a game object has been added to an area.
        /// </summary>
        protected void InstanceInsertedIntoCollection(OEICollectionWithEvents cList, int index, object value)
        {
            INWN2Instance ins  = (INWN2Instance)value;
            NWN2GameArea  area = (NWN2GameArea)cList.Tag;

            OnInstanceAdded(cList, new InstanceEventArgs(ins, area));
        }
예제 #2
0
 /// <summary>
 /// Checks whether a given instance
 /// appears to have been created by Narrative Threads.
 /// </summary>
 /// <param name="instance">The instance to check.</param>
 /// <returns>True if the instance appears to have
 /// been created by Narrative Threads; false otherwise.</returns>
 public bool CreatedByNarrativeThreads(INWN2Instance instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("instance");
     }
     return(CreatedByNarrativeThreads(Nwn2ScriptSlot.GetNwn2Type(instance.ObjectType), instance.Template.ResRef.Value));
 }
예제 #3
0
        /// <summary>
        /// Saves the currently selected instance in the Area viewer to a
        /// user-labeled file.
        /// @note Check that instance is valid before call.
        /// </summary>
        /// <param name="iinstance"></param>
        /// <param name="repo"></param>
        internal static void SaveInstanceToFile(INWN2Instance iinstance, DirectoryResourceRepository repo = null)
        {
            INWN2Blueprint iblueprint = CreateBlueprint(iinstance, repo);

            if (iblueprint != null)
            {
                SaveBlueprintToFile(iblueprint, repo);
            }
        }
예제 #4
0
        public InstanceBehaviour CreateInstanceBehaviour(INWN2Instance instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            return(CreateInstanceBehaviour(instance, instance.Area));
        }
예제 #5
0
        public ObjectBlock GetBlock(Nwn2Address address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            if (session.GetModule() == null)
            {
                throw new InvalidOperationException("No module is open.");
            }

            if (address.TargetType == Nwn2Type.Module)
            {
                return(blocks.CreateModuleBlock());
            }

            else if (address.TargetType == Nwn2Type.Area)
            {
                NWN2GameArea area = session.GetArea(address.AreaTag);

                if (area == null)
                {
                    throw new ArgumentException("No such area in the current module.", "area");
                }
                else
                {
                    return(blocks.CreateAreaBlock(area));
                }
            }

            else
            {
                NWN2ObjectType type = Nwn2ScriptSlot.GetObjectType(address.TargetType).Value;

                INWN2Blueprint blueprint = session.GetBlueprint(address.InstanceTag, type);
                if (blueprint != null)
                {
                    return(blocks.CreateInstanceBlockFromBlueprint(blueprint));
                }

                foreach (NWN2AreaViewer viewer in NWN2Toolset.NWN2ToolsetMainForm.App.GetAllAreaViewers())
                {
                    NWN2InstanceCollection instances = session.GetObjectsByAddressInArea(address, viewer.Area.Tag);

                    if (instances.Count > 0)
                    {
                        INWN2Instance instance = instances[0];
                        return(blocks.CreateInstanceBlock(instance));
                    }
                }

                return(null);
            }
        }
예제 #6
0
        public ObjectBlock CreateInstanceBlock(INWN2Instance instance, NWN2GameArea area)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            InstanceBehaviour behaviour = CreateInstanceBehaviour(instance, area);

            ObjectBlock block = CreateInstanceBlock(behaviour);

            return(block);
        }
예제 #7
0
        public InstanceBehaviour CreateInstanceBehaviour(INWN2Instance instance, NWN2GameArea area)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            string tag = ((INWN2Object)instance).Tag;

            string displayName = GetDisplayName(instance);

            if (displayName == String.Empty)
            {
                displayName = tag;
            }

            string areaTag;

            if (area != null)
            {
                areaTag = area.Tag;
            }
            else if (instance.Area != null)
            {
                areaTag = instance.Area.Tag;
            }
            else
            {
                areaTag = String.Empty;
            }

            string resRef = instance.Template.ResRef.Value;

            string icon;

            if (instance is NWN2ItemInstance)
            {
                icon = ((NWN2ItemInstance)instance).Icon.ToString();
            }
            else
            {
                icon = String.Empty;
            }

            return(new InstanceBehaviour(tag, displayName, instance.ObjectType, areaTag, resRef, icon));
        }
예제 #8
0
        /// <summary>
        /// Creates an instance of a blueprint and adds it to the area.
        /// </summary>
        /// <param name="blueprint">The blueprint to create the game
        /// object from.</param>
        /// <param name="tag">The tag to give the newly-created object.
        /// Pass null to use the default tag.</param>
        /// <returns>The newly-created game object.</returns>
        public override INWN2Instance AddGameObject(INWN2Blueprint blueprint, string tag)
        {
            if (blueprint == null)
            {
                throw new ArgumentNullException("blueprint", "Need a blueprint to create object from.");
            }

            INWN2Instance instance = NWN2GlobalBlueprintManager.CreateInstanceFromBlueprint(blueprint);

            if (tag != null)
            {
                ((INWN2Object)instance).Tag = tag;
            }

            nwn2Area.AddInstance(instance);

            return(instance);
        }
예제 #9
0
        /// <summary>
        /// Creates an instance of a blueprint and adds it to the area.
        /// </summary>
        /// <param name="blueprint">The blueprint to create the game
        /// object from.</param>
        /// <param name="tag">The tag to give the newly-created object.
        /// Pass null to use the default tag.</param>
        /// <param name="position">The position within the area to place
        /// the object.</param>
        /// <returns>The newly-created game object.</returns>
        public override INWN2Instance AddGameObject(INWN2Blueprint blueprint, string tag, Vector3?position)
        {
            INWN2Instance instance = AddGameObject(blueprint, tag);

            if (position.HasValue)
            {
                INWN2SituatedInstance situated = instance as INWN2SituatedInstance;
                if (situated == null)
                {
                    throw new ArgumentException("Instances of the given blueprint have " +
                                                "no Position field - their position cannot be set.", "blueprint");
                }
                else
                {
                    situated.Position = position.Value;
                }
            }

            return(instance);
        }
예제 #10
0
        /// <summary>
        /// Gets an object in this area with a given ObjectID.
        /// </summary>
        /// <param name="type">The type of the object.</param>
        /// <param name="guid">The unique ID of the object.</param>
        /// <returns>The object matching the given description,
        /// or null if none was found.</returns>
        /// <remarks>This method will throw an InvalidOperationException if
        /// the area is not open.</remarks>
        public override INWN2Instance GetObject(NWN2ObjectType type, Guid guid)
        {
            bool loaded = nwn2Area.Loaded;

            if (!loaded)
            {
                throw new InvalidOperationException("Area must be open in the toolset " +
                                                    "before the method can run.");
            }

            NWN2InstanceCollection all    = nwn2Area.AllInstances[(int)type];
            INWN2Instance          unique = null;

            foreach (INWN2Instance instance in all)
            {
                if (instance.ObjectID == guid)
                {
                    unique = instance;
                    break;
                }
            }

            return(unique);
        }
예제 #11
0
        /// <summary>
        /// Raises an event indicating that a game object has been removed from an area.
        /// </summary>
        protected void InstanceRemovedFromCollection(OEICollectionWithEvents cList, int index, object value)
        {
            INWN2Instance ins = (INWN2Instance)value;

            try {
                foreach (NWN2GameArea a in NWN2Toolset.NWN2ToolsetMainForm.App.Module.Areas.Values)
                {
                    foreach (NWN2InstanceCollection collection in a.AllInstances)
                    {
                        if (collection == cList)
                        {
                            OnInstanceRemoved(cList, new InstanceEventArgs(ins, a));
                            return;
                        }
                    }
                }
            }
            catch (Exception) {}

            // Always null when the instance has been removed:
            NWN2GameArea area = (NWN2GameArea)cList.Tag;

            OnInstanceRemoved(cList, new InstanceEventArgs(ins, area));
        }
예제 #12
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
        }
예제 #13
0
        public void UpdateBlockWithNewTag(NWN2PropertyValueChangedEventArgs e)
        {
            try {
                if (tracking.Contains(e.PropertyName) && e.NewValue != e.OldValue)
                {
                    foreach (object o in e.ChangedObjects)
                    {
                        if (o is INWN2Instance)
                        {
                            INWN2Instance     instance  = (INWN2Instance)o;
                            InstanceBehaviour behaviour = blocks.CreateInstanceBehaviour(instance);

                            string bag = String.Format(Nwn2MoveableProvider.InstanceBagNamingFormat, instance.ObjectType);

                            if (window.BlockBox.HasBag(bag))
                            {
                                UIElementCollection existingBlocks = window.BlockBox.GetMoveables(bag);

                                // If it's the tag that's changed, use the old tag to search, otherwise use the current one:
                                string tag;
                                if (e.PropertyName == "Tag")
                                {
                                    tag = e.OldValue as string;
                                }
                                else
                                {
                                    tag = ((INWN2Object)instance).Tag;
                                }

                                bool updated = false;

                                foreach (UIElement u in existingBlocks)
                                {
                                    ObjectBlock existing = u as ObjectBlock;
                                    if (existing == null)
                                    {
                                        continue;
                                    }
                                    InstanceBehaviour existingBehaviour = existing.Behaviour as InstanceBehaviour;
                                    if (existingBehaviour == null)
                                    {
                                        continue;
                                    }

                                    // If you find an instance of the same type, resref and tag, replace its behaviour to update it:
                                    if (existingBehaviour.ResRef == behaviour.ResRef && existingBehaviour.Nwn2Type == behaviour.Nwn2Type && existingBehaviour.Tag == tag)
                                    {
                                        existing.Behaviour = behaviour;
                                        updated            = true;
                                        break;
                                    }
                                }

                                if (!updated)
                                {
                                    ObjectBlock block = blocks.CreateInstanceBlock(behaviour);
                                    window.BlockBox.AddMoveable(bag, block, false);
                                }
                            }


                            if (e.PropertyName == "Tag")
                            {
                                UpdateScriptsFollowingTagChange(instance, (string)e.OldValue, (string)e.NewValue, true);
                            }
                        }

                        else if (o is NWN2GameArea)
                        {
                            NWN2GameArea area = (NWN2GameArea)o;

                            // Refuse changes to tags or areas unless they are to match the resource name:
                            if (e.PropertyName == "Tag" && ((string)e.NewValue) != area.Name)
                            {
                                area.Tag = area.Name;
                                return;
                            }
                            else if (e.PropertyName == "Display Name" && (Nwn2Strings.GetStringFromOEIString((OEIShared.Utils.OEIExoLocString)e.NewValue) != area.Name))
                            {
                                area.DisplayName = Nwn2Strings.GetOEIStringFromString(area.Name);
                                return;
                            }

                            AreaBehaviour behaviour = blocks.CreateAreaBehaviour(area);

                            if (window.BlockBox.HasBag(Nwn2MoveableProvider.AreasBagName))
                            {
                                UIElementCollection existingBlocks = window.BlockBox.GetMoveables(Nwn2MoveableProvider.AreasBagName);

                                string tag;
                                if (e.PropertyName == "Tag")
                                {
                                    tag = e.OldValue as string;
                                }
                                else
                                {
                                    tag = area.Tag;
                                }

                                bool updated = false;

                                foreach (UIElement u in existingBlocks)
                                {
                                    ObjectBlock existing = u as ObjectBlock;
                                    if (existing == null)
                                    {
                                        continue;
                                    }
                                    AreaBehaviour existingBehaviour = existing.Behaviour as AreaBehaviour;
                                    if (existingBehaviour == null)
                                    {
                                        continue;
                                    }

                                    // If you find an area with the same tag, replace its behaviour to update it:
                                    if (existingBehaviour.Tag == tag)
                                    {
                                        existing.Behaviour = behaviour;
                                        updated            = true;
                                        break;
                                    }
                                }

                                if (!updated)
                                {
                                    ObjectBlock block = blocks.CreateAreaBlock(behaviour);
                                    window.BlockBox.AddMoveable(Nwn2MoveableProvider.AreasBagName, block, false);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception x) {
                MessageBox.Show("Something went wrong when updating a block.\n\n" + x);
            }
        }
예제 #14
0
 /// <summary>
 /// Constructs a new <see cref="Sussex.Flip.Games.NeverwinterNightsTwo.Utils.InstanceEventArgs"/> instance.
 /// </summary>
 /// <param name="instance">The instance relating to this event.</param>
 /// <param name="area">The area that owns (or owned) the instance.</param>
 public InstanceEventArgs(INWN2Instance instance, NWN2GameArea area)
 {
     this.instance = instance;
     this.area     = area;
 }
예제 #15
0
        internal static void SortStore()
        {
            // first check areaviewer for a selected Instance ->
            NWN2AreaViewer         areaviewer;
            NWN2InstanceCollection collection;

            if ((areaviewer = NWN2ToolsetMainForm.App.GetActiveViewer() as NWN2AreaViewer) != null &&
                (collection = areaviewer.SelectedInstances) != null && collection.Count == 1 &&
                collection[0] is NWN2StoreTemplate)
            {
                var store = collection[0] as NWN2StoreInstance;
                var its   = new NWN2InstanceStoreItemCollection();

                // add items in the store of all types into 'its'
                int count = store.ArmorItems.Count;
                for (int i = 0; i != count; ++i)
                {
                    its.Add(store.ArmorItems[i]);
                }
                store.ArmorItems.Clear();

                count = store.WeaponItems.Count;
                for (int i = 0; i != count; ++i)
                {
                    its.Add(store.WeaponItems[i]);
                }
                store.WeaponItems.Clear();

                count = store.PotionItems.Count;
                for (int i = 0; i != count; ++i)
                {
                    its.Add(store.PotionItems[i]);
                }
                store.PotionItems.Clear();

                count = store.RingItems.Count;
                for (int i = 0; i != count; ++i)
                {
                    its.Add(store.RingItems[i]);
                }
                store.RingItems.Clear();

                count = store.MiscellaneousItems.Count;
                for (int i = 0; i != count; ++i)
                {
                    its.Add(store.MiscellaneousItems[i]);
                }
                store.MiscellaneousItems.Clear();

                // sort the items that are in 'its' to their store-panels per their BaseItems.2da "StorePanel" val
                TwoDAReference TwoDaRef;
                int            id;

                for (int i = 0; i != its.Count; ++i)
                {
                    id       = its[i].Item.BaseItem.Row;
                    TwoDaRef = new TwoDAReference("baseitems", "StorePanel", false, id);
                    // NOTE: If row is invalid a blank string is returned.

                    switch (TwoDaRef.ToString())
                    {
//						case "0":
                    default:  store.ArmorItems.Add(its[i]); break;

                    case "1": store.WeaponItems.Add(its[i]); break;

                    case "2": store.PotionItems.Add(its[i]); break;

                    case "3": store.RingItems.Add(its[i]); break;

                    case "4": store.MiscellaneousItems.Add(its[i]); break;
                    }
                }

                var a = new INWN2Instance[] { store };
                NWN2ToolsetMainForm.App.AreaContents.SelectInstances(a);                 // update store panels.
                // NOTE: Floating panels won't be updated.
            }
            else             // second check blueprint tree for a selected Blueprint ->
            {
                object[] selection = NWN2ToolsetMainForm.App.BlueprintView.Selection;
                if (selection != null && selection.Length == 1 &&
                    (selection[0] as INWN2Template).ObjectType == NWN2ObjectType.Store)
                {
                    var store = selection[0] as NWN2StoreBlueprint;
                    var its   = new NWN2BlueprintStoreItemCollection();

                    // add items in the store of all types into 'its'
                    int count = store.ArmorItems.Count;
                    for (int i = 0; i != count; ++i)
                    {
                        its.Add(store.ArmorItems[i]);
                    }
                    store.ArmorItems.Clear();

                    count = store.WeaponItems.Count;
                    for (int i = 0; i != count; ++i)
                    {
                        its.Add(store.WeaponItems[i]);
                    }
                    store.WeaponItems.Clear();

                    count = store.PotionItems.Count;
                    for (int i = 0; i != count; ++i)
                    {
                        its.Add(store.PotionItems[i]);
                    }
                    store.PotionItems.Clear();

                    count = store.RingItems.Count;
                    for (int i = 0; i != count; ++i)
                    {
                        its.Add(store.RingItems[i]);
                    }
                    store.RingItems.Clear();

                    count = store.MiscellaneousItems.Count;
                    for (int i = 0; i != count; ++i)
                    {
                        its.Add(store.MiscellaneousItems[i]);
                    }
                    store.MiscellaneousItems.Clear();

                    // sort the items that are in 'its' to their store-panels per their BaseItems.2da "StorePanel" val
                    TwoDAReference TwoDaRef;
                    int            id;

                    for (int i = 0; i != its.Count; ++i)
                    {
                        var it = new NWN2ItemInstance(its[i].Item);
                        id       = it.BaseItem.Row;
                        TwoDaRef = new TwoDAReference("baseitems", "StorePanel", false, id);
                        // NOTE: If row is invalid a blank string is returned.

                        switch (TwoDaRef.ToString())
                        {
//							case "0":
                        default:  store.ArmorItems.Add(its[i]); break;

                        case "1": store.WeaponItems.Add(its[i]); break;

                        case "2": store.PotionItems.Add(its[i]); break;

                        case "3": store.RingItems.Add(its[i]); break;

                        case "4": store.MiscellaneousItems.Add(its[i]); break;
                        }
                    }

                    string label = (selection[0] as INWN2Object).LocalizedName[BWLanguages.CurrentLanguage];
                    NWN2ToolsetMainForm.App.CreateNewPropertyPanel(selection, NWN2ToolsetMainForm.App.Module, false, label);                     // update store panels.
                    // NOTE: Floating panels won't be updated.
                }
            }
        }
예제 #16
0
 /// <summary>
 /// Creates an actor from an instance
 /// </summary>
 /// <param name="actor">The instance that the actor is created from</param>
 /// <param name="type">The type of the instance</param>
 public Actor(NWN2Toolset.NWN2.Data.Instances.INWN2Instance actor, EnumTypes.actorType type)
 {
     instance = actor;
     this.type = type;
     boolInstance = true;
 }