Advertisement
Zalerinian

ZE - Character Poses

Dec 4th, 2015
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2.  * @plugindesc Allows actor and event sprites to have different poses. These are controlled by plugin commands.
  3.  * <pluginID ZE - Character Poses>
  4.  * @author Zalerinian
  5.  *
  6.  * @param Dash Pose
  7.  * @desc When dashing, this pose will be set. Default: [dsh]
  8.  * @default [dsh]
  9.  *
  10.  * @param Jump Pose
  11.  * @desc When jumping, this pose will be set. Default: [jmp]
  12.  * @default [jmp]
  13.  *
  14.  * @param Adaptive Filenames
  15.  * @desc Please see help. Default: false
  16.  * @default false
  17.  *
  18.  * @param Restrict Auto Pose
  19.  * @desc Only change poses for jumping, etc for the player. Default: true
  20.  * @default true
  21.  *
  22.  * @param Enable Multi Frame
  23.  * @desc Enables the plugin to work with Shaz's MoreCharacterFrames plugin. Please see help. Default: false
  24.  * @default false
  25.  *
  26.  * @help
  27.  * ==============================================================================
  28.  *    Support
  29.  * ==============================================================================
  30.  *
  31.  * Have an issue, question, or suggestion? My preferred method of contact would
  32.  * be on the RMW forums, preferably by posing in one of my topics, but if you
  33.  * really need to reach me directly, feel free to PM me, or send me an email
  34.  * using the address below.
  35.  *
  36.  * Author: Zalerinian
  37.  * email: support at razelon.com
  38.  *
  39.  * ==============================================================================
  40.  *    Introduction
  41.  * ==============================================================================
  42.  *
  43.  * ZE - Character Frames allows you to have different character graphics for
  44.  * different actions in the game. It's easier than just setting the character
  45.  * image in an event, and it also allows other plugins to use the pose system to
  46.  * automatically change events or actor's appearances based on the action
  47.  * currently taking place.
  48.  *
  49.  * This plugin will not crash or break down when loading it into an old save
  50.  * file. It aliases the extractSaveContents function of DataManager to add in the
  51.  * needed information, if it is not already there.
  52.  *
  53.  * ==============================================================================
  54.  *    Parameters
  55.  * ==============================================================================
  56.  *
  57.  * Adaptive Filenames
  58.  * ------------------------------------------------------------------------------
  59.  *
  60.  * If this setting is enabled, we will try to match the pose name partially. This
  61.  * means that if only certain poses have multiple frames, then this will try to
  62.  * match those files.
  63.  *
  64.  * Please note that this feature requires the ZE - File List plugin, which
  65.  * maintains a list of all files in the project.
  66.  *
  67.  * Enable Multi Frame
  68.  * ------------------------------------------------------------------------------
  69.  *
  70.  * If this parameter is set to true, instead of directly editing the character's
  71.  * image file, this will call the old, aliased version of setImage. The reason
  72.  * that this feature must be enabled is that by default, setImage will clear the
  73.  * current pose. By calling the alias of the function directly, the pose is not
  74.  * reset, and any changes to setImage in plugins before this will take affect.
  75.  *
  76.  * Please Note: Any changes in setImage will NOT take affect when changing the
  77.  * character's poses if the changes are made in plugins loaded AFTER Character
  78.  * Poses. In order for those changes to take affect when changing character
  79.  * poses with Mutli Frame support, you must place those plugins above this one.
  80.  *
  81.  * ==============================================================================
  82.  *    Plugin Commands
  83.  * ==============================================================================
  84.  *
  85.  * To interact with this plugin via events and plugin commands, we'll be using
  86.  * the CharacterPose, or CharPose, command. Either form is acceptable, and are
  87.  * case-insensitive.
  88.  *
  89.  *
  90.  * There are several different ways to interact with a character's poses.
  91.  *  * Set
  92.  *  * Add
  93.  *  * Play
  94.  *  * Queue
  95.  *  * Loop
  96.  *  * QueueLoop
  97.  *  * Remove
  98.  *  * Clear / Reset
  99.  *
  100.  * The general format for plugin commands is CharPose mode type id pose, where
  101.  *
  102.  * Mode is one of the above commands.
  103.  *
  104.  * Type is "actor", "ev", or "event".
  105.  * 'ev' and 'event' both target events on the map, while 'actor' targets the
  106.  * player's party.
  107.  *
  108.  * ID is the event's ID, as seen in the editor, or the party member's index.
  109.  * Actor IDs start at 0, indicating the party leader, while Event IDs start at 1.
  110.  *
  111.  * There are several ways to define IDs:
  112.  * A single number will indicate one event or actor.
  113.  * A number range, such as 5-8, will apply the change to all events or actors in
  114.  *  that range. The range is inclusive.
  115.  * A list of IDs, separated by commas, such as 1,2,3,4,5. Please note that these
  116.  *  cannot be separated by a space.
  117.  * A game variable can be used by using v[id], where id is the variable's ID.
  118.  *  This is referred to as 'variable notation'.
  119.  *  If the value of a game variable is an array, it will be treated as a list of
  120.  *  IDs.
  121.  *
  122.  * Pose the pose we want to set, add, play, loop, queue, remove, etc.
  123.  * The pose CAN contain spaces. The pose can be any string of characters, but it
  124.  * is generally recommended that poses are wrapped in square brackets ([]).
  125.  *
  126.  *
  127.  * For the Loop and QueueLoop modes, an additional value is needed, to indicate
  128.  * number of times the pose should loop. The format for these commands is
  129.  * CharPose mode loops type id pose.
  130.  *
  131.  * loops < 0 indicates that the pose will loop infinitely, until manually
  132.  * changed.
  133.  * loops == 0 indicates that the pose will be cleared, and the last pose will be
  134.  * reset onto the target.
  135.  * loops > 0 indicates how many times that pose will be looped before it is
  136.  * stopped.
  137.  *
  138.  *
  139.  * Set
  140.  * ------------------------------------------------------------------------------
  141.  *
  142.  * Setting a pose is the most basic way of doing things. This will clear out the
  143.  * current pose that's playing, and favor the supplied pose instead. All other
  144.  * pose modes will internally call this to change the pose.
  145.  *
  146.  * Examples:
  147.  *
  148.  * To set the party leader's pose to "[dsh]", use:
  149.  * CharPose set actor 0 [dsh]
  150.  *
  151.  * To set the pose for events in the range 4 through 12 to [sit], use:
  152.  * CharPose set event 4-12 [sit]
  153.  *
  154.  * To set the pose of an actor whose ID is in variable 2 to [walk], use:
  155.  * CharPose set actor v[2] [walk]
  156.  *
  157.  * Add
  158.  * ------------------------------------------------------------------------------
  159.  *
  160.  * The given pose will be appended to the current pose. This will check to make
  161.  * sure that the current pose is not the one being added.
  162.  *
  163.  * Examples:
  164.  *
  165.  * To add the [dsh] pose to the party leader, use:
  166.  * CharPose add actor 0 [dsh]
  167.  *
  168.  *
  169.  * To add the [fly] pose to event 7, use:
  170.  * CharPose add ev 7 [fly].
  171.  *  * Remember, both 'ev' and 'event' refer to events on the map!
  172.  *
  173.  *
  174.  * Play
  175.  * ------------------------------------------------------------------------------
  176.  *
  177.  * Sets the pose on the character (Sets, not adds), and prevents the character
  178.  * moving. If you want to allow the character to move while playing a pose,
  179.  * you'll need to use set.
  180.  *
  181.  * Examples:
  182.  *
  183.  * To have event 1 play the [hit] pose, use:
  184.  * CharPose play event 1 [hit]
  185.  *
  186.  * To have the 1st follower play the [nod] pose, use:
  187.  * CharPose play actor 1 [nod]
  188.  *
  189.  * Queue
  190.  * ------------------------------------------------------------------------------
  191.  *
  192.  * Adds the pose to the pose queue. If the queue was empty before this call, it
  193.  * will be played immediately. If not, it will be added to the queue to be
  194.  * played when its turn comes. This will only queue a pose to be played once
  195.  * before it will stop. To queue a pose to play more than once, use QueueLoop.
  196.  *
  197.  * Examples:
  198.  *
  199.  * To queue the [charge] pose on events 4, 7, 8, and 11, use:
  200.  * Charpose queue ev 4,7,8,11 [charge]
  201.  *
  202.  * To queue the [fall] pose on event 3, use:
  203.  * CharPose queue event 3 [fall]
  204.  *
  205.  * Loop
  206.  * ------------------------------------------------------------------------------
  207.  *
  208.  * NOTICE: The Loop and QueueLoop commands have a slightly different format,
  209.  * because you need to specify how many loops the pose should do. The modified
  210.  * format is:
  211.  *
  212.  * CharPose loop <loops> <type> <id> <pose>, where <loops> should be replaced by
  213.  * the number of loops, or variable notation.
  214.  *
  215.  *
  216.  * Sets the pose on the character, and prevents the character from moving. Unlike
  217.  * play, this allows a pose to be looped instead of just running once. You can
  218.  * specify the number of loops to perform. 0 or below will loop infinitely, while
  219.  * any number above 0 will make the pose loop that many times.
  220.  *
  221.  * loops < 0: Loop until manually cleared.
  222.  * 0: clears loop
  223.  * loops > 0: Loops the specified number of times.
  224.  *
  225.  *
  226.  * Sometimes, though, you want to get a value from a variable for the number of
  227.  * loops to do. In order to get a value from a variable, instead of specifying a
  228.  * number for the use the format v[#], where # is the Variable ID. The V is
  229.  * case-insensitive. Variable values follow the same rules as directly inputting
  230.  * a number. 0 and below results in an infinite loop, anything higher than 0 will
  231.  * loop that many times.
  232.  *
  233.  *
  234.  * Examples:
  235.  *
  236.  * To loop the [tired] pose 5 times on event 12, use:
  237.  * CharPose loop 5 ev 12 [tired]
  238.  *
  239.  * To infinitely loop the [sleep] pose on event 3 until manually changes, use:
  240.  * CharPose loop -1 ev 3 [sleep]
  241.  *
  242.  * To stop a loop on the party leader, and to return to the pose that was played
  243.  * before this, use:
  244.  * CharPose loop 0 actor 0
  245.  *
  246.  * QueueLoop
  247.  * ------------------------------------------------------------------------------
  248.  *
  249.  * NOTICE: The Loop and QueueLoop commands have a slightly different format,
  250.  * because you need to specify how many loops the pose should do. The modified
  251.  * format is:
  252.  *
  253.  * CharPose queueloop <loops> <type> <id> <pose>, where <loops> should be
  254.  * replaced by the number of loops, or variable notation.
  255.  *
  256.  *
  257.  * Just like queue, this will set the given pose to be played when it is able to.
  258.  * The difference, however, is that you must not specify the number of loops you
  259.  * want it to do. If you don't specify a number, an error will be thrown.
  260.  *
  261.  * Examples:
  262.  *
  263.  * To queue the [sing] pose to loop 4 times on the 2nd follower, use:
  264.  * CharPose QueueLoop 4 actor 2 [sing]
  265.  *
  266.  * To queue the [talk] pose to loop twice on event 10, use:
  267.  * CharPose QueueLoop 2 event 10 [talk]
  268.  *
  269.  * Remove
  270.  * ------------------------------------------------------------------------------
  271.  *
  272.  * This will remove the specified pose from the character. Please note, this will
  273.  * only work if the pose you want to remove is on the END of the list. If you
  274.  * want to remove multiple poses at once, you can put them all in one composite
  275.  * plugin command, but keep in mind that the new pose still has to exist as a
  276.  * file, or the character will disappear and an error will be thrown on the next
  277.  * scene change.
  278.  *
  279.  * Examples:
  280.  *
  281.  * To remove the [jmp] pose from the party leader and first 2 followers, use:
  282.  * CharPose remove actor 0-2 [jmp]
  283.  *
  284.  * To remove the [sit] pose from event 4, use:
  285.  * CharPose remove event 4 [sit]
  286.  *
  287.  * Clear / Reset
  288.  * ------------------------------------------------------------------------------
  289.  *
  290.  * This will remove all poses from the character, and set them back to their
  291.  * default sprites.
  292.  *
  293.  * Examples:
  294.  *
  295.  * To rest the party leader back to their base sprite, use:
  296.  * CharPose clear actor 0
  297.  */
  298.  
  299.  (function() {
  300.   if(Imported.MVCommons && PluginManager.version("MVCommons", ">=", "1.5.0")) {
  301.     var author = [{
  302.       email: "support@razelon.com",
  303.       name: "Zalerinian",
  304.       website: "http://www.razelon.com"
  305.       }];
  306.     var v = PluginManager.register("ZE - Character Poses", "1.1.1", PluginManager.getBasicPlugin("ZE - Character Poses").description, author, "2015-12-05");
  307.     if (v === false){
  308.       PluginManager.printPlugin("ZE - Character Poses");
  309.       throw new Error("Unable to load ZE - Character Poses due to registration failure! Is there another version running?");
  310.     }
  311.   } else {
  312.     throw new Error("ZE - Character Poses requires the MVCommons plugin, version 1.5.0 or higher");
  313.   }
  314. })();
  315.  
  316. var Imported = Imported || {};
  317. var Zale = Zale || {};
  318. Zale.CharPose = {};
  319.  
  320. (function(){
  321.   var params = PluginManager.parameters("ZE - Character Poses");
  322.   Zale.CharPose.PARAMS   = params;
  323.   Zale.CharPose.DASHPOSE = params["Dash Pose"];
  324.   Zale.CharPose.JUMPPOSE = params["Jump Pose"];
  325.   Zale.CharPose.ADAPTIVE = MVC.Boolean(params["Adaptive Filenames"]);
  326.   Zale.CharPose.RESTRICT = MVC.Boolean(params["Restrict Auto Pose"]);
  327.   Zale.CharPose.MULTIFRM = MVC.Boolean(params["Enable Multi Frame"]);
  328.  
  329.   /*
  330.    * Game_Interpreter.prototype._charposeGetLoops(str)
  331.    * @param {String} str The string indicating loop settings.
  332.    * @note
  333.    * This function interprets the give string and returns the number of loops the
  334.    * pose will perform. If no loop count could be found, an error is thrown.
  335.    *
  336.    * This function only supports variable notation (v[id]), and directly
  337.    * inserting a number for how many loops to do.
  338.    *
  339.    * @return {Number} The number of loops.
  340.    */
  341.   Game_Interpreter.prototype._charposeGetLoops = function(str) {
  342.     var tmp;
  343.     if(tmp = str.match(/v\[(\d+)\]/i)) {
  344.       return $gameVariables.value(Number(tmp[1]));
  345.     } else if(tmp = str.match(/(\d+)/)) {
  346.       return Number(tmp[1]);
  347.     } else {
  348.       throw new Error("No number of loops specified for " + mode + " pose change.<br/>\nev" + this._eventId + ":" + this._index);
  349.     }
  350.   }
  351.  
  352.   /*
  353.    * Game_Interpreter.prototype._charposeGetID(str)
  354.    * @param {String} str The string indicating character ID settings.
  355.    * @note
  356.    * This function interprets the give string and returns an array of IDs that
  357.    * the current pose change should affect.
  358.    *
  359.    * This function supports variable notation (v[id]), range notation (1-5),
  360.    * comma notation (1,2,3,4,5), and directly inserting an ID to use.
  361.    *
  362.    * With variable notation, if the value received is an array already, it is
  363.    * returned as-is, assuming that it is properly formatted as all ID numbers.
  364.    * If the variable is not an array, it is returned as it is in a new array.
  365.    *
  366.    * If no ID format could be found, an error is thrown.
  367.    *
  368.    * @return {Array} An array of IDs to act on.
  369.    */
  370.   Game_Interpreter.prototype._charposeGetID = function(str) {
  371.     var tmp;
  372.     if(tmp = str.match(/v\[(\d+)\]/i)) {
  373.       var v = $gameVariables.value(Number(tmp[1]));
  374.       if(MVC.isArray(v)) {
  375.         return v;
  376.       }
  377.       return [$gameVariables.value(Number(tmp[1]))];
  378.     } else if(tmp = str.match(/(\d+)-(\d+)/)) {
  379.       var ret = [];
  380.       for(var i = Number(tmp[1]); i <= Number(tmp[2]); i++) {
  381.         ret.push(i);
  382.       }
  383.       return ret;
  384.     } else if(tmp = str.match(/,/)) {
  385.       return str.split(',').map(function(v) {
  386.         return Number(v);
  387.       })
  388.     } else if(tmp = str.match(/(\d+)/)) {
  389.       return [Number(tmp[1])];
  390.     } else {
  391.       throw new Error("No target ID specified for " + mode + " pose change.<br/>\nev" + this._eventId + ":" + this._index);
  392.     }
  393.   }
  394.  
  395.   /*
  396.    * Game_Interpreter.prototype.pluginCommand(cmd, args)
  397.    * @param {String} cmd The command identifier.
  398.    * @param {Array} args An array of strings indicating command parameters.
  399.    * @note
  400.    * This function is the main point of interaction for the plugin. It will
  401.    * ensure that the command is CharPose, or CharacterPose, case-insensitive,
  402.    * and from there all required information is pulled from the arguments.
  403.    *
  404.    * In order to support affecting multiple characters at one time, the code that
  405.    * actually changes poses is in a for loop, and the characters are changed in
  406.    * reverse order of that from the array. This is to reduce the number of times
  407.    * 'ids.length' is called, as that is a function call that will slightly
  408.    * increase run time per loop. Going backwards allows us to avoid this.
  409.    *
  410.    * If a valid target could not be selected, an error is thrown.
  411.    *
  412.    */
  413.   Zale.CharPose.GI_pcmd_IOnabqiuABXZCV4w = Game_Interpreter.prototype.pluginCommand;
  414.   Game_Interpreter.prototype.pluginCommand = function(cmd, args) {
  415.     if(cmd.match(/Char(?:acter)?Pose/i)) {
  416.       var command = cmd + " " + args.join(" ");
  417.       var tmp    = "";
  418.       var mode   = args.shift().toLowerCase();
  419.       var loops  = 0;
  420.       if(["loop", "queueloop"].contains(mode)) {
  421.         loops = this._charposeGetLoops(args.shift())
  422.       }
  423.       if(loops < 0) {
  424.         console.warn("An infinite pose loop has been started by Event " + this._eventId + ", line " + this._index);
  425.       }
  426.       var ttype  = args.shift();
  427.       var ids    = this._charposeGetID(args.shift());
  428.       var pose   = args.join(" ");
  429.       for(var i = ids.length - 1; i >= 0; i--) {
  430.         var target = null;
  431.         var id = ids[i] - 1;
  432.         if(ttype.match(/ev(?:ent)?/i)){
  433.           target = $gameMap.events()[id];
  434.           ttype = "Event";
  435.         } else if(ttype.match(/actor/i)) {
  436.           target = [$gamePlayer].concat($gamePlayer.followers().visibleFollowers())[id];
  437.           ttype = "Actor";
  438.         }
  439.         if(!target) {
  440.           throw new Error("Invalid target! Event: " + this._eventId + ":" + this._index + ". Command: " + command + "<br/>\nMode: " + mode + " | ID: " + id + " | Pose: \'" + pose + "\' | Target: " + target + " | Target Type: " + ttype);
  441.         }
  442.         switch(mode) {
  443.           case "add":
  444.             target.addPose(pose);
  445.             break;
  446.           case "remove":
  447.             target.removePose(pose);
  448.             break;
  449.           case "play":
  450.             target.playPose(pose);
  451.             break;
  452.           case "queue":
  453.             target.queuePose({pose: pose, loop: 1});
  454.             break;
  455.           case "loop":
  456.             target.loopPose({pose: pose, loops: loops});
  457.             break;
  458.           case "queueloop":
  459.             target.queuePose({pose: pose, loops: loops});
  460.             break;
  461.           case "clear":
  462.           case "reset":
  463.             target.clearPose();
  464.             break;
  465.           case "set":
  466.           default:
  467.             target.setPose(pose);
  468.             break;
  469.         }
  470.       }
  471.     }
  472.     Zale.CharPose.GI_pcmd_IOnabqiuABXZCV4w.call(this, cmd, args);
  473.   }
  474.  
  475.   /*
  476.    * DataManager.extractSaveContents(contents)
  477.    * @param {Object} contents The JS object that has all the sae data.
  478.    * @note
  479.    * This function has been aliased to allow the plugin to fix itself when the
  480.    * plugin is installed in a game, and then used with new saves. We don't need
  481.    * to worry about updating all the map events to support the new data, because
  482.    * part of Scene_Load checks an internal version ID that's stored in
  483.    * $gameSystem, and if the ID in $dataSystem is different than that of
  484.    * $gameSystem, then the whole map is reloaded to ensure we aren't missing any
  485.    * data (Because the map you save on is stored in the save file as well).
  486.    */
  487.   Zale.CharPose.DM_extractSaveContents = DataManager.extractSaveContents;
  488.   DataManager.extractSaveContents = function(contents) {
  489.     Zale.CharPose.DM_extractSaveContents.call(this, contents);
  490.     if($gamePlayer._currentPose === undefined) {
  491.       $gamePlayer._currentPose  = "";
  492.       $gamePlayer._originalName = "";
  493.       $gamePlayer._lastPose     = "";
  494.       $gamePlayer._poseQueue    = [];
  495.       $gamePlayer._loopCount    = 0;
  496.       $gamePlayer._posePlaying  = false;
  497.       $gamePlayer._poseLooping  = false;
  498.     }
  499.   }
  500.  
  501.  
  502.   /*
  503.    * Game_CharacterBase.prototype.isMoving()
  504.    * @note
  505.    * This function was aliased to return true if a pose is currently being played
  506.    * for the current character. This both ensure that the character's pattern is
  507.    * updated, and also that the character cannot move until the pose is finished
  508.    * playing.
  509.    */
  510.   Zale.CharPose.GCB_ismov_BOivqicb42c = Game_CharacterBase.prototype.isMoving;
  511.   Game_CharacterBase.prototype.isMoving = function() {
  512.     if(this._posePlaying) {
  513.       return true;
  514.     } else {
  515.       return Zale.CharPose.GCB_ismov_BOivqicb42c.call(this);
  516.     }
  517.   }
  518.  
  519.   /*
  520.    * Game_CharacterBase.prototype.initMembers()
  521.    * @note
  522.    * This function is aliased in order to add in variables to each character so
  523.    * that we may properly track and update the poses each character will have.
  524.    */
  525.   Zale.CharPose.GCB_initm_IONCOIEvbiehrewih = Game_CharacterBase.prototype.initMembers;
  526.   Game_CharacterBase.prototype.initMembers = function() {
  527.     Zale.CharPose.GCB_initm_IONCOIEvbiehrewih.call(this);
  528.     this._currentPose  = "";
  529.     this._originalName = "";
  530.     this._lastPose     = "";
  531.     this._poseQueue    = [];
  532.     this._loopCount    = 0;
  533.     this._posePlaying  = false;
  534.     this._poseLooping  = false;
  535.   }
  536.  
  537.   /*
  538.    * Game_CharacterBase.prototype.setImage(cname, cindex)
  539.    * @param {String} cname The image name for the character sheet.
  540.    * @param {Number} cindex The index of the character on the spritesheet.
  541.    * @note
  542.    * This function is aliased so that when the character's image is set, all pose
  543.    * information is cleared, as the character's base has changed.
  544.    */
  545.   Zale.CharPose.GCB_simg_NVbe8vhll = Game_CharacterBase.prototype.setImage;
  546.   Game_CharacterBase.prototype.setImage = function(cname, cindex) {
  547.     Zale.CharPose.GCB_simg_NVbe8vhll.call(this, cname, cindex);
  548.     this._originalName = cname;
  549.     this._currentPose  = "";
  550.     this._lastPose     = "";
  551.     this._poseQueue    = [];
  552.     this._loopCount    = 0;
  553.     this._posePlaying  = false;
  554.     this._poseLooping  = false;
  555.   }
  556.  
  557.   /*
  558.    * Game_CharacterBase.prototype.updatePattern()
  559.    * @note
  560.    * This function was aliased to allow us to check when a pose has run one
  561.    * complete animation. By using isOriginalPattern, we are more likely to be
  562.    * compatible with other plugins that change how the spritesheets work, such
  563.    * as Shaz' MoreCharacterFrames plugin.
  564.    *
  565.    * This is also where we check out loop counters, and decrease it if necessary.
  566.    */
  567.   Zale.CharPose.GCB_upattern_Qhdn19vbejA = Game_CharacterBase.prototype.updatePattern;
  568.   Game_CharacterBase.prototype.updatePattern = function() {
  569.     Zale.CharPose.GCB_upattern_Qhdn19vbejA.call(this);
  570.     if(this.isOriginalPattern() && this._posePlaying && (this._isMultiFrame || !this._isMultiFrame && this._pattern !== 3)) {
  571.       if(!this._poseLooping || this._posePlaying && this._loopCount === 0) {
  572.         this.setPose(this._lastPose);
  573.         this.checkPoseQueue();
  574.       }
  575.       if(this._loopCount > 0) {
  576.         --this._loopCount;
  577.       }
  578.     }
  579.   }
  580.  
  581.   /*
  582.    * Game_CharacterBase.prototype.updateStop()
  583.    * This function is aliased to remove the dash pose if we're stopped moving.
  584.    * This will only take affect if the Restrict setting is false or the setting
  585.    * is true and this object is a Game_Player, and if the current pose is the
  586.    * dashing pose.
  587.    */
  588.   Zale.CharPose.GCB_ustop_BXovinocwio49c = Game_CharacterBase.prototype.updateStop;
  589.   Game_CharacterBase.prototype.updateStop = function() {
  590.     Zale.CharPose.GCB_ustop_BXovinocwio49c.call();
  591.     if((!Zale.CharPose.RESTRICT || Zale.CharPose.RESTRICT && this instanceof Game_Player) && this.poseIs(Zale.CharPose.DASHPOSE)) {
  592.       this.removePose(Zale.CharPose.DASHPOSE);
  593.     }
  594.   }
  595.  
  596.   /*
  597.    * Game_CharacterBase.prototype.jump(xp, yp)
  598.    * @param {Number} xp The addition to the X coordinate.
  599.    * @param {Number} yp The addition to the Y coordinate.
  600.    * @note
  601.    * Similar to updateStop, but this function will add the jump pose if the
  602.    * conditions allow.
  603.    */
  604.   Zale.CharPose.GCB_jump_IObinbqdoif = Game_CharacterBase.prototype.jump;
  605.   Game_CharacterBase.prototype.jump = function(xp, yp) {
  606.     Zale.CharPose.GCB_jump_IObinbqdoif.call(this, xp, yp);
  607.     if(!Zale.CharPose.RESTRICT || Zale.CharPose.RESTRICT && this instanceof Game_Player) {
  608.       this.setPose(Zale.CharPose.JUMPPOSE);
  609.     }
  610.   }
  611.  
  612.   /*
  613.    * Game_CharacterBase.prototype.updateJump()
  614.    * @note
  615.    * Also similar to updateStop, this function will remove the jump pose if the
  616.    * conditions apply.
  617.    */
  618.   Zale.CharPose.GCB_ujump_Bve9b42o9chnq = Game_CharacterBase.prototype.updateJump;
  619.   Game_CharacterBase.prototype.updateJump = function() {
  620.     Zale.CharPose.GCB_ujump_Bve9b42o9chnq.call(this);
  621.     if((!Zale.CharPose.RESTRICT || Zale.CharPose.RESTRICT && this instanceof Game_Player) && this._jumpCount === 0) {
  622.       this.removePose(Zale.CharPose.JUMPPOSE);
  623.     }
  624.   }
  625.  
  626.   /*
  627.    * Game_CharaterBase.prototype.updateMove()
  628.    * @note
  629.    * This function was aliased to both add and remove the dash pose for a
  630.    * character, depending on whether or not they're dashing or not. As with other
  631.    * functions, this is subject to the Restrict setting for only allowing the
  632.    * player to change poses automatically.
  633.    */
  634.   Zale.CharPose.GCB_umove_Bc99eboiufg = Game_CharacterBase.prototype.updateMove;
  635.   Game_CharacterBase.prototype.updateMove = function() {
  636.     Zale.CharPose.GCB_umove_Bc99eboiufg.call(this);
  637.     if(!Zale.CharPose.RESTRICT || Zale.CharPose.RESTRICT && this instanceof Game_Player) {
  638.       if(this.isMoving()) {
  639.         if(this.isDashing()) {
  640.           this.setPose(Zale.CharPose.DASHPOSE);
  641.         } else {
  642.           this.removePose(Zale.CharPose.DASHPOSE);
  643.         }
  644.       }
  645.     }
  646.   }
  647.  
  648.   /*
  649.    * Game_CharacterBase.prototype.poseIs(pose)
  650.    * @param {String} pose The pose to check for
  651.    * @note
  652.    * This function will take the given pose, and return true if that is he last
  653.    * pose on the current list. Keep in mind that checking if the pose ends with
  654.    * an empty string, i.e. "" or '', will return true for any value.
  655.    */
  656.   Game_CharacterBase.prototype.poseIs = function(pose) {
  657.     return this._currentPose.endsWith(pose);
  658.   }
  659.  
  660.   /*
  661.    * Game_CharacterBase.prototype.setPose(pose)
  662.    * @param {String} pose The pose to set the character to
  663.    * @note
  664.    * This function is the main one, and is internally called by all others. This
  665.    * function takes into consideration a few things to ensure compatibility, and
  666.    * functionality.
  667.    * As noted in it's description in the Help Text, the adaptive filename feature
  668.    * will only work if the ZE - File List plugin is included in the game. As long
  669.    * as the pose we want to set to isn't empty, the adaptive filenames feature
  670.    * will try it's best to match the character's original name and new pose with
  671.    * an existing image file. If the search didn't return any results, we fall
  672.    * back to using the character's current name and new pose as their image.
  673.    *
  674.    * The reason we have the Enable Multi Frame parameter is because the setImage
  675.    * function was aliased and changed to reset all pose information when set.
  676.    * However, that's also where Shaz' MoreCharacterFrames plugin sets up its
  677.    * data. Rather than just building in compatibility with that plugin alone, I
  678.    * opted to have this function call the alias of setImage, which is the
  679.    * function as it worked before this plugin was loaded in. This allows us to
  680.    * still use the changes people made before us, without resetting the pose
  681.    * data.
  682.    *
  683.    * And then finally we just clear some flags and set the current pose to the
  684.    * one we're currently on.
  685.    */
  686.   Game_CharacterBase.prototype.setPose = function(pose) {
  687.     if(pose !== this._currentPose && (!this.poseIs(pose) || pose === "")) {
  688.       this._lastPose = this._currentPose;
  689.       var img = this._originalName;
  690.       if(Zale.CharPose.ADAPTIVE && Imported["ZE - File List"] && FileList._list) {
  691.         if(pose !== "") {
  692.           var regex = new RegExp("characters\/" + this._originalName.escape() + "[\\-\\[\\]\+A-Za-z0-9 ]*" + pose.escape(), "i");
  693.           var img = FileList.scanWithPath(regex);
  694.           if(MVC.isArray(img) && img.length === 0){
  695.             img = this._originalName + pose
  696.           } else {
  697.             img = img[0].basename(".png");
  698.           }
  699.         }
  700.       } else {
  701.         img = this._originalName + pose;
  702.       }
  703.       if(Zale.CharPose.MULTIFRM) {
  704.         Zale.CharPose.GCB_simg_NVbe8vhll.call(this, img, this._characterIndex);
  705.       } else {
  706.         this._characterName = img;
  707.       }
  708.       this._currentPose = pose;
  709.       this._posePlaying = false;
  710.       this._poseLooping = false;
  711.       this._loopCount   = 0;
  712.     }
  713.   }
  714.  
  715.   /*
  716.    * Game_CharacterBase.prototype.addPose(pose)
  717.    * @param {String} pose The pose to add onto the character
  718.    * @note
  719.    * This function takes the given pose and appends it onto the character's
  720.    * current pose, rather than setting the whole thing directly. This will make
  721.    * sure that the current pose is not already the one we're adding, so as to not
  722.    * duplicate the current pose.
  723.    */
  724.   Game_CharacterBase.prototype.addPose = function(pose) {
  725.     if(!this.poseIs(pose)) {
  726.       this.setPose(this._currentPose + pose);
  727.     }
  728.   }
  729.  
  730.   /*
  731.    * Game_CharacterBase.prototype.removePose(pose)
  732.    * @param {String} pose The pose to remove.
  733.    * @note
  734.    * This function will remove the given pose from the current pose. This will
  735.    * not make sure that the new pose exists. If it doesn't, the character will be
  736.    * assigned an empty sprite automatically, and will appear to has vanished.
  737.    * Additionally, since this results in a bitmap not loading properly, going
  738.    * to the menu scene will crash the game when it check for errors in the
  739.    * ImageManager.
  740.    *
  741.    * I had considered making an error handler for the Bitmap class, and removing
  742.    * the error should this occur, but have not implemented it. If there is a need
  743.    * for it later on, I can add it in, but for now it is not included.
  744.    *
  745.    * @return The new pose, or null if the pose couldn't be removed.
  746.    */
  747.   Game_CharacterBase.prototype.removePose = function(pose) {
  748.     if(this._currentPose.lastIndexOf(pose) >= 0) {
  749.       this.setPose(this._currentPose.splice(this._currentPose.lastIndexOf(pose), pose.length));
  750.       return this._currentPose;
  751.     }
  752.     return null;
  753.   }
  754.  
  755.   /*
  756.    * Game_CharacterBase.prototype.clearPose()
  757.    * @note
  758.    * this function will clear the pose by setting it to an empty string.
  759.    */
  760.   Game_CharacterBase.prototype.clearPose = function() {
  761.     this.setPose("");
  762.   }
  763.  
  764.   /*
  765.    * Game_CharacterBase.prototype.clearPoseQueue()
  766.    * @note
  767.    * This function clears the pose queue by setting it back to an empty array.
  768.    */
  769.   Game_CharacterBase.prototype.clearPoseQueue = function() {
  770.     this._poseQueue = [];
  771.   }
  772.  
  773.   /*
  774.    * Game_CharacterBase.prototype.queuePose(poseObj)
  775.    * @param {Object} poseObj A JS object with 'pose' and 'loops' properties.
  776.    * @note
  777.    * This function will add the given pose object to the queue, and then call the
  778.    * checkPoseQueue function if no pose is currently playing.
  779.    */
  780.   Game_CharacterBase.prototype.queuePose = function(poseObj) {
  781.     this._poseQueue.push(poseObj);
  782.     if(!this._posePlaying) {
  783.       this.checkPoseQueue();
  784.     }
  785.   }
  786.  
  787.   /*
  788.    * Game_CharacterBase.prototype.poseQueueEmpty()
  789.    * @note
  790.    * This function will return true if the pose queue is empty.
  791.    * @return {Boolean} Whether or not the pose queue is emtpy.
  792.    */
  793.   Game_CharacterBase.prototype.poseQueueEmpty = function() {
  794.     return this._poseQueue.length === 0;
  795.   }
  796.  
  797.   /*
  798.    * Game_CharacterBase.prototype.checkPoseQueue()
  799.    * @note
  800.    * This function will check if the the pose queue is empty. If it isn't, the
  801.    * first pose in the list will be taken out, and sent to loopPose. Keep in
  802.    * mind, the pose queue is based on First In, First Out (FIFO).
  803.    */
  804.   Game_CharacterBase.prototype.checkPoseQueue = function() {
  805.     if(!this.poseQueueEmpty()) {
  806.       var pose = this._poseQueue.shift();
  807.       this.loopPose(pose.pose, pose.loops);
  808.     }
  809.   }
  810.  
  811.   /*
  812.    * Game_CharacterBase.prototype.playPose(pose)
  813.    * @param {String} pose The pose to play.
  814.    * @note
  815.    * This will set the character's pose to the one given to this function, and
  816.    * then set some flags to indicate that this pose is being played. The
  817.    * character will not be able to move until the pose is complete.
  818.    */
  819.   Game_CharacterBase.prototype.playPose = function(pose) {
  820.     this.setPose(pose);
  821.     this._poseLooping = false;
  822.     this._posePlaying = true;
  823.     this.resetStopCount();
  824.     this.resetPattern();
  825.   }
  826.  
  827.   /*
  828.    * Game_CharacterBase.prototype.loopPose(pose, loops)
  829.    * @param {String} pose The pose to loop on the character.
  830.    * @param {Number} loops The number of times to loop the pose.
  831.    * @note
  832.    * This function will call playPose on the given pose, but also set an
  833.    * additional flag indicating that the pose is looping, and a loop
  834.    * counter, indiciating how many more loops are left on the current pose.
  835.    *
  836.    * One is subtracted from the loop counter before it begins, because otherwise
  837.    * it would loop one too many times, as the counter is, in reality, the number
  838.    * of times the pose has to be replayed. We subtract one here to show that it's
  839.    * been played once already, since the counter is not updated again until after
  840.    * the pose is done playing.
  841.    */
  842.   Game_CharacterBase.prototype.loopPose = function(pose, loops) {
  843.     if(loops === 0) {
  844.       console.log("0 loops requested - Setting pose to last stored value.");
  845.       this.setPose(this._lastPose);
  846.       return;
  847.     }
  848.     this.playPose(pose);
  849.     this._loopCount   = (--loops || 0);
  850.     this._poseLooping = true;
  851.   }
  852. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement