2
\$\begingroup\$

Well, the thing is that i've been using Attachable Augments (a GREAT plugin made by Yanfly, check yanfly.moe for more info) for a while, but I feel that something was not there. You can buy items and buy things, but why not buying items with already attached parts?

So i've tried to make a plugin. This works with the idea to only make one weapon of one type (for example 'sword') and then use different materials to change the stat buffs/debuffs (for example, making the 'steel' material in order to make the sword).

As far as i've gone, i managed to select random attatchments for one object and attached them to this item, and it shows correctly in the shop. The problem is that every time I exit the 'buy' menu or the shop an enter again, the 'new' object is just the older but with new attachments and added buffs, so i have one weapon with the older stats and the newer stats.

What can I do in order to make this work?

This is the pluggin code:

if (Imported.YEP_X_AttachAugments) {
    console.log("Iniciado el plugin");                                      ///< Remover en la versión final. Solo es un mensaje de consola inutil
    var MaxAttachableItemCount = 100;                                       ///< This would be the value of all attachable augments for one object. Default (100)
    var GenericAttachableItems;                                             ///< Empty Array that would change with the items of the last category
    var LastCategory = null;                                                ///< It saves the last category searched

    var paramsRA = PluginManager.parameters('YEP_X_Random_Attaches');       ///< Parameters of this plugin
    var paramsAA = PluginManager.parameters('YEP_X_AttachAugments');        ///< Parameters of Yanfly plugin
    var enabled_param = Boolean(paramsRA['Enabled'] || true);               ///< Enabled parameter
    var augmentSlotsParamW = String(paramsAA['Weapon Slots'].split(','));   ///< Weapon Slots
    var augmentSlotsParamA = String(paramsAA['Armor Slots'].split(','));    ///< Armor Slots
    var startingWeapons;
    var firstTimeOpennedShop = true;                                        ///< Says if it's the first time the shop is open or not

    /** function randomAttach(category)
     * This would generate and attach one attachable
     * item to the object 'category'
     * type.
     */
    //Slifer.Random.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
    function randomAttachFind(category){
        //this.cout("Stating search of random Attachment");
        var Attach = new Array();
        //if(Slifer.Random.isDatabaseLoaded){
        category = category.toUpperCase();
                this.LastCategory = null;
                this.GenericAttachableItems = new Array();
                this.MaxAttachableItemCount = 0;
                                                        ///< No category
                //cout($dataItems);
                var contador = 0;
                for (var i = 1; i <= $dataItems.length-4; i++) {
                    //cout("Object: " + $dataItems[i]);
                    var eval = $dataItems[i].augmentTypes;
                    cout ("Eval: " + eval[0] + " eval length: " + eval.length);
                    var pushed = false;
                    for (var l = 0; l < eval.length; l++) {
                        if(category ==  eval[l] && pushed == false){
                            pushed = true;
                            var aux = $dataItems[i];
                            //cout("Attached: " + aux);
                            this.GenericAttachableItems.push(aux);
                            //cout("Finded!");
                        }
                    }
                }

                this.MaxAttachableItemCount = GenericAttachableItems.length + 1;                    ///< Get the arrayLenght
                //this.cout("MaxAttachableItemCount: " + this.MaxAttachableItemCount);
                var randomNumber = Math.floor((Math.random() * MaxAttachableItemCount) + 1);        ///< Generate a random number
                randomNumber -= 1;                                                                  ///< This is to match the array index
                //this.cout("randomNumber: " + randomNumber);

                Attach = GenericAttachableItems[randomNumber];                                  ///< Obtaining the Attachment

        //}
        this.LastCategory = category;
        //cout("This is the selected item: ");
        //cout(Attach);
        return Attach;
    }

    function cout(message){
        console.log(message);
    }
    /** function AttachableItemCount(item_name)
     * This would count all attachable items for
     * one object.
     */

    /** function proccessingNoteTags()
     * This proccesses the notetags reffearing the plugin.
     * The useful notetags are said upper.
     */
    function proccessingNoteTags(){

    }


    /** Game_Interpreter.prototype.pluginCommand = function(command, args)
     * This would proccess the plugin commands and call the necesary
     * functions to work.
     */
    var alias_pluginCommand = Game_Interpreter.prototype.pluginCommand;     ///< Aliasing
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        alias_pluginCommand.apply(this);
        switch (command){
            case "RandomShop":
                this.makeItemList();    ///< Call Shop
                break;
        }
    };


    /**
     * goods[0] -> Item Type
     * goods[1] -> Item ID
     * goods[2] -> Item Price
     * goods[3] -> Item Concrete Price
     *
     * $dataItems[x]   -> Item at x index
     * $dataWeapons[x] -> Weapon at x index
     * $dataArmors[x]  -> Armor at x index
     */

    Window_ShopBuy.prototype.makeItemList = function() {
        this._data = [];
        this._price = [];
        var attach =  new Array();
        var first = false;
        this._shopGoods.forEach(function(goods) {
            var item = null;
            switch (goods[0]) {
            case 0:
                item = $dataItems[goods[1]];
                break;
            case 1:
                item = $dataWeapons[goods[1]];
                if(firstTimeOpennedShop == true){
                    cout(item);
                    if(startingWeapons == null){
                        startingWeapons = new Array();
                        startingWeapons.push(item); 
                        first = true;
                    }
                    if(true && startingWeapons != null){
                        startingWeapons.push(item); 
                    }
                    ///< Here we have to give random attaches!
                    console.log("Finding item augments");
                    console.log("Item slots lenght" + item.augmentSlots.length)
                    ItemManager.removeAllAugments(item);
                    for(var slotId = 0; slotId < item.augmentSlots.length; slotId++){
                        attach.push(randomAttachFind(item.augmentSlots[slotId]));
                        console.log("Slot id: " + slotId);
                        console.log("Slot name: " + item.augmentSlots[slotId]);
                        console.log(attach[slotId]);
                    }

                }else if (firstTimeOpennedShop != true){

                }
                break;
            case 2:
                item = $dataArmors[goods[1]];
                break;
            }
            if (item) {
                this._data.push(item);
                this._price.push(goods[2] === 0 ? item.price : goods[3]);
                ItemManager.installAugments(item,attach);
                attach = new Array();
            }
        }, this);
        this.firstTimeOpennedShop = false;

    };

There's some code that doesn't do anything. Don't care about it, that will be future code. (It's my first plugin and my first time with javascript, so I don`t know if there's a better way to do it or what i'm doing wrong)

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Well, I've solved some of the problems!

Here is the actual code:

Window_ShopBuy.prototype.makeItemList = function() {
            if(this.firstTimeOpennedShop == undefined || this.firstTimeOpennedShop == null)
                this.firstTimeOpennedShop = true;
            else
                this.firstTimeOpennedShop = false;
            this._data = [];
            this._price = [];
            var attach =  new Array();
            var itemID = 0;
            this._shopGoods.forEach(function(goods) {
                var item = null;
                switch (goods[0]) {
                case 0:
                    item = $dataItems[goods[1]];
                    break;
                case 1:
                    item = $dataWeapons[goods[1]];
                    cout("DEBUG: "+this.firstTimeOpennedShop);
                    if(this.firstTimeOpennedShop == true){
                        cout(item);
                        if(startingWeapons == null){
                            startingWeapons = new Array();
                            startingWeapons.push(item);
                        }
                        if(this.firstTimeOpennedShop == true && startingWeapons != null){
                            startingWeapons.push(item); 
                        } else {
                            item = startingWeapons[itemID];
                            itemID++;
                            firstTimeOpennedShop = false;
                        }
                        ///< Here we have to give random attaches!
                        console.log("Finding item augments");
                        console.log("Item slots lenght" + item.augmentSlots.length)
                        ItemManager.removeAllAugments(item);
                        for(var slotId = 0; slotId < item.augmentSlots.length; slotId++){
                            attach.push(randomAttachFind(item.augmentSlots[slotId]));
                            console.log("Slot id: " + slotId);
                            console.log("Slot name: " + item.augmentSlots[slotId]);
                            console.log(attach[slotId]);
                        }

                    }else if (this.firstTimeOpennedShop != true){

                    }
                    break;
                case 2:
                    item = $dataArmors[goods[1]];
                    break;
                }
                if (item) {
                    this._data.push(item);
                    this._price.push(goods[2] === 0 ? item.price : goods[3]);
                    ItemManager.installAugments(item,attach);
                    attach = new Array();
                }
            }, this);
            this.firstTimeOpennedShop = false;
            itemID = 0;
        };
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .