Ciao, ho scaricato il seguente plugin che permette di ricevere dei bonus extra se si indossano equip dello stesso set (per esempio: "Spada della Morte" + "Scudo della Morte" = Att x3). Vorrei fare in modo, però, che il bonus possa essere letto dal giocatore in modo che sappia l'effetto in modo esplicito. Posto il codice. Grazie.
Spoiler
/*:
* @plugindesc Adds equipment sets to the game, that provide bonuses depending on the number of items equipped.
*
* @author Iavra
*
* @param Configuration
* @desc File path to the configuration file, that's used to load set bonuses.
* @default sets.json
*
* @param Stackable Bonuses
* @desc If set to true, all set bonuses stack. If false, only the highest applicable one gets applied.
* @default true
*
* @help
* To register one or more equipment sets, put a JSON file in your project folder and set the parameter "Configuration"
* to its file path. Following is a sample file containing 1 set:
*
* [
* {
* "name": "Testset",
* "description": "This is a test set.",
* "icon": 1,
* "items": [
* ["weapon", 1],
* ["armor", 2]
* ],
* "traits": {
* "2": [
* {"code": 21, "dataId": 2, "value": 2.0}
* ]
* }
* }
* ]
*
* The sample set contains of the weapon #1 and armor #2 and doubles the "atk" parameter of an actor, if he has both
* equipped (equipping the weapon twice does NOT count). Set name, description and icon are not directly used by this
* plugin, but can be utilized by others.
*
* You can add all traits, that are available in the database (actors/classes/weapons/armors -> traits). Following is
* a table containing all codes:
*
* 11 Element Rate
* 12 Debuff Rate
* 13 State Rate
* 14 State Resist
* 20 Param Plus
* 21 Param Rate
* 22 XParam Plus
* 23 SParam Rate
* 31 Attack Element
* 32 Attack State
* 33 Attack Speed
* 34 Attack Times
* 41 Add Skill Type
* 42 Seal Skill Type
* 43 Add Skill
* 44 Seal Skill
* 62 Special Flag
*
* There are more trait codes, but i'm not sure, if and how they are working, but feel free to tinker around with them.
*
* Following is a table containing the dataIds for all params:
*
* 0 Max HP
* 1 Max MP
* 2 Attack Power
* 3 Defense Power
* 4 Magic Attack Power
* 5 Magic Defense Power
* 6 Agility
* 7 Luck
*
* Following is a table containing the dataIds for all xparams:
*
* 0 Hit Rate
* 1 Evasion Rate
* 2 Critical Rate
* 3 Critical Evasion Rate
* 4 Magic Evasion Rate
* 5 Magic Reflection Rate
* 6 Counter Attack Rate
* 7 HP Regeneration Rate
* 8 MP Regeneration Rate
* 9 TP Regeneration Rate
*
* Following is a table containing the dataIds for all sparams:
*
* 0 Target Rate
* 1 Guard Effect Rate
* 2 Recovery Effect Rate
* 3 Pharmacology
* 4 MP Cost Rate
* 5 TP Charge Rate
* 6 Physical Damage Rate
* 7 Magical Damage Rate
* 8 Floor Damage Rate
* 9 Experience Rate
*
* Following is a table containing the dataIds for special flags:
*
* 0 Auto Battle
* 1 Guard
* 2 Substitute
* 3 Preserve TP
*
* The plugin provides some script calls to interact with sets:
*
* IAVRA.SETS.sets(); Returns all registered sets.
* IAVRA.SETS.setsForItem(item); Returns all sets containing the given armor or weapon.
* IAVRA.SETS.setsForActor(actor); Returns all sets containing at least 1 item currently equipped to the given actor.
*
* Furthermore, each set has the following functions to interact with:
*
* set.numItemsEquipped(actor); Returns the number of items belonging to this set currently equipped to the actor.
* set.applicableTraits(actor); Returns all traits of the set, that are currently applied to the actor.
* set.name; The name of the set.
* set.description; The description of the set.
* set.icon; The icon index of the set.
* set.items; All items belonging to the set.
*/
var IAVRA = IAVRA || {};
(function($) {
"use strict";
/**
* Read plugin parameters independent from the actual filename.
*/
var _params = $plugins.filter(function(p) { return p.description.contains(''); })[0].parameters;
var _param_config = _params['Configuration'];
var _param_stackable = _params['Stackable Bonuses'].toLowerCase() === 'true';
/**
* New trait code, that defines value to be added to "paramPlus" to increase the base param values.
*/
var _trait_paramPlus = 20;
/**
* Holds the set data, before create set objects, since we have to wait for the database being loaded, first.
*/
var _data;
/**
* Holds all registered sets.
*/
var _sets = [];
/**
* Load the configuration file and store the data for later usage.
*/
var _loadData = function() {
var request = new XMLHttpRequest();
request.open('GET', _param_config);
request.overrideMimeType('application/json');
request.onload = function() { _data = JSON.parse(request.responseText); };
request.onerror = function() { throw new Error('There was an error loading the file.'); };
request.send();
};
/**
* Create set objects from the loaded data. If part of the data is invalid, log the error, but continue. Makes it
* easier to test configurations. Afterwards, clear the cached data object to free some memory, because it's not
* needed anymore.
*/
var _initialize = function() {
_data.forEach(function(data) {
try { _sets.push(new IAVRA.SETS.Set(data)); } catch(error) { console.warn('Invalid set data: ', error); }
});
_data = null;
};
/**
* Return the actual weapon/armor entries for the given item data.
*/
var _parseItems = function(data) {
return data.map(function(item) { switch(item[0]) {
case 'weapon': return $dataWeapons[item[1]];
case 'armor': return $dataArmors[item[1]];
}})
};
/**
* Returns an array containing all traits of a given set data, ordered by the number of equipped items needed.
*/
var _parseTraits = function(data) {
return Object.keys(data).reduce(function(array, key) { array[key|0] = data[key]; return array; }, [])
};
/**
* On refresh, store the actor sets and set bonuses inside the actor, so they don't have to be calculated every
* time a parameter or trait is accessed.
*/
var _refreshActor = function(actor) {
var sets = $.SETS.setsForActor(actor);
var traits = Array.prototype.concat.apply([], sets.map(function(s) { return s.applicableTraits(actor); }));
actor._iavra_sets = { sets: sets, traits: traits };
};
//=============================================================================
// IAVRA.SETS
//=============================================================================
$.SETS = {
/**
* Returns all registered sets.
*/
sets: function() { return _sets; },
/**
* Returns an array of all sets containing the given item.
*/
setsForItem: function(item) { return _sets.filter(function(s) { return s.items.contains(item); }); },
/**
* Returns an array of all sets, that are currently present on the given actor.
*/
setsForActor: function(actor) { return _sets.filter(function(s) { return s.numItemsEquipped(actor) > 0; }); },
/**
* Holds all information regarding the registered equipment sets.
*/
Set: function() { this.initialize.apply(this, arguments); }
};
//=============================================================================
// IAVRA.SETS.Set
//=============================================================================
(function($) {
/**
* Initialize a bunch of stuff from the given data.
*/
$.prototype.initialize = function(data) {
this._name = data.name;
this._description = data.description;
this._icon = parseInt(data.icon);
this._items = _parseItems(data.items);
this._traits = _parseTraits(data.traits);
};
/**
* Returns the number of items a given actor has equipped, that belong to this set.
*/
$.prototype.numItemsEquipped = function(actor) {
var e = actor.equips(); return this.items.filter(function(i) { return e.contains(i); }).length;
};
/**
* Returns the traits belonging to this set, that can be applied to the given actor depending on the number of
* set items they have equipped.
*/
$.prototype.applicableTraits = function(actor) {
var num = this.numItemsEquipped(actor), result = [];
for(var t = this._traits, i = t.length; i--; ) { if(t[i] && i <= num) {
if(_param_stackable) { result = result.concat(t[i]); } else { return t[i]; }
} }
return result;
};
/**
* Defining some properties for encapsulation.
*/
Object.defineProperties($.prototype, {
name: { get: function() { return this._name; } },
description: { get: function() { return this._description; } },
icon: { get: function() { return this._icon; } },
items: { get: function() { return this._items; } }
});
})($.SETS.Set);
//=============================================================================
// Game_Actor
//=============================================================================
(function($) {
/**
* On refresh, store all sets and their traits applicable to this actor inside the object, so we don't need to
* calculate them every time we need to access a trait.
*/
var alias_refresh = $.prototype.refresh;
$.prototype.refresh = function() {
_refreshActor(this);
alias_refresh.call(this);
};
/**
* Also add all traits supplied by equipment sets.
*/
var alias_traitObjects = $.prototype.traitObjects;
$.prototype.traitObjects = function() {
return alias_traitObjects.call(this).concat(this._iavra_sets);
};
/**
* We have added a new trait id (20), that gets used to add constant values to the param base.
*/
var alias_paramPlus = $.prototype.paramPlus;
$.prototype.paramPlus = function(paramId) {
return alias_paramPlus.call(this, paramId) + this.traitsSum(_trait_paramPlus, paramId);
};
/**
* Contains all sets and set bonuses, that are currently applied to this actor. Gets updated during refresh.
*/
$.prototype._iavra_sets = { sets: [], traits: [] };
})(Game_Actor);
//=============================================================================
// Scene_Boot
//=============================================================================
(function($) {
/**
* On create, start loading our configuration file.
*/
var alias_create = $.prototype.create;
$.prototype.create = function() { alias_create.call(this); _loadData(); };
/**
* Wait, until the configuration has been loaded.
*/
var alias_isReady = $.prototype.isReady;
$.prototype.isReady = function() { return (_data !== undefined) && alias_isReady.call(this); };
/**
* On start, parse the loaded data, since we need access to $dataWeapons and $dataArmors.
*/
var alias_start = $.prototype.start;
$.prototype.start = function() { _initialize(); alias_start.call(this); };
})(Scene_Boot);
//=============================================================================
// DataManager
//=============================================================================
(function($) {
/**
* When loading a game, refresh all set bonuses. This makes the plugin plug-and-play and allows to edit the
* configuration file without invalidating all savegames.
*/
var alias_loadGame = $.loadGame;
$.loadGame = function(savefileId) {
var result = alias_loadGame.call(this, savefileId);
$gameActors._data.forEach(function(actor) { if(actor) { _refreshActor(actor); } });
return result;
};
})(DataManager);
})(IAVRA);
* @plugindesc Adds equipment sets to the game, that provide bonuses depending on the number of items equipped.
*
* @author Iavra
*
* @param Configuration
* @desc File path to the configuration file, that's used to load set bonuses.
* @default sets.json
*
* @param Stackable Bonuses
* @desc If set to true, all set bonuses stack. If false, only the highest applicable one gets applied.
* @default true
*
* @help
* To register one or more equipment sets, put a JSON file in your project folder and set the parameter "Configuration"
* to its file path. Following is a sample file containing 1 set:
*
* [
* {
* "name": "Testset",
* "description": "This is a test set.",
* "icon": 1,
* "items": [
* ["weapon", 1],
* ["armor", 2]
* ],
* "traits": {
* "2": [
* {"code": 21, "dataId": 2, "value": 2.0}
* ]
* }
* }
* ]
*
* The sample set contains of the weapon #1 and armor #2 and doubles the "atk" parameter of an actor, if he has both
* equipped (equipping the weapon twice does NOT count). Set name, description and icon are not directly used by this
* plugin, but can be utilized by others.
*
* You can add all traits, that are available in the database (actors/classes/weapons/armors -> traits). Following is
* a table containing all codes:
*
* 11 Element Rate
* 12 Debuff Rate
* 13 State Rate
* 14 State Resist
* 20 Param Plus
* 21 Param Rate
* 22 XParam Plus
* 23 SParam Rate
* 31 Attack Element
* 32 Attack State
* 33 Attack Speed
* 34 Attack Times
* 41 Add Skill Type
* 42 Seal Skill Type
* 43 Add Skill
* 44 Seal Skill
* 62 Special Flag
*
* There are more trait codes, but i'm not sure, if and how they are working, but feel free to tinker around with them.
*
* Following is a table containing the dataIds for all params:
*
* 0 Max HP
* 1 Max MP
* 2 Attack Power
* 3 Defense Power
* 4 Magic Attack Power
* 5 Magic Defense Power
* 6 Agility
* 7 Luck
*
* Following is a table containing the dataIds for all xparams:
*
* 0 Hit Rate
* 1 Evasion Rate
* 2 Critical Rate
* 3 Critical Evasion Rate
* 4 Magic Evasion Rate
* 5 Magic Reflection Rate
* 6 Counter Attack Rate
* 7 HP Regeneration Rate
* 8 MP Regeneration Rate
* 9 TP Regeneration Rate
*
* Following is a table containing the dataIds for all sparams:
*
* 0 Target Rate
* 1 Guard Effect Rate
* 2 Recovery Effect Rate
* 3 Pharmacology
* 4 MP Cost Rate
* 5 TP Charge Rate
* 6 Physical Damage Rate
* 7 Magical Damage Rate
* 8 Floor Damage Rate
* 9 Experience Rate
*
* Following is a table containing the dataIds for special flags:
*
* 0 Auto Battle
* 1 Guard
* 2 Substitute
* 3 Preserve TP
*
* The plugin provides some script calls to interact with sets:
*
* IAVRA.SETS.sets(); Returns all registered sets.
* IAVRA.SETS.setsForItem(item); Returns all sets containing the given armor or weapon.
* IAVRA.SETS.setsForActor(actor); Returns all sets containing at least 1 item currently equipped to the given actor.
*
* Furthermore, each set has the following functions to interact with:
*
* set.numItemsEquipped(actor); Returns the number of items belonging to this set currently equipped to the actor.
* set.applicableTraits(actor); Returns all traits of the set, that are currently applied to the actor.
* set.name; The name of the set.
* set.description; The description of the set.
* set.icon; The icon index of the set.
* set.items; All items belonging to the set.
*/
var IAVRA = IAVRA || {};
(function($) {
"use strict";
/**
* Read plugin parameters independent from the actual filename.
*/
var _params = $plugins.filter(function(p) { return p.description.contains(''); })[0].parameters;
var _param_config = _params['Configuration'];
var _param_stackable = _params['Stackable Bonuses'].toLowerCase() === 'true';
/**
* New trait code, that defines value to be added to "paramPlus" to increase the base param values.
*/
var _trait_paramPlus = 20;
/**
* Holds the set data, before create set objects, since we have to wait for the database being loaded, first.
*/
var _data;
/**
* Holds all registered sets.
*/
var _sets = [];
/**
* Load the configuration file and store the data for later usage.
*/
var _loadData = function() {
var request = new XMLHttpRequest();
request.open('GET', _param_config);
request.overrideMimeType('application/json');
request.onload = function() { _data = JSON.parse(request.responseText); };
request.onerror = function() { throw new Error('There was an error loading the file.'); };
request.send();
};
/**
* Create set objects from the loaded data. If part of the data is invalid, log the error, but continue. Makes it
* easier to test configurations. Afterwards, clear the cached data object to free some memory, because it's not
* needed anymore.
*/
var _initialize = function() {
_data.forEach(function(data) {
try { _sets.push(new IAVRA.SETS.Set(data)); } catch(error) { console.warn('Invalid set data: ', error); }
});
_data = null;
};
/**
* Return the actual weapon/armor entries for the given item data.
*/
var _parseItems = function(data) {
return data.map(function(item) { switch(item[0]) {
case 'weapon': return $dataWeapons[item[1]];
case 'armor': return $dataArmors[item[1]];
}})
};
/**
* Returns an array containing all traits of a given set data, ordered by the number of equipped items needed.
*/
var _parseTraits = function(data) {
return Object.keys(data).reduce(function(array, key) { array[key|0] = data[key]; return array; }, [])
};
/**
* On refresh, store the actor sets and set bonuses inside the actor, so they don't have to be calculated every
* time a parameter or trait is accessed.
*/
var _refreshActor = function(actor) {
var sets = $.SETS.setsForActor(actor);
var traits = Array.prototype.concat.apply([], sets.map(function(s) { return s.applicableTraits(actor); }));
actor._iavra_sets = { sets: sets, traits: traits };
};
//=============================================================================
// IAVRA.SETS
//=============================================================================
$.SETS = {
/**
* Returns all registered sets.
*/
sets: function() { return _sets; },
/**
* Returns an array of all sets containing the given item.
*/
setsForItem: function(item) { return _sets.filter(function(s) { return s.items.contains(item); }); },
/**
* Returns an array of all sets, that are currently present on the given actor.
*/
setsForActor: function(actor) { return _sets.filter(function(s) { return s.numItemsEquipped(actor) > 0; }); },
/**
* Holds all information regarding the registered equipment sets.
*/
Set: function() { this.initialize.apply(this, arguments); }
};
//=============================================================================
// IAVRA.SETS.Set
//=============================================================================
(function($) {
/**
* Initialize a bunch of stuff from the given data.
*/
$.prototype.initialize = function(data) {
this._name = data.name;
this._description = data.description;
this._icon = parseInt(data.icon);
this._items = _parseItems(data.items);
this._traits = _parseTraits(data.traits);
};
/**
* Returns the number of items a given actor has equipped, that belong to this set.
*/
$.prototype.numItemsEquipped = function(actor) {
var e = actor.equips(); return this.items.filter(function(i) { return e.contains(i); }).length;
};
/**
* Returns the traits belonging to this set, that can be applied to the given actor depending on the number of
* set items they have equipped.
*/
$.prototype.applicableTraits = function(actor) {
var num = this.numItemsEquipped(actor), result = [];
for(var t = this._traits, i = t.length; i--; ) { if(t[i] && i <= num) {
if(_param_stackable) { result = result.concat(t[i]); } else { return t[i]; }
} }
return result;
};
/**
* Defining some properties for encapsulation.
*/
Object.defineProperties($.prototype, {
name: { get: function() { return this._name; } },
description: { get: function() { return this._description; } },
icon: { get: function() { return this._icon; } },
items: { get: function() { return this._items; } }
});
})($.SETS.Set);
//=============================================================================
// Game_Actor
//=============================================================================
(function($) {
/**
* On refresh, store all sets and their traits applicable to this actor inside the object, so we don't need to
* calculate them every time we need to access a trait.
*/
var alias_refresh = $.prototype.refresh;
$.prototype.refresh = function() {
_refreshActor(this);
alias_refresh.call(this);
};
/**
* Also add all traits supplied by equipment sets.
*/
var alias_traitObjects = $.prototype.traitObjects;
$.prototype.traitObjects = function() {
return alias_traitObjects.call(this).concat(this._iavra_sets);
};
/**
* We have added a new trait id (20), that gets used to add constant values to the param base.
*/
var alias_paramPlus = $.prototype.paramPlus;
$.prototype.paramPlus = function(paramId) {
return alias_paramPlus.call(this, paramId) + this.traitsSum(_trait_paramPlus, paramId);
};
/**
* Contains all sets and set bonuses, that are currently applied to this actor. Gets updated during refresh.
*/
$.prototype._iavra_sets = { sets: [], traits: [] };
})(Game_Actor);
//=============================================================================
// Scene_Boot
//=============================================================================
(function($) {
/**
* On create, start loading our configuration file.
*/
var alias_create = $.prototype.create;
$.prototype.create = function() { alias_create.call(this); _loadData(); };
/**
* Wait, until the configuration has been loaded.
*/
var alias_isReady = $.prototype.isReady;
$.prototype.isReady = function() { return (_data !== undefined) && alias_isReady.call(this); };
/**
* On start, parse the loaded data, since we need access to $dataWeapons and $dataArmors.
*/
var alias_start = $.prototype.start;
$.prototype.start = function() { _initialize(); alias_start.call(this); };
})(Scene_Boot);
//=============================================================================
// DataManager
//=============================================================================
(function($) {
/**
* When loading a game, refresh all set bonuses. This makes the plugin plug-and-play and allows to edit the
* configuration file without invalidating all savegames.
*/
var alias_loadGame = $.loadGame;
$.loadGame = function(savefileId) {
var result = alias_loadGame.call(this, savefileId);
$gameActors._data.forEach(function(actor) { if(actor) { _refreshActor(actor); } });
return result;
};
})(DataManager);
})(IAVRA);