"Customize" the Equipment Optimize Button

Fernyfer775

Veteran
Veteran
Joined
Oct 6, 2013
Messages
1,317
Reaction score
818
First Language
English
Hey all. So, in my current project, I reworked "LUCK" into a stat called "POWER" which serves as an indicator of a piece of gear's potential/strength/what-have-you. My question is two-fold:

  1. How exactly does the default optimize button work? How are stats weighed? Does it just put on the piece with the highest total amount of stats on it, skewing items with higher hp/mp to always be equipped?
  2. Is there a way to change the way the optimize formula works to be based off one stat instead: LUCK? If so, HOW?
If it helps, this is the code found within "rpg_objects" which is where, I'm sure, you would alter the formula:
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++) {
var performance = this.calcEquipItemPerformance(items);
if (performance > bestPerformance) {
bestPerformance = performance;
bestItem = items;
}
}
return bestItem;
};

Game_Actor.prototype.calcEquipItemPerformance = function(item) {
return item.params.reduce(function(a, b) {
return a + b;
});
};

Any/all help would be appreciated, thank you! ^_^
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
Code:
Window_EquipCommand.prototype.makeCommandList = function() {
    this.addCommand(TextManager.equip2,   'equip');
    this.addCommand(TextManager.optimize, 'optimize'); <-
    this.addCommand(TextManager.clear,    'clear');
};

Scene_Equip.prototype.createCommandWindow = function() {
    var wx = this._statusWindow.width;
    var wy = this._helpWindow.height;
    var ww = Graphics.boxWidth - this._statusWindow.width;
    this._commandWindow = new Window_EquipCommand(wx, wy, ww);
    this._commandWindow.setHelpWindow(this._helpWindow);
    this._commandWindow.setHandler('equip',    this.commandEquip.bind(this));
    this._commandWindow.setHandler('optimize', this.commandOptimize.bind(this)); <-
    this._commandWindow.setHandler('clear',    this.commandClear.bind(this));
    this._commandWindow.setHandler('cancel',   this.popScene.bind(this));
    this._commandWindow.setHandler('pagedown', this.nextActor.bind(this));
    this._commandWindow.setHandler('pageup',   this.previousActor.bind(this));
    this.addWindow(this._commandWindow);
};

Scene_Equip.prototype.commandOptimize = function() {
    SoundManager.playEquip();
    this.actor().optimizeEquipments(); <-
    this._statusWindow.refresh();
    this._slotWindow.refresh();
    this._commandWindow.activate();
};

Game_Actor.prototype.optimizeEquipments = function() {
    var maxSlots = this.equipSlots().length;
    this.clearEquipments();
    for (var i = 0; i < maxSlots; i++) {
        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++) {
        var performance = this.calcEquipItemPerformance(items[i]); <-
        if (performance > bestPerformance) {
            bestPerformance = performance;
            bestItem = items[i];
        }
    }
    return bestItem;
};

Game_Actor.prototype.calcEquipItemPerformance = function(item) {
    return item.params.reduce(function(a, b) {  <-
        return a + b;  <-
    });
};

from the literal word "optimize" to the actual logic in 6 jumps.
sometimes, a simple search is all it takes.

short answer, yes, you can.
long answer, you'll have to grab that parameter Luck, and translate it to a simple number that you can use in an addition, or write a completely new formula that would suit you,... but yes, it can be done, it is all an addition of results.... wherever those results come from, for the function that processes them, is of no consequence to that function.... so you can feed it whatever numbers you want.
 

Fernyfer775

Veteran
Veteran
Joined
Oct 6, 2013
Messages
1,317
Reaction score
818
First Language
English
Thank you for taking the time to reply, but it doesn't quite get me to where I want to be with this.

See, I looked through that code, so I know where it would be altered, but I posted here because I don't know how to alter it. All the gear in my game already has the LUCK stat on it, which dictates how strong that piece of gear is. I am looking for help on how to change the code I posted in the OP to just cycle through the gear and slap on the piece that has the highest LUCK stat on it.

I'm a novice when it comes to javascript, so a lot of the stuff in that code is very foreign to me, and even with all my best attempts, I haven't managed to get it to just equip the pieces with the highest LUCK.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
have calcItemPerformance() return the actual value of Luck then?

the comparison is made by bestEquipItem(), based on what calcItemPerformance() returns.
if your base for comparison is straight Luck,.... ?
 

Fernyfer775

Veteran
Veteran
Joined
Oct 6, 2013
Messages
1,317
Reaction score
818
First Language
English
Yeah, it's literally just the luck stat. So, I would just need the code to see the luck stat on the currently equipped item and then replace it with whatever other piece i have that has the highest luck .
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
actor.luk() ?

the base function should still be the same, even if you have renamed it.
 

Isabella Ava

Veteran
Veteran
Joined
Sep 13, 2016
Messages
635
Reaction score
756
First Language
English
Hey all. So, in my current project, I reworked "LUCK" into a stat called "POWER" which serves as an indicator of a piece of gear's potential/strength/what-have-you. My question is two-fold:

  1. How exactly does the default optimize button work? How are stats weighed? Does it just put on the piece with the highest total amount of stats on it, skewing items with higher hp/mp to always be equipped?
  2. Is there a way to change the way the optimize formula works to be based off one stat instead: LUCK? If so, HOW?
If it helps, this is the code found within "rpg_objects" which is where, I'm sure, you would alter the formula:
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++) {
var performance = this.calcEquipItemPerformance(items);
if (performance > bestPerformance) {
bestPerformance = performance;
bestItem = items;
}
}
return bestItem;
};

Game_Actor.prototype.calcEquipItemPerformance = function(item) {
return item.params.reduce(function(a, b) {
return a + b;
});
};

Any/all help would be appreciated, thank you! ^_^
Replace this:
Game_Actor.prototype.calcEquipItemPerformance = function(item) {
return item.params.reduce(function(a, b) {
return a + b;
});
};
with this:
Game_Actor.prototype.calcEquipItemPerformance = function(item) {
return item.params[7];
};
 

Fernyfer775

Veteran
Veteran
Joined
Oct 6, 2013
Messages
1,317
Reaction score
818
First Language
English
@Isabella Ava Works like a charm, thank you so much! :D (I have no idea what any of the function a, b, whatever means, so that's what was throwing me off)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,040
Members
137,569
Latest member
Shtelsky
Top