Alter battlers plugin: http://kdworkshop.net/alter-battlers/
This file contains 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
//============================================================================= | |
// PKD_AlterBattler.js | |
//============================================================================= | |
// [Update History] | |
// v1.0 (18.01.2023) - release | |
/*: | |
* @plugindesc (v1.0) - Different images for enemies in battle | |
* @author Pheonix KageDesu | |
* @target MZ MV | |
* @url https://kdworkshop.net/alter-battlers/ | |
* @help | |
* [Description] | |
* | |
* This plugin allows you to add a level of randomization to the | |
* appearance of enemies in battle. Specifically, it allows you to | |
* assign multiple images to one enemy, and then have the game | |
* randomly select one of those images to be used when that enemy | |
* is encountered in battle. | |
* This can add an element of surprise and variety to encounters. | |
* | |
* Packages with alternative enemies images | |
* you can find here: https://kdworkshop.net/category/resources/ | |
* ------------------------- | |
* [Usage] | |
* | |
* Image name rules: | |
* [ORIGINAL]_alt(X).png | |
* | |
* Exapmle: | |
* Original image name: Goblin.png | |
* Alternatives: Goblin_alt1.png, Goblin_alt2.png, Goblin_alt3.png | |
* | |
* (Numbers should starts from 1) | |
* | |
* Add Note <alternatives:X> to Enemy Note that uses Goblin.png image | |
* Example: <alternatives:3> | |
* | |
* Or you can use Goblin_altX.png image if you don't want that | |
* default image (Goblin.png) appears in battle | |
* | |
* ------------------------ | |
* [Terms of Use] | |
* See at plugin web page | |
* https://kdworkshop.net/alter-battlers/ | |
* | |
* [Help] | |
* https://kdworkshop.net/discord-server/ | |
* | |
* [Support Author] | |
* https://www.patreon.com/KageDesu | |
* https://boosty.to/kagedesu | |
* | |
* | |
* | |
* @param keepOriginal | |
* @text Show original image? | |
* @type boolean | |
* @on Show | |
* @off No, only alt | |
* @desc Show original enemy image (without _altX) also? | |
* @default false | |
*/ | |
(function(){ | |
(function(){ | |
// * Load parameters | |
let parameters = PluginManager.parameters('PKD_AlterBattlers'); | |
let pIsShowOriginal = parameters.keepOriginal == 'true'; | |
window.PKD_AlterBattlers = {}; | |
window.PKD_AlterBattlers.pIsShowOriginal = pIsShowOriginal; | |
})(); | |
// Generated by CoffeeScript 2.6.1 | |
var AltManager, getValueFromMeta, hasMeta, isKeepOriginal, shuffleArray; | |
hasMeta = function(symbol, obj) { | |
return (obj != null) && (obj.meta != null) && (obj.meta[symbol] != null); | |
}; | |
getValueFromMeta = function(symbol, obj) { | |
if (!hasMeta(symbol, obj)) { | |
return null; | |
} | |
return obj.meta[symbol]; | |
}; | |
(function() { //╒═════════════════════════════════════════════════════════════════════════╛ | |
// ■ Game_Enemy.coffee | |
//╒═════════════════════════════════════════════════════════════════════════╛ | |
//--------------------------------------------------------------------------- | |
var ALIAS__battlerName, ALIAS__setup, _; | |
//@[DEFINES] | |
_ = Game_Enemy.prototype; | |
//@[ALIAS] | |
ALIAS__setup = _.setup; | |
_.setup = function() { | |
var e; | |
ALIAS__setup.call(this, ...arguments); | |
this._pAltImagesCount = null; | |
try { | |
this._pAltImagesCount = getValueFromMeta('alternatives', this.enemy()); | |
if (this._pAltImagesCount != null) { | |
this._pAltImagesCount = Number(this._pAltImagesCount); | |
} | |
} catch (error) { | |
e = error; | |
console.warn(e); | |
this._pAltImagesCount = null; | |
} | |
}; | |
//@[ALIAS] | |
ALIAS__battlerName = _.battlerName; | |
_.battlerName = function() { | |
var e; | |
if (this._pAltImagesCount > 0) { | |
try { | |
return this.pAltBattlerName(); | |
} catch (error) { | |
e = error; | |
console.warn(e); | |
return ALIAS__battlerName.call(this, ...arguments); | |
} | |
} else { | |
return ALIAS__battlerName.call(this, ...arguments); | |
} | |
}; | |
_.pAltBattlerName = function() { | |
var altBattlerName, nextAltIndex, originalBattleName; | |
if (this._pAltBattlerName == null) { | |
originalBattleName = ALIAS__battlerName.call(this); | |
// * Уже установлен альтернативный | |
if (originalBattleName.contains("_alt")) { | |
altBattlerName = originalBattleName.replace(/\d+$/, ""); | |
} else { | |
// * Стандартный | |
altBattlerName = originalBattleName + "_alt"; | |
} | |
nextAltIndex = $gameTemp.pGetAltManager().getNextIndex(originalBattleName, this._pAltImagesCount); | |
if (nextAltIndex <= 0) { | |
this._pAltBattlerName = originalBattleName; | |
} else { | |
this._pAltBattlerName = altBattlerName + nextAltIndex; | |
} | |
} | |
return this._pAltBattlerName; | |
}; | |
})(); | |
(function() { // ■ END Game_Enemy.coffee | |
//--------------------------------------------------------------------------- | |
//╒═════════════════════════════════════════════════════════════════════════╛ | |
// ■ Game_Troop.coffee | |
//╒═════════════════════════════════════════════════════════════════════════╛ | |
//--------------------------------------------------------------------------- | |
var ALIAS__clear, _; | |
//@[DEFINES] | |
_ = Game_Troop.prototype; | |
//@[ALIAS] | |
ALIAS__clear = _.clear; | |
_.clear = function() { | |
ALIAS__clear.call(this, ...arguments); | |
$gameTemp._pAltManager = null; | |
}; | |
})(); | |
(function() { // ■ END Game_Troop.coffee | |
//--------------------------------------------------------------------------- | |
//╒═════════════════════════════════════════════════════════════════════════╛ | |
// ■ Game_Temp.coffee | |
//╒═════════════════════════════════════════════════════════════════════════╛ | |
//--------------------------------------------------------------------------- | |
var _; | |
//@[DEFINES] | |
_ = Game_Temp.prototype; | |
_.pGetAltManager = function() { | |
if (!this._pAltManager) { | |
this._pAltManager = new AltManager(); | |
} | |
return this._pAltManager; | |
}; | |
})(); | |
// ■ END Game_Temp.coffee | |
//--------------------------------------------------------------------------- | |
isKeepOriginal = function() { | |
return window.PKD_AlterBattlers.pIsShowOriginal; | |
}; | |
shuffleArray = function(arr) { | |
var i, j, randomIndex, ref, temp; | |
if (arr.length <= 1) { | |
return arr; | |
} | |
for (i = j = 0, ref = arr.length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) { | |
randomIndex = Math.floor(Math.random() * arr.length); | |
temp = arr[i]; | |
arr[i] = arr[randomIndex]; | |
arr[randomIndex] = temp; | |
} | |
return arr; | |
}; | |
AltManager = class AltManager { | |
constructor() { | |
this._enemiesBattlerKeys = {}; | |
} | |
_isCanGetMoreFor(battlerName) { | |
if (this._enemiesBattlerKeys[battlerName] != null) { | |
return this._enemiesBattlerKeys[battlerName].length > 0; | |
} else { | |
return true; | |
} | |
} | |
_clearFor(battlerName, max) { | |
var i, j, ref, ref1, results, startIndex; | |
this._enemiesBattlerKeys[battlerName] = []; | |
if (isKeepOriginal()) { | |
startIndex = 0; | |
} else { | |
startIndex = 1; | |
} | |
results = []; | |
for (i = j = ref = startIndex, ref1 = max; (ref <= ref1 ? j <= ref1 : j >= ref1); i = ref <= ref1 ? ++j : --j) { | |
results.push(this._enemiesBattlerKeys[battlerName].push(i)); | |
} | |
return results; | |
} | |
getNextIndex(battlerName, max) { | |
var e; | |
try { | |
if (this._enemiesBattlerKeys[battlerName] != null) { | |
if (this._isCanGetMoreFor(battlerName)) { | |
this._enemiesBattlerKeys[battlerName] = shuffleArray(this._enemiesBattlerKeys[battlerName]); | |
return this._enemiesBattlerKeys[battlerName].shift(); | |
} else { | |
this._clearFor(battlerName, max); | |
return this.getNextIndex(battlerName); | |
} | |
} else { | |
this._clearFor(battlerName, max); | |
return this.getNextIndex(battlerName); | |
} | |
} catch (error) { | |
e = error; | |
console.warn(e); | |
} | |
return 0; | |
} | |
}; | |
(function() { //╒═════════════════════════════════════════════════════════════════════════╛ | |
// ■ Scene_Battle.coffee | |
//╒═════════════════════════════════════════════════════════════════════════╛ | |
//--------------------------------------------------------------------------- | |
var ALIAS__terminate, _; | |
//@[DEFINES] | |
_ = Scene_Battle.prototype; | |
//@[ALIAS] | |
ALIAS__terminate = _.terminate; | |
_.terminate = function() { | |
ALIAS__terminate.call(this, ...arguments); | |
$gameTemp._pAltManager = null; | |
}; | |
})(); | |
// ■ END Scene_Battle.coffee | |
//--------------------------------------------------------------------------- | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment