Need a plugin for Multiple Accessories

Discussion in 'JS Plugin Requests' started by Animebryan, Feb 17, 2019.

  1. Animebryan

    Animebryan Feels like I'm slowly dying! Veteran

    Messages:
    340
    Likes Received:
    157
    Location:
    Marysville, CA
    First Language:
    English
    Primarily Uses:
    RMMV
    I need a plugin that allows multiple accessories instead of just 1 by default. Not only does it need to allow multiple accessories but to be able to restrict multiple copies of the same accessory. The multiple accessory slots need to be considered as the same equipment type so that any accessory can be equipped into any slot. It also needs to allow 'Cursed' accessories that lock only their own slot & not all of them. If anyone can point me to a plugin that does this already or can provide a new one I would appreciate it.

    Also, don't suggest Yanfly's Equip Core, because its flawed hence the reason I'm asking for a new one.
     
    #1
  2. Levolpehh

    Levolpehh Veteran Veteran

    Messages:
    87
    Likes Received:
    66
    First Language:
    English
    Primarily Uses:
    RMMV
    Why not just make 2 different equipment slots labelled Accessory 1 and 2?
     
    #2
  3. Magnus0808

    Magnus0808 Software Developer Veteran

    Messages:
    116
    Likes Received:
    109
    First Language:
    Danish
    Primarily Uses:
    RMMV
    Made this for you. I even made it compatible with Yanfly's Equip Core in case someone wants to use it with that. However, it does not require it at all. It might not be the most polished plugin so if you encounter any bugs or flaws feel free to shoot me a message and I will fix it :)
    You can set an item to be cursed by adding the note tag <cursed:true> to the item.

    Code:
    //=============================================================================
    // Multiple Accessories
    // MRP_MultipleAccessories.js
    // By Magnus0808 || Magnus Rubin Peterson
    // Version 1.0
    //=============================================================================
    
    /*:
     * @plugindesc Multiple Accessories including cursed items
     * @author Magnus0808
     *
     * @help If you use Yanfly Equip Core then put this after that one.
     * You can also make it so you cannot take an item of on normal means by
     * setting it as cursed. You do this by adding the note tag <cursed:true> to
     * the item.
     *
     * @param Default Equip Slots
     * @type Number[]
     * @desc This is the list of the default equip slots.
     * @default ["1","2","3","4","5"]
     *
     * @param Equip Multiple Of The Same Item
     * @type Boolean
     * @desc If false then you can only equip one of each item.
     * @default false
     *
     * @param Optimize With Cursed Items
     * @type Boolean
     * @desc If true then curesed items will also be used when optimizing.
     * @default false
     *
     * @param Ignore These Equipment Type When Optimizing
     * @type Number[]
     * @desc This is a list of Equipment Types that are not used when optimizing
     * @default ["5"]
     
     */
     
     
    (function(){
       
        MultipleAccessories = {};
        MultipleAccessories.Parameters = PluginManager.parameters('MRP_MultipleAccessories');
        MultipleAccessories.equipSlots = JSON.parse(MultipleAccessories.Parameters['Default Equip Slots']);
        for(var i = 0; i < MultipleAccessories.equipSlots.length; i++){
            MultipleAccessories.equipSlots[i] = Number(MultipleAccessories.equipSlots[i]);
        }
        MultipleAccessories.optCursed = (String(MultipleAccessories.Parameters['Optimize With Cursed Items']) == 'true');
        MultipleAccessories.mulitiItems = (String(MultipleAccessories.Parameters['Equip Multiple Of The Same Item']) == 'true');
        MultipleAccessories.ignoreItems = JSON.parse(MultipleAccessories.Parameters['Ignore These Equipment Type When Optimizing']);
        for(var i = 0; i < MultipleAccessories.equipSlots.length; i++){
            MultipleAccessories.ignoreItems[i] = Number(MultipleAccessories.ignoreItems[i]);
        }
       
        // Changes to DataManager
        // Compatibility with yanfly equipcore
        DataManager.setDefaultEquipSlots = function(obj) {
            obj.equipSlots = MultipleAccessories.equipSlots;
        };
       
        // Changes to Game_Actor
        Game_Actor.prototype.equipSlots = function() {
            var slots;
            if(this.currentClass().equipSlots) { // Compatibility with yanfly equipcore
                slots = this.currentClass().equipSlots.slice();
            } else {
                slots = MultipleAccessories.equipSlots;
            }
            if (slots.length >= 2 && this.isDualWield()) {
                slots[1] = 1;
            }
            return slots;
        };
       
        Game_Actor.prototype.clearOptimizeEquipments = function() {
            var maxSlots = this.equipSlots().length;
            for (var i = 0; i < maxSlots; i++) {
                if(MultipleAccessories.ignoreItems.contains(this.equipSlots()[i])) continue;
                if (this.isEquipChangeOk(i)) {
                    this.changeEquip(i, null);
                }
            }
        };
       
        Game_Actor.prototype.optimizeEquipments = function() {
            var maxSlots = this.equipSlots().length;
            this.clearOptimizeEquipments();
            for (var i = 0; i < maxSlots; i++) {
                if(MultipleAccessories.ignoreItems.contains(this.equipSlots()[i])) continue;
                if (this.isEquipChangeOk(i)) {
                    this.changeEquip(i, this.bestEquipItem(i));
                }
            }
        };
       
        Game_Actor.prototype.bestEquipItem = function(slotId) {
            var etypeId = this.equipSlots()[slotId];
            var items = $gameParty.equipItems().filter(function(item) {
                return item.etypeId === etypeId && this.canEquip(item);
            }, this);
            var bestItem = null;
            var bestPerformance = -1000;
            for (var i = 0; i < items.length; i++) {
                if(!MultipleAccessories.optCursed && items[i].meta.cursed) continue;
                var performance = this.calcEquipItemPerformance(items[i]);
                if (performance > bestPerformance) {
                    bestPerformance = performance;
                    bestItem = items[i];
                }
            }
            return bestItem;
        };
       
        var MRP_MA_GA_CANEQUIP = Game_Actor.prototype.canEquip;
        Game_Actor.prototype.canEquip = function(item) {
            if(!MultipleAccessories.mulitiItems && this.isEquipped(item)) {
                return false;
            }
            return MRP_MA_GA_CANEQUIP.call(this, item);
    
        };
       
        var MRP_MA_GA_EQUIPCHANGEOK = Game_Actor.prototype.isEquipChangeOk;
        Game_Actor.prototype.isEquipChangeOk = function(slotId) {      
            var item = this.equips()[slotId];
            if(item && item.meta.cursed) return false;
           
            return MRP_MA_GA_EQUIPCHANGEOK.call(this, slotId);
        };
       
        Game_Actor.prototype.releaseUnequippableItems = function(forcing) {
            for (;;) {
                var slots = this.equipSlots();
                var equips = this.equips();
                var changed = false;
                for (var i = 0; i < equips.length; i++) {
                    var item = equips[i];
                    if (item && (!MRP_MA_GA_CANEQUIP.call(this, item) || item.etypeId !== slots[i])) {
                        if (!forcing) {
                            this.tradeItemWithParty(null, item);
                        }
                        this._equips[i].setObject(null);
                        changed = true;
                    }
                }
                if (!changed) {
                    break;
                }
            }
        };
       
        // "Changes" to Window_EquipSlot
        // This is just the default isEnabled no changes. However, yanfly EquipCore f**** it up so I have to include
        // it ín order for them to be compatible.
        Window_EquipSlot.prototype.isEnabled = function(index) {
            return this._actor ? this._actor.isEquipChangeOk(index) : false;
        };
       
    })();
     

    Attached Files:

    Last edited: Feb 19, 2019
    #3
    cedr777 and Animebryan like this.
  4. Gigadragon78

    Gigadragon78 Villager Member

    Messages:
    7
    Likes Received:
    1
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    You dont need a plugin for this...
    Just create a new entry in types,in my case hands and foots.
     
    #4
  5. Animebryan

    Animebryan Feels like I'm slowly dying! Veteran

    Messages:
    340
    Likes Received:
    157
    Location:
    Marysville, CA
    First Language:
    English
    Primarily Uses:
    RMMV
    It definitely works once I figured out setting the slot numbers, but the curse effect still locks all the accessory slots. Also, it doesn't exclude accessories from the Optimize function (which it should).

    By default, if you make additional accessory slots the editor still considers them to be separate slots. When you set up accessories, you have to set which equip slot they go to. That means that each accessory would have to go into a specific slot which means you would have to pick & choose between multiple accessories that go into the same slot. The propose of Yanfly's Equip Core & Magnus' plugin is that any additional accessory slots are all considered as the same type, allowing you to equip any accessory into any slot.
     
    #5
  6. Magnus0808

    Magnus0808 Software Developer Veteran

    Messages:
    116
    Likes Received:
    109
    First Language:
    Danish
    Primarily Uses:
    RMMV
    That sounds odd. I just tested it again and it worked just fine. What did you set the parameters to?
    Do you use any other plugins that might make it not work?
     
    #6
  7. Animebryan

    Animebryan Feels like I'm slowly dying! Veteran

    Messages:
    340
    Likes Received:
    157
    Location:
    Marysville, CA
    First Language:
    English
    Primarily Uses:
    RMMV
    You can see for yourself:
     
    #7
  8. Magnus0808

    Magnus0808 Software Developer Veteran

    Messages:
    116
    Likes Received:
    109
    First Language:
    Danish
    Primarily Uses:
    RMMV
    Hmm that really is weird. I dont have any programs to take a video on my computer so I just embedded an image showing it working.
    [​IMG]
    You could probably make a fresh project, where the only plugin you use is mine, to test it out for yourself :)

    I didn't catch that you wanted Accessories not to be included in the optimization at all. I'll add a parameter where you can choose which Equipment types not to use in the optimization. :) I'll add it when I figure out why the heck you're having issues with the plugin.

    The way I handle only to lock the slot with the cursed item is by looking directly at the item in the slot during isEquipChangeOk and returning false if it is cursed, so it really shouldn't lock anything else. You have quite a few other plugins and while it doesn't seem like they should interfere with my plugin you never know :/ If you could send me zip with the plugins I'll check them for issues.

    I have to sleep now as it is almost 4am here and I have to get up in about 4 hours. However, I will contuine working on this later today.
     
    #8
  9. Magnus0808

    Magnus0808 Software Developer Veteran

    Messages:
    116
    Likes Received:
    109
    First Language:
    Danish
    Primarily Uses:
    RMMV
    Since it turned out that the issue was not with my plugin. Just that you forgot to remove the Lock Equipment trait from your item. I have updated the plugin to include the option to not use specific Equipment types when using the optimizing function. I set the default parameter to exclude Accessories :)
    My original reply is updated with the plugin changes.
     
    #9
  10. Animebryan

    Animebryan Feels like I'm slowly dying! Veteran

    Messages:
    340
    Likes Received:
    157
    Location:
    Marysville, CA
    First Language:
    English
    Primarily Uses:
    RMMV
    The locking effect is working now but I'm having another problem, one that I was having with Yanfly's Equip Core. If I equip some accessories & choose Optimize, it strips off all my accessories! Its one thing to not equip accessories when using Optimize but to have it strip off all accessories is absurd too! Do you think you can figure what causes it?
     
    #10
  11. Magnus0808

    Magnus0808 Software Developer Veteran

    Messages:
    116
    Likes Received:
    109
    First Language:
    Danish
    Primarily Uses:
    RMMV
    Oh yeah I forgot about that! The optimize function calls clearEquipments. I have fixed it now so when optimizing it does not clear the Equipment which you have told not to be optimized :)
    I have updated the plugin in my original response
     
    #11
    Animebryan likes this.
  12. Animebryan

    Animebryan Feels like I'm slowly dying! Veteran

    Messages:
    340
    Likes Received:
    157
    Location:
    Marysville, CA
    First Language:
    English
    Primarily Uses:
    RMMV
    Thanks! It works perfectly now.
     
    #12

Share This Page