code:
/*=============================================================================
 * Archeia/Liquidize - Steamworks
 * By Liquidize & Archeia - htp://anima.mintkit.lol / http://archeia.moe
 * Archeia_Steamworks.js
 * Version: 1.00
 *
 * Copyright (C) 2016 Dan "Liqudize" Deptula & Archeia
 *
 * This plugin is licensed to you, the user under the terms that you credit
 * Liquidize and Archeia in your game (commercial or free). The terms also include you leaving all
 * copyrights intact, you are however free to modify this file to add additional
 * functionality or fix bugs.
 *
 * TLDR WHY PLUGIN IS CALLED "ARCHEIA_STEAMWORKS": I, Liquidize, was asked to create
 * this at the request of Archeia. I name my plugins with a prefix, that prefix is
 * the name of the person whom asked me to make it, or the game name. She gave moral
 * support though and therefore is credited ;-;.
 *
 *=============================================================================*/
/*:
 * @plugindesc Plugin Description <Archeia_Steamworks>
 * @author Liquidize & Archeia
 *
 * @param Steamworks Debug
 * @desc Enable or disable debug messages
 * @default false
 *
 * @param Cloud Saving
 * @desc Maybe one day this will be a thing.
 * @default NOT IMPLEMENTED
 *
 * @help
 * ---------------------------------------------------------------------------
 * This plugin allows Steamworks integration into your RPG Maker Game via a
 * modified Greenworks node module. This plugin will only function on Windows
 * (and Mac ONE DAY MAYBE I HOPE) builds. Due to this plugin being built upon
 * a modified Greenworks module, you must credit the creators of Greenworks
 * and since Greenworks  is Licensed under the MIT license, you must also include
 * that license in your game package.
 *
 * Greenworks: https://github.com/greenheartgames/greenworks
 *
 * ----------------------------------------------------------------------------
 * HOW-TO (INSTALL)
 * ----------------------------------------------------------------------------
 *
 * In order to use this plugin, you must first have the Steamworks SDK found
 * here: https://partner.steamgames.com/?goto=%2Fhome
 *
 * Once you have the Steamworks SDK downloaded and extracted copy the binaries
 * from the redistributable folder to "yourProject\js\libs" directory. The files
 * you will want to copy are:
 *
 * WINDOWS: steam_api.dll
 * (FOR THE FUTURE: MAC: libsteam_api.dylib)
 *
 * Then copy the contents of this package to your plugin folder, keeping the
 * file structure intact. The end result of this should be:
 *
 * yourProjectMainFolder
 * - js
 * -- libs
 * --- steamworks-win32.node
 * --- steamworks.js
 * -- plugins
 * --- Archeia_Steamworks.js
 * - data
 * - img
 * - audio
 * - fonts
 * - icon
 *
 * Then simply add the plugin to the plugin manager, and it is installed.
 *
 * (NOTE FOR PLAY TESTING)
 * Steam needs to know the app-id for your game, it can only knows this
 * automatically when you launch the game via steam. So when play testing, you
 * need to place a text file called steam_appid.txt with a single line containing
 * your games steam app id, inside the nwjs-win (FOR FUTURE: nwjs-osx for Mac's)
 * folder of your RPG Maker MV install. On steam that is the following:
 *
 * (WINDOWS)
 * STEAM_INSTALL_LOCATION\steamapps\common\RPG Maker MV\nwjs-win
 * (FOR FUTURE WHEN MACS BECOME A THING)
 * STEAM_INSTALL_LOCATION\steamapps\common\RPG Maker MV\nwjs-osx
 *
 * ============================================================================
 * HOW-TO (USAGE)
 * ============================================================================
 *
 * The plugin is meant to be easily usable for non-developers via plugin commands.
 * Some things however require a "Callback" function, as they have to connect to
 * steams servers to get information, or do things (e.g: unlocking achievements)
 * these things may take some time, and therefore when using plugin commands that
 * require a callback, you should apply a wait before executing more logic.
 * The plugin is a wrapper for my modified Greenworks module, meaning that
 * the functions used by the plugin commands are usable by developers in their
 * own plugins.
 *
 *
 * ----------------------------------------------------------------------------
 * PLUGIN COMMANDS
 * ----------------------------------------------------------------------------
 *
 * Plugin commands are case insensitive so any case is usable.
 * All plugins have the initial command prefix as "steamworks" followed by the
 * action name, and then the arguments for the action.
 *
 * All plugins that return a value, will return -1 if an error occurs. This
 * is so you can check if something bad happens with events.
 *
 * ----------------------------------------------------------------------------
 * GETTING THE USERS STEAM NAME
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): steamname, screenname, or name
 *
 * Arguments: the variable id (a number) to place the name in.
 *
 * Callback(s): No.
 *
 * Usage Example(s):
 *
 * steamworks steamname 1
 * steamworks screenname 999
 * StEaMwOrKs NAME 626
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action as
 * getting the steam name, we then use the variable provided (in the examples:
 * 1, 999 and 626) to store the steam name once we obtain it.
 *
 * ----------------------------------------------------------------------------
 * GETTING THE USERS STEAM ID/ACCOUNT ID
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): steamid, accountid, or id
 *
 * Arguments: the variable id (a number) to place the steam id in.
 *
 * Callback(s): No.
 *
 * Usage Example(s):
 *
 * steamworks steamid 1
 * steamworks accountid 1333
 * StEaMwOrKs Id 909
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action as
 * getting the steam id, we then use the variable provided (in the examples:
 * 1, 1333 and 909) to store the steam id once we obtain it.
 *
 * ----------------------------------------------------------------------------
 * GETTING THE USERS STATIC STEAM ID/STATIC ACCOUNT ID
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): staticsteamid, staticid, or staticaccountid
 *
 * Arguments: the variable id (a number) to place the static id in.
 *
 * Callback(s): No.
 *
 * Usage Example(s):
 *
 * steamworks staticsteamid 2
 * steamworks staticid 2000
 * StEaMwOrKs staticaccountid 109
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action as
 * getting the static steam id, we then use the variable provided (in the examples:
 * 2, 2000 and 109) to store the static steam id once we obtain it.
 *
 *
 * ----------------------------------------------------------------------------
 * GETTING THE USERS STEAM LEVEL
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): level or steamlevel
 *
 * Arguments: the variable id (a number) to place the level in.
 *
 * Callback(s): No.
 *
 * Usage Example(s):
 *
 * steamworks level 2
 * steamworks steamlevel 987
 * StEaMWORKs STEAMLEVEL 1100
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action as
 * getting the users steam level, we then use the variable provided (in the examples:
 * 2, 987 and 1100) to store the users steam level once we obtain it.
 *
 *
 * ----------------------------------------------------------------------------
 * GETTING THE NUMBER OF PLAYERS IN GAME NOW
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): numofplayers or playercount
 *
 * Arguments: the variable id (a number) to place the amount of players in.
 *
 * Callback(s): Yes, so use a wait event.
 *
 * Usage Example(s):
 *
 * steamworks numofplayers 1
 * steamworks playercount 200
 * StEaMwOrKs NUMOFPLAYERS 10
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action as
 * getting the amount of players in game, we then use the variable provided (in the examples:
 * 1, 200 and 10) to store the amount of players once it is obtained. This
 * is an action that requires a callback, and must connect to steams server. It
 * is advised to use a wait event to wait a few frames for this to occur.
 *
 * ----------------------------------------------------------------------------
 * GETTING THE NUMBER OF ACHIEVEMENTS IN YOUR GAME
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): numofachievements or achievementcount
 *
 * Arguments: the variable id (a number) to place the returned value in.
 *
 * Callback(s): No.
 *
 * Usage Example(s):
 *
 * steamworks numofachievements 7
 * steamworks numofachievements 8
 * StEaMwOrKs achievementcount 9
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action as
 * getting the amount of achievements the game as, we then use the variable
 * provided (in the examples: 7, 8 and 9) to store the amount of achievements
 * the game has.
 *
 * ----------------------------------------------------------------------------
 * GETTING IF THE USER HAS STEAM OVERLAY ENABLED
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): overlayenabled, gameoverlayenabled or steamoverlayenabled
 *
 * Arguments: the variable id (a number) to place the returned value in.
 *
 * Callback(s): No.
 *
 * Usage Example(s):
 *
 * steamworks overlayenabled 10
 * steamworks gameoverlayenabled 11
 * StEaMwOrKs steamoverlayenabled 12
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action as
 * getting whether the user has overlay enabled or not, we then use the variable
 * provided (in the examples: 10, 11 and 12) to store if they have the overlay
 * enabled or not in it.
 *
 * NOTE: The return values for this differ since this returns a boolean.
 * If an error occurs (such as Steamworks not being initialized) it returns -1
 * if the value is false it return 0, if the value is true it returns 1.
 *
 * ----------------------------------------------------------------------------
 * OPENING THE STEAM OVERLAY
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): openoverlay, opensteamoverlay or opengameoverlay
 *
 * Arguments: the location to open to. The following are valid options:
 * Friends, Community, Players, Settings, OfficialGameGroup, Stats and Achievements
 *
 * Callback(s): No.
 *
 * Usage Example(s):
 *
 * steamworks openoverlay Friends
 * steamworks opensteamoverlay Settings
 * StEaMwOrKs opengameoverlay Achievements
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action is to
 * open the game overlay to the Friends list, the Settings, and the Achievements
 * page.
 *
 * ----------------------------------------------------------------------------
 * OPENING THE STEAM OVERLAY TO A URL
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): openoverlaytourl, opengameoverlayurl or opensteamovertourl
 *
 * Arguments: the url to open to.
 *
 * Callback(s): No.
 *
 * Usage Example(s):
 *
 * steamworks openoverlay http://anima.mintkit.lol
 * steamworks opensteamoverlay http://archeia.moe
 * StEaMwOrKs opengameoverlay http://rpgmakerweb.com
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action is to
 * open the game overlay to the specified url. The urls given in the examples
 * are urls to Liquidize's and Archeia's websites, as well as the website to
 * RPGMaker Web.
 *
 * ----------------------------------------------------------------------------
 * UNLOCKING AN ACHIEVEMENT
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): activateachievement, giveachivement or grantachievement
 *
 * Arguments: the achievement name to unlock.
 *
 * Callback(s): Yes, this function requires a callback and therefore must
 * take some time, it is recommended to do a wait message if you want to do things
 * such as notify the player in game.
 *
 * Usage Example(s):
 *
 * steamworks activateachievement THE_BEST_ACHIEVEMENT_EVER
 * steamworks giveachivement WHAT_IS_MOE_BABY_DONT_MOE_ME_NO_MOE
 * StEaMwOrKs grantachievement BY_THE_POWER_OF_MEMES
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action is to
 * unlock the specified achievement.
 *
 * Special Notes: The plugin command for this, uses a special call back that
 * executes the function to give, or take items and skills when an achievement
 * is acquired. For more information about this, see the notetag section.
 *
 *
 * ----------------------------------------------------------------------------
 * REMOVING/CLEARING/LOCKING AN ACHIEVEMENT
 * ----------------------------------------------------------------------------
 *
 * Action Name(s): deactivateachievement, clearachievement or getrekted
 *
 * Arguments: the achievement name to lock/remove.
 *
 * Callback(s): Yes, this function requires a callback and therefore must
 * take some time, it is recommended to do a wait message if you want to do things
 * such as notify the player in game.
 *
 * Usage Example(s):
 *
 * steamworks activateachievement THE_BEST_ACHIEVEMENT_EVER
 * steamworks giveachivement WHAT_IS_MOE_BABY_DONT_MOE_ME_NO_MOE
 * StEaMwOrKs grantachievement BEST_PLUGIN_2016
 *
 * Usage Explanation:
 *
 * First we use the command steamworks, this lets the plugin command interpreter
 * know that we want to do a steamworks command, then we specify the action is to
 * lock the specified achievement.
 *
 * Special Notes: The plugin command for this, uses a special call back that
 * executes the function to give, or take items and skills when an achievement
 * is removed/locked. For more information about this, see the notetag section.
 *
 * ============================================================================
 * NOTE TAGS
 * ============================================================================
 *
 * This plugin makes it easy for non-scripters to grant their users some rewards
 * for obtaining, or losing achievements. You do this by using note tags on the
 * specified objects.
 *
 * Note tags are case insensitive, so any casing will work.
 *
 * -----------------------------------------------------------------------------
 * ITEM,WEAPON, and ARMOR Note tags
 * -----------------------------------------------------------------------------
 * The below are note tags usable in Item, Weapon, or Armor objects.
 * -----------------------------------------------------------------------------
 * WHEN AN ACHIEVEMENT IS UNLOCKED
 * -----------------------------------------------------------------------------
 *
 * Notetag: <ACHIEVEMENT GRANT: ACHIEVEMENT_NAME,+/-AMOUNT_TO_GIVEHERE/>
 *
 * Aliases: <ACHIEVEMENT UNLOCKED: ACHIEVEMENT_NAME,+/-AMOUNT_TO_GIVEHERE/>
 *          <ACHIEVEMENT ACHIEVED: ACHIEVEMENT_NAME,+/-AMOUNT_TO_GIVEHERE/>
 *
 * Usage Example(s):
 *
 * <ACHIEVEMENT GRANT: MY_LOVELY_ACHIEVEMENT,+1/>
 * <ACHIEVEMENT ACHIEVED: MY_LOVELY_ACHIEVEMENT_SUPERMODE,-10/>
 *
 * Usage Explanation:
 *
 * The first example above will give the player 1 of the item,weapon,or armor
 * when the achievement called "MY_LOVELY_ACHIEVEMENT" is unlocked.
 *
 * The second example will take 10 of the item,weapon,or armor from the user if
 * the achievement "MY_LOVELY_ACHIEVEMENT_SUPERMODE" is unlocked.
 *
 * -----------------------------------------------------------------------------
 * WHEN AN ACHIEVEMENT IS REMOVED/LOCKED
 * -----------------------------------------------------------------------------
 *
 * Notetag: <ACHIEVEMENT CLEAR: ACHIEVEMENT_NAME,+/-AMOUNT_TO_GIVEHERE/>
 *
 * Aliases: <ACHIEVEMENT TAKEN: ACHIEVEMENT_NAME,+/-AMOUNT_TO_GIVEHERE/>
 *          <ACHIEVEMENT UNACHIEVED: ACHIEVEMENT_NAME,+/-AMOUNT_TO_GIVEHERE/>
 *          <ACHIEVEMENT REKTED: ACHIEVEMENT_NAME,+/-AMOUNT_TO_GIVEHERE/>
 *
 * Usage Example(s):
 *
 * <ACHIEVEMENT CLEAR: MY_LOVELY_ACHIEVEMENT,+1/>
 * <ACHIEVEMENT UNACHIEVED: MY_LOVELY_ACHIEVEMENT_SUPERMODE,-10/>
 *
 * Usage Explanation:
 *
 * The first example above will give the player 1 of the item,weapon,or armor
 * when the achievement called "MY_LOVELY_ACHIEVEMENT" is removed or locked.
 *
 * The second example will take 10 of the item,weapon,or armor from the user if
 * the achievement "MY_LOVELY_ACHIEVEMENT_SUPERMODE" is removed or locked.
 *
 * -----------------------------------------------------------------------------
 * Class Note tags
 * -----------------------------------------------------------------------------
 * The below are note tags usable in the Class object.
 *
 * -----------------------------------------------------------------------------
 * WHEN AN ACHIEVEMENT IS UNLOCKED
 * -----------------------------------------------------------------------------
 *
 * Notetag: <ACHIEVEMENT GRANT: ACHIEVEMENT_NAME,LEARN/UNLEARN,SKILL_ID/>
 *
 * Aliases: <ACHIEVEMENT UNLOCKED: ACHIEVEMENT_NAME,LEARN/UNLEARN,SKILL_ID/>
 *          <ACHIEVEMENT ACHIEVED: ACHIEVEMENT_NAME,LEARN/UNLEARN,SKILL_ID/>
 *
 * Usage Example(s):
 *
 * <ACHIEVEMENT GRANT: MY_LOVELY_ACHIEVEMENT,LEARN,1/>
 * <ACHIEVEMENT ACHIEVED: MY_LOVELY_ACHIEVEMENT_SUPERMODE,UNLEARN,99/>
 *
 * Usage Explanation:
 *
 * The first example above will give any party member, whose class has this tag,
 * the skill with ID 1, when this achievement is unlocked.
 *
 * The second example will take skill 99 from any party member, whose class has
 * this tag when this achievement (MY_LOVELY_ACHIEVEMENT_SUPERMODE) is unlocked.
 *
 * -----------------------------------------------------------------------------
 * WHEN AN ACHIEVEMENT IS REMOVED/LOCKED
 * -----------------------------------------------------------------------------
 *
 * Notetag: <ACHIEVEMENT CLEAR: ACHIEVEMENT_NAME,LEARN/UNLEARN,SKILL_ID/>
 *
 * Aliases: <ACHIEVEMENT TAKEN: ACHIEVEMENT_NAME,LEARN/UNLEARN,SKILL_ID/>
 *          <ACHIEVEMENT UNACHIEVED: ACHIEVEMENT_NAME,LEARN/UNLEARN,SKILL_ID/>
 *          <ACHIEVEMENT REKTED: ACHIEVEMENT_NAME,LEARN/UNLEARN,SKILL_ID/>
 *
 * Usage Example(s):
 *
 * <ACHIEVEMENT CLEAR: MY_LOVELY_ACHIEVEMENT,LEARN,1/>
 * <ACHIEVEMENT UNACHIEVED: MY_LOVELY_ACHIEVEMENT_SUPERMODE,UNLEARN,99/>
 *
 * Usage Explanation:
 *
 * The first example above will give any party member, whose class has this tag,
 * the skill with ID 1, when this achievement is removed/locked.
 *
 * The second example will take skill 99 from any party member, whose class has
 * this tag.
 *
 *
 * ============================================================================
 * WHY NO MAC!?
 * ============================================================================
 * Neither I nor does Archeia own a Mac, and therefore we can't compile the
 * required libraries for Mac easily. A Mac version will be available soon.
 * Please be patient.
 *
 * ============================================================================
 * Coming soon, to a plugin near you.
 * ============================================================================
 *
 * - Steam Cloud Syncing (We're working on it)
 * - Workshop Support (I don't know why, but we're working on it)
 * - Find a way to make steam overlay function
 * - Mac and Linux Support
 *
 * ============================================================================
 * Change Log
 * ============================================================================
 *
 * Version 1.0:
 *            - Finished Script!
 *
 *=============================================================================*/

var Imported = Imported || {};
var Archeia = Archeia || {};
Archeia.Steamworks = Archeia.Steamworks || {};
Archeia.Utils = Archeia.Utils || {};

(function ($) {
  "use strict";

  var parameters = $plugins.filter(function (plugin) {
    return plugin.description.contains("<Archeia_Steamworks>");
  });
  if (parameters.length === 0) {
    throw new Error("Couldn't find the parameters of Archeia_Steamworks.");
  }

  $.Parameters = parameters[0].parameters;
  $.Param = {};

  $.Param.debugMode = eval($.Parameters["Steamworks Debug"]);
  $.Param.cloudSaving = eval($.Parameters["Cloud Saving"]);

  var steamworks = require("./js/libs/steamworks");

  // Store a copy of the user.
  $.CachedUser = null;

  //================================================================================
  // DataManager
  //================================================================================

  Archeia.Steamworks.DataManager_isDatabaseLoaded =
    DataManager.isDatabaseLoaded;
  DataManager.isDatabaseLoaded = function () {
    if (!Archeia.Steamworks.DataManager_isDatabaseLoaded.call(this))
      return false;
    this.processSteamworksItemNotetags($dataItems);
    this.processSteamworksItemNotetags($dataWeapons);
    this.processSteamworksItemNotetags($dataArmors);
    this.processSteamworksClassNotetags($dataClasses);
    return true;
  };

  DataManager.processSteamworksItemNotetags = function (group) {
    var note1 =
      /<(?:ACHIEVEMENT GRANT|achievement unlocked|achieved):[ ](.*),([+-]\d+)\/>/i;
    var note2 =
      /<(?:ACHIEVEMENT CLEAR|achievement taken|achievement rekted|unachieved):[ ](.*),([-+]\d+)\/>/i;
    for (var n = 1; n < group.length; n++) {
      var obj = group[n];
      var notedata = obj.note.split(/[\r\n]+/);

      obj.steamworks = {};
      obj.steamworks.achievementGrants = {};
      obj.steamworks.achievementClears = {};

      for (var i = 0; i < notedata.length; i++) {
        var line = notedata[i];
        if (line.match(note1)) {
          var achievement = RegExp.$1;
          var given = parseInt(RegExp.$2);
          if (!obj.steamworks.achievementGrants[achievement]) {
            obj.steamworks.achievementGrants[achievement] = given;
          }
        } else if (line.match(note2)) {
          var achievement = RegExp.$1;
          var given = parseInt(RegExp.$2);
          if (!obj.steamworks.achievementClears[achievement]) {
            obj.steamworks.achievementClears[achievement] = given;
          }
        }
      }
    }
  };

  DataManager.processSteamworksClassNotetags = function (group) {
    var note1 =
      /<(?:ACHIEVEMENT GRANT|achievement unlocked|achieved):[ ](.*),(LEARN|UNLEARN),(\d+)\/>/i;
    var note2 =
      /<(?:ACHIEVEMENT CLEAR|achievement taken|achievement rekted|unachieved):[ ](.*),(LEARN|UNLEARN),(\d+)\/>/i;
    for (var n = 1; n < group.length; n++) {
      var obj = group[n];
      var notedata = obj.note.split(/[\r\n]+/);

      obj.steamworks = {};
      obj.steamworks.achievementGrants = {};
      obj.steamworks.achievementClears = {};

      for (var i = 0; i < notedata.length; i++) {
        var line = notedata[i];
        if (line.match(note1)) {
          obj.steamworks.achievementGrants[RegExp.$1] =
            obj.steamworks.achievementGrants[RegExp.$1] || {};
          obj.steamworks.achievementGrants[RegExp.$1].learn =
            obj.steamworks.achievementGrants[RegExp.$1].learn || [];
          obj.steamworks.achievementGrants[RegExp.$1].unlearn =
            obj.steamworks.achievementGrants[RegExp.$1].unlearn || [];
          var type = RegExp.$2.toLowerCase();
          switch (type) {
            case "learn":
              obj.steamworks.achievementGrants[RegExp.$1].learn.push(
                parseInt(RegExp.$3)
              );
              break;
            case "unlearn":
              obj.steamworks.achievementGrants[RegExp.$1].unlearn.push(
                parseInt(RegExp.$3)
              );
              break;
          }
        } else if (line.match(note2)) {
          obj.steamworks.achievementClears[RegExp.$1] =
            obj.steamworks.achievementClears[RegExp.$1] || {};
          obj.steamworks.achievementClears[RegExp.$1].learn =
            obj.steamworks.achievementClears[RegExp.$1].learn || [];
          obj.steamworks.achievementClears[RegExp.$1].unlearn =
            obj.steamworks.achievementClears[RegExp.$1].unlearn || [];
          var type = RegExp.$2.toLowerCase();
          switch (type) {
            case "learn":
              obj.steamworks.achievementClears[RegExp.$1].learn.push(
                parseInt(RegExp.$3)
              );
              break;
            case "unlearn":
              obj.steamworks.achievementClears[RegExp.$1].unlearn.push(
                parseInt(RegExp.$3)
              );
              break;
          }
        }
      }
    }
  };

  //================================================================================
  // SceneManager - initializes the API.
  //================================================================================

  Archeia.Steamworks.SceneManager_initialize = SceneManager.initialize;
  SceneManager.initialize = function () {
    Archeia.Steamworks.SceneManager_initialize.call(this);
    this.initSteamworks();
  };

  SceneManager.initSteamworks = function () {
    this._steamInitialized = steamworks.initAPI();
    if (this.steamworksInitialized() == true) {
      console.warn("Initialized Steamworks API");
    } else {
      console.warn("Steamworks failed to initialize.");
    }
  };

  SceneManager.steamworksInitialized = function () {
    return this._steamInitialized;
  };

  //================================================================================
  // Game_System
  //================================================================================

  Game_System.prototype.getSteamUserObject = function () {
    if (SceneManager.steamworksInitialized()) {
      return steamworks.getSteamId();
    } else {
      if ($.Param.debugMode)
        console.warn("[ARCHEIA STEAMWORKS] Steamworks is not Initialized.");
      return null;
    }
  };

  Game_System.prototype.getSteamName = function () {
    if (this.getCachedSteamUser()) {
      return this.getCachedSteamUser().screenName;
    } else {
      if ($.Param.debugMode)
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to obtain Steam Name. Is Steamworks Initialized?"
        );
      return null;
    }
  };

  Game_System.prototype.getSteamLevel = function () {
    if (this.getCachedSteamUser()) {
      return this.getCachedSteamUser().level;
    } else {
      if ($.Param.debugMode)
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to obtain Steam Level. Is Steamworks Initialized?"
        );
      return null;
    }
  };

  Game_System.prototype.getSteamAccountId = function () {
    if (this.getCachedSteamUser()) {
      return this.getCachedSteamUser().accountId;
    } else {
      if ($.Param.debugMode)
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to obtain Account Id. Is Steamworks Initialized?"
        );
      return null;
    }
  };

  Game_System.prototype.getSteamStaticAccountId = function () {
    if (this.getCachedSteamUser()) {
      return this.getCachedSteamUser().staticAccountId;
    } else {
      if ($.Param.debugMode)
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to obtain Static Account Id. Is Steamworks Initialized?"
        );
      return null;
    }
  };

  Game_System.prototype.getCachedSteamUser = function () {
    if ($.CachedUser) {
      return $.CachedUser;
    } else {
      return ($.CachedUser = this.getSteamUserObject());
    }
  };

  Game_System.prototype.unlockAchievement = function (
    achievement,
    callback,
    errorcallback
  ) {
    if (SceneManager.steamworksInitialized()) {
      steamworks.activateAchievement(
        achievement,
        function () {
          if (callback) {
            callback(achievement);
          }
        },
        function (err) {
          if (errorcallback) {
            errorcallback(err);
          } else {
            if ($.Param.debugMode) {
              console.error(
                Archeia.Utils.sformat(
                  "[ARCHEIA STEAMWORKS] Error when trying to unlock achievement '{0}' OUTPUT: '{1}'",
                  achievement,
                  err
                )
              );
            }
          }
        }
      );
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to grant achievement. Is Steamworks Initialized?"
        );
      }
    }
  };

  Game_System.prototype.getAchievements = function () {
    if (SceneManager.steamworksInitialized()) {
      return steamworks.getAchievementNames();
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to retrieve achievements. Is Steamworks Initialized?"
        );
      }
      return null;
    }
  };

  Game_System.prototype.getNumberOfAchievements = function () {
    if (SceneManager.steamworksInitialized()) {
      return steamworks.getNumberOfAchievements();
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to retrieve achievement count. Is Steamworks Initialized?"
        );
      }
      return null;
    }
  };

  Game_System.prototype.clearAchievement = function (
    achievement,
    callback,
    errorcallback
  ) {
    if (SceneManager.steamworksInitialized()) {
      steamworks.clearAchievement(
        achievement,
        function () {
          if (callback) {
            callback(achievement);
          }
        },
        function (err) {
          if (errorcallback) {
            errorcallback(err);
          } else {
            if ($.Param.debugMode) {
              console.error(
                Archeia.Utils.sformat(
                  "[ARCHEIA STEAMWORKS] Error when trying to clear achievement '{0}' OUTPUT: '{1}'",
                  achievement,
                  err
                )
              );
            }
          }
        }
      );
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to clear achievement. Is Steamworks Initialized?"
        );
      }
    }
  };

  Game_System.prototype.getAchievement = function (
    achievement,
    callback,
    errorcallback
  ) {
    if (SceneManager.steamworksInitialized()) {
      steamworks.getAchievement(
        achievement,
        function (achieved) {
          if (callback) {
            callback(achieved, achievement);
          }
        },
        function (err) {
          if (errorcallback) {
            errorcallback(err);
          } else {
            if ($.Param.debugMode) {
              console.error(
                Archeia.Utils.sformat(
                  "[ARCHEIA STEAMWORKS] Error when trying to get achievement '{0}' OUTPUT: '{1}'",
                  achievement,
                  err
                )
              );
            }
          }
        }
      );
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get achievement. Is Steamworks Initialized?"
        );
      }
    }
  };

  Game_System.prototype.getCurrentGameLanguage = function () {
    if (SceneManager.steamworksInitialized()) {
      return steamworks.getCurrentGameLanguage();
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get game language. Is Steamworks Initialized?"
        );
      }
      return null;
    }
  };

  Game_System.prototype.getNumberOfPlayers = function (
    callback,
    errorcallback
  ) {
    if (SceneManager.steamworksInitialized()) {
      steamworks.getNumberOfPlayers(
        function (numofplayers) {
          if (callback) {
            callback(numofplayers);
          }
        },
        function (err) {
          if (errorcallback) {
            errorcallback(err);
          } else {
            if ($.Param.debugMode) {
              console.error(
                Archeia.Utils.sformat(
                  "[ARCHEIA STEAMWORKS] Error when trying to get number of players. OUTPUT: '{0}'",
                  err
                )
              );
            }
          }
        }
      );
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get number of players. Is Steamworks Initialized?"
        );
      }
      return null;
    }
  };

  Game_System.prototype.activateGameOverlay = function (option) {
    if (SceneManager.steamworksInitialized()) {
      if (!option) {
        option = "Community";
      }
      steamworks.activateGameOverlay(option);
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to open steam overlay. Is Steamworks Initialized? Does the player have game overlay enabled?"
        );
      }
    }
  };

  Game_System.prototype.isGameOverlayEnabled = function () {
    if (SceneManager.steamworksInitialized()) {
      return steamworks.isGameOverlayEnabled();
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get if steam overlay is enabled. Is Steamworks Initialized?"
        );
      }
      return null;
    }
  };

  Game_System.prototype.activateGameOverlayToWebpage = function (url) {
    if (SceneManager.steamworksInitialized()) {
      steamworks.activateGameOverlayToWebPage(url);
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get open game overlay to specified url. Is Steamworks Initialized? Does the player have Game overlay Enabled?"
        );
      }
      return null;
    }
  };

  Game_System.prototype.saveTextToCloud = function (
    file,
    contents,
    callback,
    errorcallback
  ) {
    if (SceneManager.steamworksInitialized()) {
      steamworks.saveTextToFile(
        file,
        contents,
        function () {
          if (callback) {
            callback();
          }
        },
        function (err) {
          if (errorcallback) {
            errorcallback(err);
          } else {
            if ($.Param.debugMode) {
              console.error(
                Archeia.Utils.sformat(
                  "[ARCHEIA STEAMWORKS] Error when trying to save file to cloud. OUTPUT: '{0}'",
                  err
                )
              );
            }
          }
        }
      );
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get save file to cloud. Is Steamworks Initialized? Does the player have cloud sync enabled?"
        );
      }
    }
  };

  Game_System.prototype.readTextFromCloud = function (
    file,
    callback,
    errorcallback
  ) {
    if (SceneManager.steamworksInitialized()) {
      steamworks.readTextFromFile(
        file,
        function (contents) {
          if (callback) {
            callback(contents);
          }
        },
        function (err) {
          if (errorcallback) {
            errorcallback(err);
          } else {
            if ($.Param.debugMode) {
              console.error(
                Archeia.Utils.sformat(
                  "[ARCHEIA STEAMWORKS] Error when trying to read file from cloud. OUTPUT: '{0}'",
                  err
                )
              );
            }
          }
        }
      );
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get red file from cloud. Is Steamworks Initialized? Does the player have cloud sync enabled?"
        );
      }
    }
  };

  Game_System.prototype.isCloudSyncEnabledForUser = function () {
    if (SceneManager.steamworksInitialized()) {
      return steamworks.isCloudEnabledForUser();
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get if cloud sync is enabled for user. Is Steamworks Initialized?"
        );
      }
      return null;
    }
  };

  Game_System.prototype.isCloudEnabled = function () {
    if (SceneManager.steamworksInitialized()) {
      return steamworks.isCloudEnabled();
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get if cloud sync is enabled. Is Steamworks Initialized?"
        );
      }
      return null;
    }
  };

  Game_System.prototype.enableCloud = function (flag) {
    if (SceneManager.steamworksInitialized()) {
      steamworks.enableCloud(flag);
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to enable/disable cloud sync. Is Steamworks Initialized?"
        );
      }
    }
  };

  Game_System.prototype.getCloudQuota = function (callback, errorcallback) {
    if (SceneManager.steamworksInitialized()) {
      steamworks.getCloudQuota(
        function (total, available) {
          if (callback) {
            callback(total, available);
          }
        },
        function (err) {
          if (errorcallback) {
            errorcallback(err);
          } else {
            if ($.Param.debugMode) {
              console.error(
                Archeia.Utils.sformat(
                  "[ARCHEIA STEAMWORKS] Error when trying to get cloud quota. OUTPUT: '{0}'",
                  err
                )
              );
            }
          }
        }
      );
    } else {
      if ($.Param.debugMode) {
        console.warn(
          "[ARCHEIA STEAMWORKS] Unable to get if cloud sync is enabled. Is Steamworks Initialized?"
        );
      }
    }
  };

  Game_System.prototype.onAchievementUnlocked = function (achievement) {
    $gameParty.members().forEach(function (member) {
      if (member.currentClass().steamworks.achievementGrants[achievement]) {
        if (
          member.currentClass().steamworks.achievementGrants[achievement].learn
        ) {
          for (
            var l = 0;
            l <
            member.currentClass().steamworks.achievementGrants[achievement]
              .learn.length;
            l++
          ) {
            member.learnSkill(
              member.currentClass().steamworks.achievementGrants[achievement]
                .learn[l]
            );
          }
        }
        if (
          member.currentClass().steamworks.achievementGrants[achievement]
            .unlearn
        ) {
          for (
            var u = 0;
            u <
            member.currentClass().steamworks.achievementGrants[achievement]
              .unlearn.length;
            u++
          ) {
            member.forgetSkill(
              member.currentClass().steamworks.achievementGrants[achievement]
                .unlearn[u]
            );
          }
        }
      }
    });

    for (var i = 0; i < $dataItems.length; i++) {
      var item = $dataItems[i];
      if (item && item.steamworks) {
        if (item.steamworks.achievementGrants[achievement]) {
          var given = item.steamworks.achievementGrants[achievement];
          $gameParty.gainItem(item, given, true);
        }
      }
    }

    for (var w = 0; w < $dataWeapons.length; w++) {
      var weapon = $dataWeapons[w];
      if (weapon && weapon.steamworks) {
        if (weapon.steamworks.achievementGrants[achievement]) {
          var given = weapon.steamworks.achievementGrants[achievement];
          $gameParty.gainItem(weapon, given, true);
        }
      }
    }

    for (var a = 0; a < $dataArmors.length; a++) {
      var armor = $dataArmors[a];
      if (armor && armor.steamworks) {
        if (armor.steamworks.achievementGrants[achievement]) {
          var given = armor.steamworks.achievementGrants[achievement];
          $gameParty.gainItem(armor, given, true);
        }
      }
    }
  };

  Game_System.prototype.onAchievementCleared = function (achievement) {
    $gameParty.members().forEach(function (member) {
      if (member.currentClass().steamworks.achievementClears[achievement]) {
        if (
          member.currentClass().steamworks.achievementClears[achievement].learn
        ) {
          for (
            var l = 0;
            l <
            member.currentClass().steamworks.achievementClears[achievement]
              .learn.length;
            l++
          ) {
            member.learnSkill(
              member.currentClass().steamworks.achievementGrants[achievement]
                .learn[l]
            );
          }
        }
        if (
          member.currentClass().steamworks.achievementClears[achievement]
            .unlearn
        ) {
          for (
            var u = 0;
            u <
            member.currentClass().steamworks.achievementClears[achievement]
              .unlearn.length;
            u++
          ) {
            member.forgetSkill(
              member.currentClass().steamworks.achievementClears[achievement]
                .unlearn[u]
            );
          }
        }
      }
    });

    for (var i = 0; i < $dataItems.length; i++) {
      var item = $dataItems[i];
      if (item && item.steamworks) {
        if (item.steamworks.achievementClears[achievement]) {
          var given = item.steamworks.achievementClears[achievement];
          $gameParty.gainItem(item, given, true);
        }
      }
    }

    for (var w = 0; w < $dataWeapons.length; w++) {
      var weapon = $dataWeapons[w];
      if (weapon && weapon.steamworks) {
        if (weapon.steamworks.achievementClears[achievement]) {
          var given = weapon.steamworks.achievementClears[achievement];
          $gameParty.gainItem(weapon, given, true);
        }
      }
    }

    for (var a = 0; a < $dataArmors.length; a++) {
      var armor = $dataArmors[a];
      if (armor && armor.steamworks) {
        if (armor.steamworks.achievementClears[achievement]) {
          var given = armor.steamworks.achievementClears[achievement];
          $gameParty.gainItem(armor, given, true);
        }
      }
    }
  };

  //================================================================================
  // Cloud Saving - coming to a meme near you.
  //================================================================================

  //================================================================================
  // Game_Interpreter
  //================================================================================

  Archeia.Steamworks.GameInterpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
  Game_Interpreter.prototype.pluginCommand = function (command, args) {
    if (command.toLowerCase() == "steamworks") {
      if (args.length < 1) return; // No action given.
      var action = args[0].toLowerCase();
      switch (action) {
        case "steamname":
        case "screenname":
        case "name":
          if (args.length < 2) return; // No variable to put it in.
          var steamname = $gameSystem.getSteamName();
          if (steamname == null) steamname = -1; // failed to get name.
          $gameVariables.setValue(parseInt(args[1]), steamname);
          break;
        case "steamid":
        case "accountid":
        case "id":
          if (args.length < 2) return; // No variable to put it in.
          var steamid = $gameSystem.getSteamAccountId();
          if (steamid == null) steamid = -1;
          $gameVariables.setValue(parseInt(args[1]), steamid);
          break;
        case "staticsteamid":
        case "staticid":
        case "staticaccountid":
          if (args.length < 2) return; // No variable to put it in.
          var statid = $gameSystem.getSteamStaticAccountId();
          if (statid == null) statid = -1;
          $gameVariables.setValue(parseInt(args[1]), statid);
          break;
        case "level":
        case "steamlevel":
          if (args.length < 2) return; // No variable to put it in.
          var level = $gameSystem.getSteamLevel();
          if (level == null) level = -1;
          $gameVariables.setValue(parseInt(args[1]), level);
          break;
        case "numofplayers":
        case "playercount":
          if (args.length < 2) return; // No variable to put it in.
          $gameSystem.getNumberOfPlayers(
            function (count) {
              $gameVariables.setValue(parseInt(args[1]), count);
            },
            function (err) {
              if ($.Param.debugMode) {
                console.error(
                  "[ARCHEIA STEAMWORKS] An error occurred when attempting to get player count. Is Steamworks Initialized?"
                );
              }
              $gameVariables.setValue(parseInt(args[1]), -1);
            }
          );
          break;
        case "numofachievements":
        case "achievementcount":
          if (args.length < 2) return; // No variable to put it in.
          var achievementcount = $gameSystem.getNumberOfAchievements();
          if (achievementcount == null) achievementcount = -1;
          $gameVariables.setValue(parseInt(args[1]), achievementcount);
          break;
        case "overlayenabled":
        case "gameoverlayenabled":
        case "steamoverlayenabled":
          if (args.length < 2) return; // No variable to put it in.
          var overlayenabled = $gameSystem.isGameOverlayEnabled();
          if (overlayenabled == null) overlayenabled = -1;
          if (overlayenabled == true) overlayenabled = 1;
          if (overlayenabled == false) overlayenabled = 0;
          $gameVariables.setValue(parseInt(args[1]), overlayenabled);
          break;
        case "openoverlay":
        case "opensteamoverlay":
        case "opengameoverlay":
          if (args.length < 2) return; // No overlay option given.
          $gameSystem.activateGameOverlay(args[1]);
          break;
        case "openoverlaytourl":
        case "opengameoverlayurl":
        case "opensteamovertourl":
          if (args.length < 2) return; // no url given.
          args = args.splice(1, args.length - 1);
          $gameSystem.activateGameOverlayToWebpage(args.join(""));
          break;
        case "activateachievement":
        case "giveachivement":
        case "grantachievement":
          if (args.length < 2) return; // no achievement name given.
          args = args.splice(1, args.length - 1);
          $gameSystem.unlockAchievement(
            args.join(""),
            $gameSystem.onAchievementUnlocked,
            null
          );
          break;
        case "deactivateachievement":
        case "clearachievement":
        case "getrekted": // I, Liquid, am a child at heart, this must be kept in in order for the children of the world to get their daily dose of memes.
          if (args.length < 2) return; // no achievement name given.
          args = args.splice(1, args.length - 1);
          $gameSystem.clearAchievement(
            args.join(""),
            $gameSystem.onAchievementCleared,
            null
          );
          break;
        case "devtest": // outputs the value of all returnable commands to console
          for (var i = 0; i < 7; i++) {
            console.warn($gameVariables.value(i));
          }
          break;
      }
    } else {
      Archeia.Steamworks.GameInterpreter_pluginCommand.call(
        this,
        command,
        args
      );
    }
  };

  //================================================================================
  // UTILS
  //================================================================================

  // The below is a string formatting function that gives me/js/people/anyone/stuff
  // the ability to use C#/C styled string formatting using {0},{1} for parameters.
  // I prefer this method, as it is what I'm used to.
  // - Liquidize
  if (!Archeia.Utils.sformat) {
    Archeia.Utils.sformat = function () {
      var theString = arguments[0];
      for (var i = 1; i < arguments.length; i++) {
        var regEx = new RegExp("\\{" + (i - 1) + "\\}", "gm");
        theString = theString.replace(regEx, arguments[i]);
      }
      return theString;
    };
  }
})(Archeia.Steamworks);

ArcheiaSteamworks = Archeia.Steamworks;
Imported["Archeia_Steamworks"] = 1.0;


code:
//=============================================================================
// Battle Mode
// by Shaz
// Last Updated: 2015.10.21
//=============================================================================

/*:
 * @plugindesc Allows side view and front view battles in the same game
 * @author Shaz
 *
 * @help This plugin does not provide plugin commands.
 *
 * Prefix a troop name with SV to set battles with that troop to side view
 * Prefix a troop name with FV to set battles with that troop to front view
 * Prefix a troop name with RV to set a random view for each battle with that troop
 * Leave out the prefix to take the system default
 *
 */

/*:ja
 * @plugindesc 同一ゲーム内で、戦闘時のサイドビューと
 * フロントビューの両方を提供します。
 * @author Shaz
 *
 * @help このプラグインは、プラグインコマンドを含みません。
 *
 * 部隊名の頭にSVとつけることで、その部隊との戦闘はサイドビューで展開されます。
 * 部隊名の頭にFVとつけることで、その部隊との戦闘はフロントビューで展開されます。
 * 部隊名の頭にRVとつけることで、その部隊との戦闘ビューはランダムに決定されます。
 *
 *上記を削除すれば、デフォルト設定に戻ります。
 *
 */

(function () {
  var _Game_System_isSideView = Game_System.prototype.isSideView;
  Game_System.prototype.isSideView = function () {
    if ($gameParty.inBattle) {
      var sv = $gameTroop.isSideView();
      if (sv === null) {
        return _Game_System_isSideView.call(this);
      } else {
        return sv;
      }
    } else {
      return _Game_System_isSideView.call(this);
    }
  };

  var _Game_Troop_setup = Game_Troop.prototype.setup;
  Game_Troop.prototype.setup = function (troopId) {
    _Game_Troop_setup.call(this, troopId);

    if (this.troop().name.match(/^SV/)) {
      this._isSideView = true;
    } else if (this.troop().name.match(/^FV/)) {
      this._isSideView = false;
    } else if (this.troop().name.match(/^RV/)) {
      this._isSideView = Math.random() < 0.5;
    } else {
      this._isSideView = null;
    }
  };

  Game_Troop.prototype.isSideView = function () {
    return this._isSideView;
  };
})();

repo_name: dazed/translations

license: unknown


code:
//=============================================================================
// BattleResultsPopup.js
//=============================================================================

/*:
 * @plugindesc Displays a battle results window instead of text messages.
 * @author Yoji Ojima
 *
 * @help This plugin does not provide plugin commands.
 */

/*:ja
 * @plugindesc 戦闘結果の表示をポップアップ形式に変更します。
 * @author Yoji Ojima
 *
 * @help このプラグインには、プラグインコマンドはありません。
 */

(function () {
  var resultDisplaying = 0;

  var _BattleManager_initMembers = BattleManager.initMembers;
  BattleManager.initMembers = function () {
    _BattleManager_initMembers.call(this);
    resultDisplaying = 0;
  };

  var _BattleManager_update = BattleManager.update;
  BattleManager.update = function () {
    _BattleManager_update.call(this);
    if (resultDisplaying > 0) {
      if (++resultDisplaying >= 60) {
        if (Input.isTriggered("ok") || TouchInput.isTriggered()) {
          resultDisplaying = 0;
        }
      }
    }
  };

  var _BattleManager_isBusy = BattleManager.isBusy;
  BattleManager.isBusy = function () {
    return _BattleManager_isBusy.call(this) || resultDisplaying > 0;
  };

  BattleManager.displayVictoryMessage = function () {};

  BattleManager.displayRewards = function () {
    resultDisplaying = 1;
  };

  Game_Actor.prototype.shouldDisplayLevelUp = function () {
    return false;
  };

  var _Scene_Battle_update = Scene_Battle.prototype.update;
  Scene_Battle.prototype.update = function () {
    _Scene_Battle_update.call(this);
    if (resultDisplaying > 30 && !this._resultWindow) {
      this._resultWindow = new Window_BattleResults();
      this.addWindow(this._resultWindow);
    }
  };

  var _Scene_Battle_stop = Scene_Battle.prototype.stop;
  Scene_Battle.prototype.stop = function () {
    _Scene_Battle_stop.call(this);
    if (this._resultWindow) {
      this._resultWindow.close();
    }
  };

  function Window_BattleResults() {
    this.initialize.apply(this, arguments);
  }

  Window_BattleResults.prototype = Object.create(Window_Base.prototype);
  Window_BattleResults.prototype.constructor = Window_BattleResults;

  Window_BattleResults.prototype.initialize = function () {
    var rewards = BattleManager._rewards;
    var width = 400;
    var height = this.fittingHeight(Math.min(9, rewards.items.length + 1));
    var statusHeight = this.fittingHeight(4);
    var x = (Graphics.boxWidth - width) / 2;
    var y = (Graphics.boxHeight - statusHeight - height) / 2;
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
    this.openness = 0;
    this.open();
  };

  Window_BattleResults.prototype.refresh = function () {
    var x = this.textPadding();
    var y = 0;
    var width = this.contents.width;
    var lineHeight = this.lineHeight();
    var rewards = BattleManager._rewards;
    var items = rewards.items;
    this.contents.clear();

    this.resetTextColor();
    this.drawText(rewards.exp, x, y);
    x += this.textWidth(rewards.exp) + 6;
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.expA, x, y);
    x += this.textWidth(TextManager.expA + "  ");

    this.resetTextColor();
    this.drawText(rewards.gold, x, y);
    x += this.textWidth(rewards.gold) + 6;
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.currencyUnit, x, y);

    x = 0;
    y += lineHeight;

    items.forEach(function (item) {
      this.drawItemName(item, x, y, width);
      y += lineHeight;
    }, this);
  };
})();


code:
//=============================================================================
// BattleVoice.js
//=============================================================================

/*:
 * @plugindesc play voice SE at battle when actor does spcified action
 * @author Sasuke KANNAZUKI
 *
 * @param pitch
 * @desc pitch of SEs. this setting is common among all voice SEs.
 * @default 100
 *
 * @param volume
 * @desc volume of SEs. this setting is common among all  voice SEs.
 * @default 90
 *
 * @noteParam attackVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam recoverVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam friendMagicVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam magicVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam skillVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam damageVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam defeatedVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam victoryVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @help This plugin does not provide plugin commands.
 *
 * note specification:
 * write down each actor's note at following format to set SE filename.
 * <attackVoice:filename>  plays when actor does normal attack.
 * <recoverVoice:filename>   plays when actor uses HP recovering magic.
 * <friendMagicVoice:filename> plays when actor spells magic for friend
 *  except HP recovering. if this is not set but <skillVoice:filename> is set,
 *   it plays <magicVoice:filename> setting file.
 * <magicVoice:filename>   plays when actor spells magic(except for friend).
 * <skillVoice:filename>   plays when actor uses special skill except magic.
 * <damageVoice:filename>    plays when actor takes damage.
 * <defeatedVoice:filename>   plays when actor is died.
 * <victoryVoice:filename>   plays when battle finishes.
 *  if plural actors attend the battle, randomly selected actor's SE is adopted.
 *
 */
/*:ja
 * @plugindesc アクターの戦闘時の行動にボイスSEを設定します。
 * @author 神無月サスケ
 *
 * @param pitch
 * @desc ボイスSEのピッチです。この設定が全てのボイスSEの共通となります。
 * @default 100
 *
 * @param volume
 * @desc ボイスSEのボリュームです。この設定が全てのボイスSEの共通となります。
 * @default 90
 *
 * @noteParam attackVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam recoverVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam friendMagicVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam magicVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam skillVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam damageVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam defeatedVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @noteParam victoryVoice
 * @noteRequire 1
 * @noteDir audio/se/
 * @noteType file
 * @noteData actors
 *
 * @help このプラグインには、プラグインコマンドはありません。
 *
 * メモ設定方法:
 * それぞれのアクターのメモに以下の書式で書いてください。
 * filename はボイスSEのファイル名にしてください。
 *
 * <attackVoice:filename>  通常攻撃の時に再生されるボイスです。
 * <recoverVoice:filename>   HP回復魔法を使用した時に再生されるボイスです。
 * <friendMagicVoice:filename>   HP回復以外の味方向け魔法を使用した時に
 *  再生されるボイスです。省略された場合で<magicVoice:filename>が
 *  設定されている場合は、そちらが再生されます。
 * <magicVoice:filename> 味方向け以外の魔法を使用した時に再生されるボイスです。
 * <skillVoice:filename>   必殺技を使用した時に再生されるボイスです。
 * <damageVoice:filename>    ダメージを受けた時に再生されるボイスです。
 * <defeatedVoice:filename>   戦闘不能になった時に再生されるボイスです。
 * <victoryVoice:filename>   戦闘勝利時に再生されるボイスです。
 *  アクターが複数いる場合は、生きているアクターの中からランダムで再生されます。
 *
 */
(function () {
  //
  // process parameters
  //
  var parameters = PluginManager.parameters("BattleVoice");
  var pitch = Number(parameters["pitch"]) || 100;
  var volume = Number(parameters["volume"]) || 90;

  AudioManager.createAudioByFileame = function (name) {
    var audio = {};
    audio.name = name;
    audio.pitch = pitch;
    audio.volume = volume;
    return audio;
  };

  //
  // play actor voice
  //
  SoundManager.playActorVoice = function (actor, type) {
    var name = "";
    switch (type) {
      case "attack":
        name = actor.meta.attackVoice;
        break;
      case "recover":
        name = actor.meta.recoverVoice;
        break;
      case "friendmagic":
        name = actor.meta.friendMagicVoice || actor.meta.magicVoice;
        break;
      case "magic":
        name = actor.meta.magicVoice;
        break;
      case "skill":
        name = actor.meta.skillVoice;
        break;
      case "damage":
        name = actor.meta.damageVoice;
        break;
      case "dead":
        name = actor.meta.defeatedVoice;
        break;
      case "victory":
        name = actor.meta.victoryVoice;
        break;
    }
    if (name) {
      var audio = AudioManager.createAudioByFileame(name);
      AudioManager.playSe(audio);
    }
  };

  //
  // functions for call actor voice.
  //
  var _Game_Actor_performAction = Game_Actor.prototype.performAction;
  Game_Actor.prototype.performAction = function (action) {
    _Game_Actor_performAction.call(this, action);
    if (action.isAttack()) {
      SoundManager.playActorVoice(this.actor(), "attack");
    } else if (action.isMagicSkill() && action.isHpRecover()) {
      SoundManager.playActorVoice(this.actor(), "recover");
    } else if (action.isMagicSkill() && action.isForFriend()) {
      SoundManager.playActorVoice(this.actor(), "friendmagic");
    } else if (action.isMagicSkill()) {
      SoundManager.playActorVoice(this.actor(), "magic");
    } else if (action.isSkill() && !action.isGuard()) {
      SoundManager.playActorVoice(this.actor(), "skill");
    }
  };

  var _Game_Actor_performDamage = Game_Actor.prototype.performDamage;
  Game_Actor.prototype.performDamage = function () {
    _Game_Actor_performDamage.call(this);
    SoundManager.playActorVoice(this.actor(), "damage");
  };

  var _Game_Actor_performCollapse = Game_Actor.prototype.performCollapse;
  Game_Actor.prototype.performCollapse = function () {
    _Game_Actor_performCollapse.call(this);
    if ($gameParty.inBattle()) {
      SoundManager.playActorVoice(this.actor(), "dead");
    }
  };

  var _BattleManager_processVictory = BattleManager.processVictory;
  BattleManager.processVictory = function () {
    var index = Math.randomInt($gameParty.aliveMembers().length);
    var actor = $gameParty.aliveMembers()[index].actor();
    SoundManager.playActorVoice(actor, "victory");
    _BattleManager_processVictory.call(this);
  };
})();


code:
//=============================================================================
// BattlebackScroll.js
//=============================================================================

/*:
 * @plugindesc Automatically scrolls a 'battlebacks1' image.
 * @author Yoji Ojima
 *
 * @param Scroll X Variable ID
 * @desc The ID of the variable for the horizontal scroll speed.
 * @default 0
 *
 * @param Scroll Y Variable ID
 * @desc The ID of the variable for the vertical scroll speed.
 * @default 0
 *
 * @help This plugin does not provide plugin commands.
 */

/*:ja
 * @plugindesc 戦闘背景（battlebacks1）を自動的にスクロールします。
 * @author Yoji Ojima
 *
 * @param Scroll X Variable ID
 * @desc 横スクロール速度を指定するための変数のIDです。
 * @default 0
 *
 * @param Scroll Y Variable ID
 * @desc 縦スクロール速度を指定するための変数のIDです。
 * @default 0
 *
 * @help このプラグインには、プラグインコマンドはありません。
 */

(function () {
  var parameters = PluginManager.parameters("BattlebackScroll");
  var scrollXVariableId = Number(parameters["Scroll X Variable ID"] || 0);
  var scrollYVariableId = Number(parameters["Scroll Y Variable ID"] || 0);

  var _Spriteset_Battle_updateBattleback =
    Spriteset_Battle.prototype.updateBattleback;
  Spriteset_Battle.prototype.updateBattleback = function () {
    _Spriteset_Battle_updateBattleback.call(this);
    var scrollX = $gameVariables.value(scrollXVariableId);
    var scrollY = $gameVariables.value(scrollYVariableId);
    if (scrollX) {
      this._back1Sprite.origin.x += scrollX / 8;
    }
    if (scrollY) {
      this._back1Sprite.origin.y += scrollY / 8;
    }
  };
})();