Created
August 17, 2018 04:37
-
-
Save armornick/2ea7c06f9f975726af29766502859fa6 to your computer and use it in GitHub Desktop.
RPG Maker MV plugin to show the skills added by a piece of equipment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*: | |
@plugindesc Show equipment skills on equip menu | |
@author armornick | |
@param Equipment Skills Text | |
@desc The label to show above the equipment skills list. | |
@default Equipment Skills | |
@help | |
This plugin shows the changes in skills via equipment. | |
=== License ==== | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |
of the Software, and to permit persons to whom the Software is furnished to do so. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | |
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | |
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
DEALINGS IN THE SOFTWARE. | |
*/ | |
var Imported = Imported || {}; | |
Imported.NIA_EquipSkillCommands = 1; | |
(function () { | |
var params = PluginManager.parameters('NIA_EquipSkillCommands'); | |
var EQUIP_SKILLS_TEXT = params['Equipment Skills Text'] || "Equipment Skills"; | |
//----------------------------------------------------------------------------- | |
// Window_EquipStatus | |
Window_EquipStatus.prototype.initialize = function(x, y, height) { | |
var width = this.windowWidth(); | |
Window_Base.prototype.initialize.call(this, x, y, width, height); | |
this._actor = null; | |
this._tempActor = null; | |
this.refresh(); | |
}; | |
/* | |
Gets the "diff value" for the given skill and new and old trait lists. | |
Returns -1 if the given skill is removed after the equipment change, | |
+1 if the skill is added after equipment change, or 0 if there is | |
no change in the given skill. | |
*/ | |
function getEquipSkillDiff (trait, oldList, newList) { | |
var result = 0, skillId = trait.dataId; | |
// if the newList is null, this means we show the current state | |
if (newList == null) { | |
return result; | |
} | |
for (let oldItem of oldList) { | |
if (oldItem.dataId === skillId) { | |
result--; break; | |
} | |
} | |
for (let newItem of newList) { | |
if (newItem.dataId === skillId) { | |
result++; break; | |
} | |
} | |
return result; | |
} | |
var NIA_EquipSkillCommands_WindowEquipStatus_refresh = Window_EquipStatus.prototype.refresh; | |
Window_EquipStatus.prototype.refresh = function() { | |
NIA_EquipSkillCommands_WindowEquipStatus_refresh.call(this); | |
if (this._actor) { | |
var i = this.numVisibleRows(); // take the next row to draw at | |
var oldEquipSkills = this._actor.traits(Game_Action.EFFECT_LEARN_SKILL), | |
allEquipSkills = oldEquipSkills; | |
var newEquipSkills = null; | |
if (this._tempActor) { | |
newEquipSkills = this._tempActor.traits(Game_Action.EFFECT_LEARN_SKILL); | |
allEquipSkills = oldEquipSkills.concat(newEquipSkills); | |
} | |
this.resetTextColor(); | |
this.drawText(EQUIP_SKILLS_TEXT, 0, this.lineHeight() * (1 + i++), 120); | |
for (let equipSkill of allEquipSkills) { | |
var skill = $dataSkills[equipSkill.dataId]; | |
this.drawEquipSkill(skill, 0, this.lineHeight() * (1 + i++), 120, | |
getEquipSkillDiff(equipSkill, oldEquipSkills, newEquipSkills)); | |
} | |
} | |
} | |
Window_EquipStatus.prototype.drawEquipSkill = function(item, x, y, width, diffvalue) { | |
if (item) { | |
var iconBoxWidth = Window_Base._iconWidth + 4; | |
this.changeTextColor(this.paramchangeTextColor(diffvalue)); | |
this.drawIcon(item.iconIndex, x + 2, y + 2); | |
this.drawText(item.name, x + iconBoxWidth, y, width - iconBoxWidth); | |
} | |
} | |
//----------------------------------------------------------------------------- | |
// Window_EquipItem | |
Window_EquipItem.prototype.maxCols = function() { | |
return 1; | |
}; | |
//----------------------------------------------------------------------------- | |
// Window_EquipSlot | |
Window_EquipSlot.prototype.initialize = function(x, y, width) { | |
var height = this.windowHeight(); | |
Window_Selectable.prototype.initialize.call(this, x, y, width, height); | |
this._actor = null; | |
this.refresh(); | |
}; | |
Window_EquipSlot.prototype.windowHeight = function() { | |
return this.fittingHeight(this.guessEquipSlotsCount()); | |
}; | |
Window_EquipSlot.prototype.guessEquipSlotsCount = function () { | |
return $gameActors.actor(1).equipSlots().length; | |
}; | |
//----------------------------------------------------------------------------- | |
// Scene_Equip | |
Scene_Equip.prototype.createStatusWindow = function() { | |
var wh = Graphics.boxHeight - this._helpWindow.height; | |
this._statusWindow = new Window_EquipStatus(0, this._helpWindow.height, wh); | |
this.addWindow(this._statusWindow); | |
}; | |
Scene_Equip.prototype.createSlotWindow = function() { | |
var wx = this._statusWindow.width; | |
var wy = this._commandWindow.y + this._commandWindow.height; | |
var ww = Graphics.boxWidth - this._statusWindow.width; | |
var wh = this._statusWindow.height - this._commandWindow.height; | |
this._slotWindow = new Window_EquipSlot(wx, wy, ww, wh); | |
this._slotWindow.setHelpWindow(this._helpWindow); | |
this._slotWindow.setStatusWindow(this._statusWindow); | |
this._slotWindow.setHandler('ok', this.onSlotOk.bind(this)); | |
this._slotWindow.setHandler('cancel', this.onSlotCancel.bind(this)); | |
this.addWindow(this._slotWindow); | |
}; | |
Scene_Equip.prototype.createItemWindow = function() { | |
var wx = this._statusWindow.width; | |
var wy = this._slotWindow.y + this._slotWindow.height; | |
var ww = Graphics.boxWidth; | |
var wh = Graphics.boxHeight - wy; | |
this._itemWindow = new Window_EquipItem(wx, wy, ww, wh); | |
this._itemWindow.setHelpWindow(this._helpWindow); | |
this._itemWindow.setStatusWindow(this._statusWindow); | |
this._itemWindow.setHandler('ok', this.onItemOk.bind(this)); | |
this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this)); | |
this._slotWindow.setItemWindow(this._itemWindow); | |
this.addWindow(this._itemWindow); | |
}; | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment