Base DFU feature request - buying items won't automatically equip them

Talk about the mods or features you'd like to see in Daggerfall Unity. Give mod creators some ideas!
User avatar
Magicono43
Posts: 652
Joined: Tue Nov 06, 2018 7:06 am

Re: Base DFU feature request - buying items won't automatically equip them

Post by Magicono43 »

I would like that solution as well honestly (that being the cached equipment). But as you said, that's if the person working on this option would feel like doing it this way. I get your reasoning and are right that it would make it more annoying for somebody trying to actually try on cloths.

User avatar
mikeprichard
Posts: 1037
Joined: Sun Feb 19, 2017 6:49 pm

Re: Base DFU feature request - buying items won't automatically equip them

Post by mikeprichard »

I also like Interkarma's idea, assuming that's something Hazelnut or another dev would agree to take on. I'm sure it's not exactly a high priority with continued bugfixes in the works, but it would be another cool little QoL feature!

Daggerfalling
Posts: 2
Joined: Tue Feb 02, 2021 2:36 pm

Re: Base DFU feature request - buying items won't automatically equip them

Post by Daggerfalling »

What if you add an alternative: press Shift+Left click to just add an item to your inventory (Or vice-versa, default click just buys and shift+click equips it).

l3lessed
Posts: 869
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Base DFU feature request - buying items won't automatically equip them

Post by l3lessed »

I think the core problem here is that your equipped items get all messed up by interacting with shops. May I suggest an alternative that's admittedly a bit more time consuming to implement.
  • Cache player equip table on shop UI open.
  • Clear button will also restore cached equip table in addition to returning unpurchased items to shelf.
  • Exit will keep player equip table
.
I'm already doing this in my outfit manager. The way that mod works is by dumping all the equipped items unique UID into a list, which is then dumped into another list for the differing outfit lists. At that point, the list are then manipulated to manage the differing outfits how the player wants.

I could take a crack at this having some code basis for it already. I wanted to get better on UI use anyways, as I feel we need an MCM style mod manager for the in game menu system, and I need to get better at UI use before I try to make it.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Hazelnut
Posts: 2711
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Base DFU feature request - buying items won't automatically equip them

Post by Hazelnut »

How do you handle item stacks and effects triggered by equipping?

If it wasn't for tricky little gotchas like that I'd have done this a while back. Not saying I'm stumped or anything, but not had time to work though it as there is always some more critical thing to get done. I have ideas of having a temporary equip table, but nothing concrete just yet.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

l3lessed
Posts: 869
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Base DFU feature request - buying items won't automatically equip them

Post by l3lessed »

Yeah, I hit that same bump when first creating this mod. I thought the effects would have some auto update routine only to find out it didn't and magic effects where all fubared, not to mention figuring out how UID's work in relation to item objects. How I solved it, you ask? Here is my save and load methods from my mod.

Heres the save method. Pretty easy method. Just checks to see if the slot/list place has already been saved and if so, updates the outfit. If not, adds it as a new item to the list for use. There is another method that asks for a name and uses a separate dictionary to track the string name/value for the list. This is probably of no use for what you're doing, since you don't need to save more than a single list. Where as, I am trying to let players create as long of an outfit list as they want/need.

Code: Select all

        //saves the currently selected outfit. It grabs the seralized equip table and the
        //current outfitName (Which was just assigned by the player), and stores each into
        //their dictionaries using the same public index integer to ensure matches.
        void saveCurrentOutfit()
        {
            //looks to see if outfit already exists using dict key.
            //if it finds it, updates that dictionary value.
            //if not, adds it to the list.
            if (outfitDictSerialized.ContainsKey(index))
            {
                outfitDictSerialized[index] = currentEquippedSerialized;
                outfitDictName[index] = outfitName;
            }
            else
            {
                outfitDictSerialized.Add(index, currentEquippedSerialized);
                outfitDictName.Add(index, outfitName);
            }

            outfitName = "Wearing\n" + outfitDictName[index];
            selectedIndex = index;

            //Debugging message.
            Debug.Log("Outfit List Size:" + outfitDictSerialized.Count);
        }
Last edited by l3lessed on Thu Feb 04, 2021 9:31 pm, edited 2 times in total.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 869
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Base DFU feature request - buying items won't automatically equip them

Post by l3lessed »

Here is the load method. I dropped it into its own post, so it can be easier to read and explain.

Code: Select all

//beginning of outfit load routine. Will use saved outfit lists to equipped outfits to player.
        void loadCurrentOutfit()
        {
            //Debugging message.
            Debug.Log("Outfit List Size:" + outfitDictSerialized.Count);
            //creates a local empty list for the dictionary to output too.
            ulong[] outfitListulong;
            //creates blank daggerfall item instance. Used for catching last equipped item below.
            DaggerfallUnityItem lastEquippedItem = new DaggerfallUnityItem();
            //looks for selected dictionary value: if it finds it, populates outfitList for if then.
            //if can't find dictionary key, it outputs error.
            if (outfitDictSerialized.TryGetValue(index, out outfitListulong))
            {
                //Debugging message.
                Debug.Log("Outfit List Size:" + outfitDictSerialized.Count);
                //for loop to unequipped all armor slots and update armoor values.
                foreach (DaggerfallUnityItem item in PlayerEntity.ItemEquipTable.EquipTable)
                {
                    if (item != null)
                    {
                        PlayerEntity.ItemEquipTable.UnequipItem(item);
                        PlayerEntity.UpdateEquippedArmorValues(item, false);

                        //checks if item being unequipped is enchanted, if so, run PlayerEffectManager to properly remove any item enchanments.
                        GameManager.Instance.PlayerEffectManager.DoItemEnchantmentPayloads(MagicAndEffects.EnchantmentPayloadFlags.Unequipped, item, GameManager.Instance.PlayerEntity.Items);
                    }
                }

                //uses the serialized item list and the players current inventory to equip saved outfit.
                PlayerEntity.ItemEquipTable.DeserializeEquipTable(outfitListulong, PlayerEntity.Items);
                //for loop to update all armor values for items deserialized and equipped above.
                foreach (DaggerfallUnityItem item in PlayerEntity.ItemEquipTable.EquipTable)
                {
                    if (item != null)
                    {
                        PlayerEntity.UpdateEquippedArmorValues(item, true);
                        lastEquippedItem = item;

                        //checks if item being equipped is enchanted, if so, run PlayerEffectManager to properly activate any item enchanments.
                        if (item.IsEnchanted)
                        {
                            GameManager.Instance.PlayerEffectManager.DoItemEnchantmentPayloads(MagicAndEffects.EnchantmentPayloadFlags.Equipped, item, GameManager.Instance.PlayerEntity.Items);
                        }
                    }
                }
                //plays sound of last equipped item. Tells player the outfit bundled loaded through audio.
                DaggerfallUI.Instance.PlayOneShot(lastEquippedItem.GetEquipSound());
                DaggerfallUI.Instance.DaggerfallHUD.Update();
            }
            else
            {
                //error messsage
                Debug.Log("Coudn't Locate Outfit: Index value not found.");
                DisplayMessage("Couldn't find outfit bundle.");
            }
            //refreshes inventory window, which includes the paper doll.
            //Put outside if then to ensure UI always updates, even if bug happens.
            DaggerfallUI.Instance.InventoryWindow.Refresh();
            DaggerfallUI.Instance.DaggerfallHUD.ActiveSpells.UpdateIcons();
        }
It's using for loops to parse through UID item tables, then dump the individual item into an empty item object, then the item is checked for enchantments, and finally the enchantments are removed/added based on if the item is being equipped or unequipped. The hard part was figuring out how to ensure UID's are maintained and reconnect when the game is loaded or if the player drops/changes the item in their inventory.
  • Check to see if the list contains an outfit at all, and if it doesn't tell player with message and exit. If it does, dump the outfit UID list into an empty list object for handling, unequipping, and equipping process of outfit.
  • Now that we confirmed there is an outfit to use and dumped it into a empty list object, it uses a loop to go through each item in the players equip table and unequips each item. The last thing it does is check to see if the item had an enchantment. If it does, it also removes the enchantment affects from the player to ensure player enchantments update properly. At this point/frame, the player is naked and has no enchantments (The armor value has not been updated yet, as we will do that when we equip the new armor/at the end to save a few cpu cycles).
  • Now that it confirmed there was an outfit, removed all items, and removed all enchantments, now we can reverse the process to equip the outfit and update the values. Grab the players item table of UID's and then use the cross-reference/deserialize object to check if the UIDs are still in the players inventory and relink them to the item in the inventory so they can be used; this restores the equip table but does not equip anything by itself. This ensures any lost items are relinked and do not cause null errors and bugs when you do call them from the equip table for use.
  • Use another for loop to check if there is an item in the list to be equipped, and if so, equip it and update the players armor value now. Lastly, check if item is enchanted and add the enchantment to the player.
  • The player has now been stripped of everything, including enchantments, then equipped with the new UID list outfit and enchantments updated/added to the player. Add a small sound feedback output to let player know outfit is equipped. Finally, do a quick hud update to ensure enchantment effect icons update.
Hope this helps you slam this out real quick. If you are too busy, I can put this on spare time list and see if I can smash it out in next week or so and submit to the main branch.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
GeeTee
Posts: 4
Joined: Wed Jan 27, 2021 10:32 am
Location: Australia

Re: Base DFU feature request - buying items won't automatically equip them

Post by GeeTee »

Hi all, I realise this deviates slightly from the main thrust of the topic, but this does seem relevant nonetheless.

Earlier:
Daggerfalling wrote: Thu Feb 04, 2021 12:39 pm What if you add an alternative: press Shift+Left click to just add an item to your inventory (Or vice-versa, default click just buys and shift+click equips it).

In fact, page 53 of (this) DF manual says you can right-click an item to perform the complementary action in Equip and Remove modes. I'm not sure if this is actually implemented in classic, but it does feel like a pretty good QOL feature to consider, especially since, y'know, it's in the manual and all.

From there, it's not much of a stretch to add RMB-to-"try on" in Buy mode as Daggerfalling suggests.

Image

User avatar
Hazelnut
Posts: 2711
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Base DFU feature request - buying items won't automatically equip them

Post by Hazelnut »

That's really interesting, well spotted. I dug out my original DF manual hardcopy and can confirm that's what it says. I checked my dosbox classic install and right click does the same as left click as far as I can see, so it looks like another feature that was unimplemented. Generally I've tested the classic game to see what to replicate, hence not being aware of this until now.

Implementing this behaviour would be very easy to do and I am happy to do this.. if extended to the purchase behaviour (like equip was selected) it would allow players to get items without equipping them.

To do this it will require moving the functionality currently on right click that's to cycle visual variants (mainly for clothes) which is a DFU QoL addition I believe. I would move this to middle mouse click (press scroll wheel) so that right click would work as described in the DF manual.

Any opinions on this? Especially from Interkarma and the other devs.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
pango
Posts: 2924
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Base DFU feature request - buying items won't automatically equip them

Post by pango »

I'm fine with this change to inventory.
So, just to be clear, it will also apply to shopping, left click = equip, right click = just add to inventory?
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

Post Reply