While sometimes we've to write short/long/etc functions(while sometimes function length just doesn't matter at all) and whether a function's considered to be short/long can sometimes be relative to the underlying context and/or plugin developers' own judgments(based on their own experiences and observations), most of us still have a general feeling/rule(applied on most but some special cases we've already dealt with) on whether a function's short/long(at least for ourselves) and many of us have some preferences on the function length(Some may prefer short functions while some may prefer long ones).
While the below is just an example demonstrating the first 5 choices in the poll under my own subjective interpretations, I still think it can help you have a vague idea on those choices(all modified from DoubleX RMMV Substitute Edit):
As short as possible -
Just short enough -
Not short nor long -
Just long enough -
As long as possible -
I don't want you to be restricted to the above example, as I want you to make your own choices based on your own judgments under your own experiences and observations instead.
While the below is just an example demonstrating the first 5 choices in the poll under my own subjective interpretations, I still think it can help you have a vague idea on those choices(all modified from DoubleX RMMV Substitute Edit):
As short as possible -
SE.Game_Action = {}; var GA = SE.Game_Action; /*------------------------------------------------------------------------ * Helper function easing checkings in filtering substitute battlers *------------------------------------------------------------------------*/ GA.effectType = function() { return this.isHpEffect() ? "hp" : this.isMpEffect() ? "mp" : null; }; // GA.effectType /*------------------------------------------------------------------------ * Helper function easing checkings in filtering substitute battlers *------------------------------------------------------------------------*/ GA.hitType = function() { return this.isPhysical() ? "pdr" : this.isMagical() ? "mdr" : null; }; // GA.hitType SE.Game_Unit = {}; var GU = SE.Game_Unit; Game_Unit.prototype.substituteBattler = function() { // Rewritten to use all filters in the filter list sequentially as well var mems = this.members(); mems = mems.filter(function(mem) { return mem.isSubstitute(); }); return GU.setSubstituteBattler(mems); // }; // Game_Unit.prototype.substituteBattler // mems: All members that can substitute GU.setSubstituteBattler = function(mems) { if (mems.length === 0) { return null; } if (mems.length === 1) { return mems[0]; } return GU.substituteBattler(mems); }; // GU.setSubstituteBattler // mems: All members that can substitute GU.substituteBattler = function(mems) { var tempMems, eT = GA.effectType.call(BattleManager.action); var hT = GA.hitType.call(BattleManager.action); var filters = $gameSystem.substituteEdit.substituteBattlerFilters; return GU.filterBattler(mems, tempMems, filters, eT, hT); }; // GU.substituteBattler /* mems: All members that can substitute * tempMems: The clone member list storing the temporary filter results * filters: All added filters applied to all members that can substitute * eT: The hp/mp effect type of the currently executing action * hT: The physical/magical hit type of the currently executing action */ GU.filterBattler = function(mems, tempMems, filters, eT, hT) { for (var index = 0, length = filters.length; index < length; index++) { tempMems = GU.substituteBattlers(mems, filters[index], eT, hT); if (tempMems.length === 1) { return tempMems[0]; } if (tempMems.length > 1) { mems = tempMems; } } return mems[0]; }; // GU.filterBattler /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * effectType: The hp/mp effect type of the currently executing action * hitType: The physical/magical hit type of the currently executing action */ GU.substituteBattlers = function(mems, filter, effectType, hitType) { // Calls the filter function corresponding to the passed filter var isET = SE.isEffectTypeFilter(filter); if (isET) { return GU.effectTypeBattlers(mems, filter, effectType); } return GU.substituteBattlers2(mems, filter, hitType); // }; // GU.substituteBattlers /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * effectType: The hp/mp effect type of the currently executing action */ GU.effectTypeBattlers = function(mems, filter, effectType) { if (!effectType) { return mems; } if (filter !== "hpMp0") { return GU.maxHpMpBattlers(mems, effectType); } return mems.filter(function(mem) { return mem[effectType] === 0; }); }; // GU.effectTypeBattlers /* mems: All members that can substitute * eT: The hp/mp effect type of the currently executing action */ GU.maxHpMpBattlers = function(mems, eT) { var maxParam = GU.maxParam(mems, eT); return mems.filter(function(mem) { return mem[eT] === maxParam; }); }; // GU.maxHpMpBattlers /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.substituteBattlers2 = function(mems, filter, hitType) { var isHT = SE.isHitTypeFilter(filter); if (isHT) { return GU.hitTypeBattlers(mems, filter, hitType); } return GU.substituteBattlers3(mems, filter); }; // GU.substituteBattlers2 /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * hT: The physical/magical hit type of the currently executing action */ GU.hitTypeBattlers = function(mems, filter, hT) { if (!hT) { return mems; } if (filter === "maxCntMrf") { return GU.maxCntMrfBattlers(mems, hT); } if (filter === "maxEvaMev") { return GU.maxEvaMevBattlers(mems, hT); } return GU.maxPdrMdrBattlers(mems, hT); }; // GU.hitTypeBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxCntMrfBattlers = function(mems, hitType) { var counter = hitType === "pdr" ? "cnt" : "mrf"; var maxParam = GU.maxParam(mems, counter); return mems.filter(function(mem) { return mem[counter] === maxParam; }); }; // GU.maxCntMrfBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxEvaMevBattlers = function(mems, hitType) { var evade = hitType === "pdr" ? "eva" : "mev"; var maxParam = GU.maxParam(mems, evade); return mems.filter(function(mem) { return mem[evade] === maxParam; }); }; // GU.maxEvaMevBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxPdrMdrBattlers = function(mems, hitType) { var maxParam = GU.maxParam(mems, hitType); return mems.filter(function(mem) { return mem[hitType] === maxParam; }); }; // GU.maxPdrMdrBattlers /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute */ GU.substituteBattlers3 = function(mems, filter, hitType) { if (II.isFilter(filter)) { return GU.filterBattlers(mems, filter); } console.log("Invalid substitute battler filter " + filter); return mems; }; // GU.substituteBattlers3 /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute */ GU.filterBattlers = function(mems, filter) { if (filter === "immortal") { return GU.immortalBattlers(mems); } return GU.maxGrdCevBattlers(mems, filter.substr(3, 3)); }; // GU.filterBattlers // mems: All members that can substitute GU.immortalBattlers = function(mems) { return mems.filter(function(mem) { return mem.isStateResist(mem.deathStateId()); }); }; // GU.immortalBattlers /* mems: All members that can substitute * param: The maximum param among all members to be found */ GU.maxGrdCevBattlers = function(mems, param) { var maxParam = GU.maxParam(mems, param); return mems.filter(function(mem) { return mem[param] === maxParam; }); }; // GU.maxGrdCevBattlers /* mems: All members that can substitute * param: The param/ExParam/SpParam used to filter the substitute battler */ GU.maxParamBattlers = function(mems, param) { return mems.slice(0).sort(function(a, { return b[param] - a[param]; })[0][param]; }; // GU.maxParamBattlers
SE.Game_Unit = {}; var GU = SE.Game_Unit; Game_Unit.prototype.substituteBattler = function() { // Rewritten to use all filters in the filter list sequentially as well var mems = this.members(); mems = mems.filter(function(mem) { return mem.isSubstitute(); }); if (mems.length === 0) { return null; } if (mems.length === 1) { return mems[0]; } return GU.substituteBattler(mems); // }; // Game_Unit.prototype.substituteBattler // mems: All members that can substitute GU.substituteBattler = function(mems) { var act = BattleManager.action; var eT = act.isHpEffect() ? "hp" : act.isMpEffect() ? "mp" : null; var hT = act.isPhysical() ? "pdr" : act.isMagical() ? "mdr" : null; var filters = $gameSystem.substituteEdit.substituteBattlerFilters; return GU.filterBattler(mems, filters, eT, hT); }; // GU.substituteBattler /* mems: All members that can substitute * filters: All added filters applied to all members that can substitute * eT: The hp/mp effect type of the currently executing action * hT: The physical/magical hit type of the currently executing action */ GU.filterBattler = function(mems, filters, eT, hT) { var tempMems; for (var index = 0, length = filters.length; index < length; index++) { tempMems = GU.substituteBattlers(mems, filters[index], eT, hT); if (tempMems.length === 1) { return tempMems[0]; } if (tempMems.length > 1) { mems = tempMems; } } return mems[0]; }; // GU.filterBattler /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * effectType: The hp/mp effect type of the currently executing action * hitType: The physical/magical hit type of the currently executing action */ GU.substituteBattlers = function(mems, filter, effectType, hitType) { // Calls the filter function corresponding to the passed filter var isET = SE.isEffectTypeFilter(filter); if (isET) { return GU.effectTypeBattlers(mems, filter, effectType); } var isHT = SE.isHitTypeFilter(filter); if (isHT) { return GU.hitTypeBattlers(mems, filter, hitType); } if (II.isFilter(filter)) { return GU.filterBattlers(mems, filter); } console.log("Invalid substitute battler filter " + filter); return mems; // }; // GU.substituteBattlers /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * effectType: The hp/mp effect type of the currently executing action */ GU.effectTypeBattlers = function(mems, filter, effectType) { if (!effectType) { return mems; } if (filter !== "hpMp0") { return GU.maxHpMpBattlers(mems, effectType); } return mems.filter(function(mem) { return mem[effectType] === 0; }); }; // GU.effectTypeBattlers /* mems: All members that can substitute * effectType: The hp/mp effect type of the currently executing action */ GU.maxHpMpBattlers = function(mems, effectType) { var maxParam = mems.slice(0).sort(function(a, { return b[effectType] - a[effectType]; })[0][effectType]; return mems.filter(function(mem) { return mem[effectType] === maxParam; }); }; // GU.maxHpMpBattlers /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.hitTypeBattlers = function(mems, filter, hitType) { if (!hitType) { return mems; } if (filter === "maxCntMrf") { return GU.maxCntMrfBattlers(mems, hitType); } else if (filter === "maxEvaMev") { return GU.maxEvaMevBattlers(mems, hitType); } return GU.maxPdrMdrBattlers(mems, hitType); }; // GU.hitTypeBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxCntMrfBattlers = function(mems, hitType) { var counter = hitType === "pdr" ? "cnt" : "mrf"; var maxParam = mems.slice(0).sort(function(a, { return b[counter] - a[counter]; })[0][counter]; return mems.filter(function(mem) { return mem[counter] === maxParam; }); }; // GU.maxCntMrfBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxEvaMevBattlers = function(mems, hitType) { var evade = hitType === "pdr" ? "eva" : "mev"; var maxParam = mems.slice(0).sort(function(a, { return b[evade] - a[evade]; })[0][evade]; return mems.filter(function(mem) { return mem[evade] === maxParam; }); }; // GU.maxEvaMevBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxPdrMdrBattlers = function(mems, hitType) { var maxParam = mems.slice(0).sort(function(a, { return b[hitType] - a[hitType]; })[0][hitType]; return mems.filter(function(mem) { return mem[hitType] === maxParam; }); }; // GU.maxPdrMdrBattlers /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute */ GU.filterBattlers = function(mems, filter) { if (filter !== "immortal") { return GU.maxGrdCevBattlers(mems, filter.substr(3, 3)); } return mems.filter(function(mem) { return mem.isStateResist(mem.deathStateId()); }); }; // GU.filterBattlers /* mems: All members that can substitute * param: The maximum param among all members to be found */ GU.maxGrdCevBattlers = function(mems, param) { var maxParam = mems.slice(0).sort(function(a, { return b[param] - a[param]; })[0][param]; return mems.filter(function(mem) { return mem[param] === maxParam; }); }; // GU.maxGrdCevBattlers
SE.Game_Unit = {}; var GU = SE.Game_Unit; Game_Unit.prototype.substituteBattler = function() { // Rewritten to use all filters in the filter list sequentially as well var mems = this.members().filter(function(mem) { return mem.isSubstitute(); }); if (mems.length === 0) { return null; } if (mems.length === 1) { return mems[0]; } return GU.substituteBattler(mems); // }; // Game_Unit.prototype.substituteBattler // mems: All members that can substitute GU.substituteBattler = function(mems) { var tempMems, act = BattleManager.action; var eT = act.isHpEffect() ? "hp" : act.isMpEffect() ? "mp" : null; var hT = act.isPhysical() ? "pdr" : act.isMagical() ? "mdr" : null; var filters = $gameSystem.substituteEdit.substituteBattlerFilters; for (var index = 0, length = filters.length; index < length; index++) { tempMems = GU.substituteBattlers(mems, filters[index], eT, hT); if (tempMems.length === 1) { return tempMems[0]; } if (tempMems.length > 1) { mems = tempMems; } } return mems[0]; }; // GU.substituteBattler /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * effectType: The hp/mp effect type of the currently executing action * hitType: The physical/magical hit type of the currently executing action */ GU.substituteBattlers = function(mems, filter, effectType, hitType) { // Calls the filter function corresponding to the passed filter if (["hpMp0", "maxHpMp"].indexOf(filter) >= 0) { return GU.effectTypeBattlers(mems, filter, effectType); } if (["maxCntMrf", "maxEvaMev", "maxPdrMdr"].indexOf(filter) >= 0) { return GU.hitTypeBattlers(mems, filter, hitType); } else if (["immortal", "maxGrd", "maxCev"].indexOf(filter) >= 0) { return GU.filterBattlers(mems, filter); } console.log("Invalid substitute battler filter " + filter); return mems; // }; // GU.substituteBattlers /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * effectType: The hp/mp effect type of the currently executing action */ GU.effectTypeBattlers = function(mems, filter, effectType) { if (!effectType) { return mems; } if (filter === "hpMp0") { return mems.filter(function(mem) { return mem[effectType] === 0; }); } var maxParam = mems.slice(0).sort(function(a, { return b[effectType] - a[effectType]; })[0][effectType]; return mems.filter(function(mem) { return mem[effectType] === maxParam; }); }; // GU.effectTypeBattlers /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.hitTypeBattlers = function(mems, filter, hitType) { if (!hitType) { return mems; } if (filter === "maxCntMrf") { return GU.maxCntMrfBattlers(mems, hitType); } else if (filter === "maxEvaMev") { return GU.maxEvaMevBattlers(mems, hitType); } var maxParam = mems.slice(0).sort(function(a, { return b[hitType] - a[hitType]; })[0][hitType]; return mems.filter(function(mem) { return mem[hitType] === maxParam; }); }; // GU.hitTypeBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxCntMrfBattlers = function(mems, hitType) { var counter = hitType === "pdr" ? "cnt" : "mrf"; var maxParam = mems.slice(0).sort(function(a, { return b[counter] - a[counter]; })[0][counter]; return mems.filter(function(mem) { return mem[counter] === maxParam; }); }; // GU.maxCntMrfBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxEvaMevBattlers = function(mems, hitType) { var evade = hitType === "pdr" ? "eva" : "mev"; var maxParam = mems.slice(0).sort(function(a, { return b[evade] - a[evade]; })[0][evade]; return mems.filter(function(mem) { return mem[evade] === maxParam; }); }; // GU.maxEvaMevBattlers /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute */ GU.filterBattlers = function(mems, filter) { if (filter === "immortal") { return mems.filter(function(mem) { return mem.isStateResist(mem.deathStateId()); }); } var param = filter.substr(3, 3); var maxParam = mems.slice(0).sort(function(a, { return b[param] - a[param]; })[0][param]; return mems.filter(function(mem) { return mem[param] === maxParam; }); }; // GU.filterBattlers
SE.Game_Unit = {}; var GU = SE.Game_Unit; Game_Unit.prototype.substituteBattler = function() { // Rewritten to use all filters in the filter list sequentially as well var act, eT, hT, filters, tempMems; var mems = this.members().filter(function(mem) { return mem.isSubstitute(); }); if (mems.length === 0) { return null; } if (mems.length === 1) { return mems[0]; } act = BattleManager.action; eT = act.isHpEffect() ? "hp" : act.isMpEffect() ? "mp" : null; hT = act.isPhysical() ? "pdr" : act.isMagical() ? "mdr" : null; filters = $gameSystem.substituteEdit.substituteBattlerFilters; for (var index = 0, length = filters.length; index < length; index++) { tempMems = GU.substituteBattlers(mems, filters[index], eT, hT); if (tempMems.length === 1) { return tempMems[0]; } if (tempMems.length > 1) { mems = tempMems; } } return mems[0]; // }; // Game_Unit.prototype.substituteBattler /* mems: All members that can substitute * filter: The added filter applied to all members that can substitute * effectType: The hp/mp effect type of the currently executing action * hitType: The physical/magical hit type of the currently executing action */ GU.substituteBattlers = function(mems, filter, effectType, hitType) { // Calls the filter function corresponding to the passed filter switch (filter) { case "hpMp0": return effectType ? mems.filter(function(mem) { return mem[effectType] === 0; }) : mems; case "immortal": return mems.filter(function(mem) { return mem.isStateResist(mem.deathStateId()); }); case "maxCntMrf": return GU.maxCntMrfBattlers(mems, hitType); case "maxEvaMev": return GU.maxEvaMevBattlers(mems, hitType); case "maxPdrMdr": return GU.maxPdrMdrBattlers(mems, hitType); case "maxHpMp": return GU.maxHpMpBattlers(mems, effectType); case "maxGrd": return GU.maxGrdBattlers(mems); case "maxCev": return GU.maxCevBattlers(mems); default: console.log("Invalid substitute battler filter " + filter); return mems; } // }; // GU.substituteBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxCntMrfBattlers = function(mems, hitType) { var counter = hitType === "pdr" ? "cnt" : "mdr" ? "mrf" : null; if (!counter) { return mems; } maxParam = mems.slice(0).sort(function(a, { return b[counter] - a[counter]; })[0][counter]; return mems.filter(function(mem) { return mem[counter] === maxParam; }); }; // GU.maxCntMrfBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxEvaMevBattlers = function(mems, hitType) { var maxParam, evade = hitType === "pdr" ? "eva" : "mdr" ? "mev" : null; if (!evade) { return mems; } maxParam = mems.slice(0).sort(function(a, { return b[evade] - a[evade]; })[0][evade]; return mems.filter(function(mem) { return mem[evade] === maxParam; }); }; // GU.maxEvaMevBattlers /* mems: All members that can substitute * hitType: The physical/magical hit type of the currently executing action */ GU.maxPdrMdrBattlers = function(mems, hitType) { if (!hitType) { return mems; } maxParam = mems.slice(0).sort(function(a, { return b[hitType] - a[hitType]; })[0][hitType]; return mems.filter(function(mem) { return mem[hitType] === maxParam; }); }; // GU.maxPdrMdrBattlers /* mems: All members that can substitute * effectType: The hp/mp effect type of the currently executing action */ GU.maxHpMpBattlers = function(mems, effectType) { var maxParam; if (!effectType) { return mems; } maxParam = mems.slice(0).sort(function(a, { return b[effectType] - a[effectType]; })[0][effectType]; return mems.filter(function(mem) { return mem[effectType] === maxParam; }); }; // GU.maxHpMpBattlers /* mems: All members that can substitute * effectType: The hp/mp effect type of the currently executing action */ GU.maxGrdBattlers = function(mems, effectType) { maxParam = mems.slice(0).sort(function(a, { return b.grd - a.grd; })[0].grd; return mems.filter(function(mem) { return mem.grd === maxParam; }); }; // GU.maxGrdBattlers /* mems: All members that can substitute * effectType: The hp/mp effect type of the currently executing action */ GU.maxCevBattlers = function(mems, effectType) { maxParam = mems.slice(0).sort(function(a, { return b.cev - a.cev; })[0].cev; return mems.filter(function(mem) { return mem.cev === maxParam; }); }; // GU.maxCevBattlers
SE.Game_Unit = {}; var GU = SE.Game_Unit; Game_Unit.prototype.substituteBattler = function() { // Rewritten to use all filters in the filter list sequentially as well var act, eT, hT, filters, tempMems; var mems = this.members().filter(function(mem) { return mem.isSubstitute(); }); if (mems.length === 0) { return null; } if (mems.length === 1) { return mems[0]; } act = BattleManager.action; eT = act.isHpEffect() ? "hp" : act.isMpEffect() ? "mp" : null; hT = act.isPhysical() ? "pdr" : act.isMagical() ? "mdr" : null; filters = $gameSystem.substituteEdit.substituteBattlerFilters; for (var index = 0, length = filters.length; index < length; index++) { switch (filter) { case "hpMp0": if (!effectType) { tempMems = mems; } else { tempMems = mems.filter(function(mem) { return mem[effectType] === 0; }); } break; case "immortal": tempMems = mems.filter(function(mem) { return mem.isStateResist(mem.deathStateId()); }); break; case "maxCntMrf": if (hitType === "pdr") { maxParam = mems.slice(0).sort(function(a, { return b.cnt - a.cnt; })[0].cnt; tempMems = mems.filter(function(mem) { return mem.cnt === maxParam; }); } else if (hitType === "mdr") { maxParam = mems.slice(0).sort(function(a, { return b.mrf - a.mrf; })[0].mrf; tempMems = mems.filter(function(mem) { return mem.mrf === maxParam; }); } else { tempMems = mems; } break; case "maxEvaMev": if (hitType === "pdr") { maxParam = mems.slice(0).sort(function(a, { return b.eva - a.eva; })[0].eva; tempMems = mems.filter(function(mem) { return mem.eva === maxParam; }); } else if (hitType === "mdr") { maxParam = mems.slice(0).sort(function(a, { return b.mev - a.mev; })[0].mev; tempMems = mems.filter(function(mem) { return mem.mev === maxParam; }); } else { tempMems = mems; } break; case "maxPdrMdr": if (hitType) { maxParam = mems.slice(0).sort(function(a, { return b[hitType] - a[hitType]; })[0][hitType]; tempMems = mems.filter(function(mem) { return mem[hitType] === maxParam; }); } else { tempMems = mems; } break; case "maxHpMp": if (effectType) { maxParam = mems.slice(0).sort(function(a, { return b[effectType] - a[effectType]; })[0][effectType]; tempMems = mems.filter(function(mem) { return mem[effectType] === maxParam; }); } else { tempMems = mems; } break; case "maxGrd": maxParam = mems.slice(0).sort(function(a, { return b.grd - a.grd; })[0].grd; tempMems = mems.filter(function(mem) { return mem.grd === maxParam; }); break; case "maxCev": maxParam = mems.slice(0).sort(function(a, { return b.cev - a.cev; })[0].cev; tempMems = mems.filter(function(mem) { return mem.cev === maxParam; }); break; default: console.log("Invalid substitute battler filter " + filter); tempMems = mems; } if (tempMems.length === 1) { return tempMems[0]; } if (tempMems.length > 1) { mems = tempMems; } } return mems[0]; // }; // Game_Unit.prototype.substituteBattler