Guest User

Recipe Crafting MV Version 1.2 (DragonPC Edit)

a guest
Nov 5th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //==
  2. // Recipe Crafting MV Version 1.2 (DragonPC Edit)
  3. //==
  4.  
  5. /*:
  6.  * @plugindesc v1.1c (DragonPC Update) // Take some items.. and make them into other items! That's crafting~
  7.  * @author Vlue
  8.  *
  9.  *@param ------Main Functions------
  10.  *
  11.  * @param Categories
  12.  * @desc The various categories of crafting available
  13.  * @default "Alchemy","Blacksmith","Tailor"
  14.  *
  15.  * @param User Definable Max Level
  16.  * @desc Define the Maximum level the player can reach in the crafting Interface (default - 99)
  17.  * @default 99
  18.  *
  19.  * @param Category Icons
  20.  * @desc The icons (index) to use for the crafting categories
  21.  * @default 219,223,225
  22.  *
  23.  * @param Player Level Icon
  24.  * @desc Icon displayed by Player level (if applicable) in crafting menu
  25.  * @default 82
  26.  *
  27.  * @param Crafting XP Formula
  28.  * @desc The exp needed to determine current crafting level (lvl)
  29.  * @default 100 * lvl
  30.  *
  31.  * @param Craft Multiple
  32.  * @desc Allow crafting of multiple items at once
  33.  * @default true
  34.  *
  35.  * @param Menu Craft Options
  36.  * @desc Whether to allow crafting from menu (off, view, craft)
  37.  * @default craft
  38.  *
  39.  * @param Display Parameters
  40.  * @desc Include/exclude various details from the recipe window
  41.  * @default gold:true, chance:true, plevel:true, clevel:true
  42.  *
  43.  * @param ------Custom Text------
  44.  *
  45.  * @param Required Level Text
  46.  * @desc Change Required Level text. (default - Required level:)
  47.  * @default Required level:
  48.  *
  49.  * @param Required Material Text
  50.  * @desc Change Required Materials text. (default - Required materials:)
  51.  * @default Required materials:
  52.  *
  53.  * @param Success Rate Text
  54.  * @desc Change Success Rate text. (default - Success rate:)
  55.  * @default Success rate:
  56.  *
  57.  * @param Crafting Cost Text
  58.  * @desc Change Crafting Cost text. (default - Crafting costs:)
  59.  * @default Crafting costs:
  60.  *
  61.  * @param Crafting Text
  62.  * @desc Change Crafting Text. (default - Craft)
  63.  * @default Craft
  64.  *
  65.  * @param Crafted Text
  66.  * @desc Change Crafted Text. (default - Crafted!)
  67.  * @default Crafted!
  68.  *
  69.  * @param Crafting Failed
  70.  * @desc Change Crafting Failed Text. (default - Crafting failed!)
  71.  * @default Crafting failed!
  72.  *
  73.  * @param Max Level Test
  74.  * @desc Text Displayed when reaching max level in a profession.
  75.  * @default MAX LEVEL
  76.  *
  77.  * @param ------Colors------
  78.  *
  79.  * @param Success 0-20 Color
  80.  * @desc Change Color of the Percentage (default - 18)
  81.  * @default 18
  82.  *
  83.  * @param Success 20-40 Color
  84.  * @desc Change Color of the Percentage (default - 20)
  85.  * @default 20
  86.  *
  87.  * @param Success 40-60 Color
  88.  * @desc Change Color of the Percentage (default - 21)
  89.  * @default 21
  90.  *
  91.  * @param Success 60-80 Color
  92.  * @desc Change Color of the Percentage (default - 17)
  93.  * @default 17
  94.  *
  95.  * @param Success 80-100 Color
  96.  * @desc Change Color of the Percentage (default - 29)
  97.  * @default 29
  98.  *
  99.  * @param ------Custom Sounds------
  100.  *
  101.  * @param Crafting Succeded Sound
  102.  * @desc Change Crafting Succeeded Sound.(Case Sensitive) (default - Item3)
  103.  * @default Item3
  104.  *
  105.  * @param Success Sound Volume
  106.  * @desc Change Crafting Succeeded Sound Volume. (default - 90)
  107.  * @default 90
  108.  *
  109.  * @param Crafting Failed Sound
  110.  * @desc Change Crafting Failed Sound.(Case Sensitive) (default - Scream)
  111.  * @default Scream
  112.  *
  113.  * @param Fail Sound Volume
  114.  * @desc Change Crafting Failed Sound Volume. (default - 90)
  115.  * @default 90
  116.  *
  117.  * @help
  118.  *
  119.  * ----------- DragonPC Update 1.2 (bug fixes + features) ----------------
  120.  *
  121.  * - Fixed Crafting popup to no longer be truncated.
  122.  * - Fixed Gauge Overlap.
  123.  * - Player EXP no-longer levels you excessively.
  124.  * - Added custom text display for inputting your own terms.
  125.  * - Added custom sound option to choose your own sounds for "Success" and "Failure".
  126.  * - Added Volume control of Success And Failure Sounds.
  127.  * - Removed Gauge when at max level and displayed MAX LEVEL (Customizable).
  128.  * - Changed Colors of Numbers when not enough, and more than you need, to Red and Green Respecitvely.
  129.  * - Gold Cost Turns red when you don't have enough Gold and green when you do.
  130.  * - Custom Colors for Levels of Success chance %.
  131.  * - Assorted Visual Upgrades.
  132.  *
  133.  *(Special Thanks to SkottyTV)
  134.  * ------------------------------------------------------------------------
  135.  *
  136.  *
  137.  * Plugin Commands:
  138.  *  crafting call categoryName            (Example: crafting call Alchemy)
  139.  *
  140.  * Recipe Setup
  141.  *  Recipes (At the moment) are created in the note field of the
  142.  *  item to be created and the format is as follows:
  143.  *
  144.  *  <recipe>
  145.  *   <materials>
  146.  *   {type:"itemtype", id:itemId, amount:numberRequired, cons:consumed?}
  147.  *   { + as many as you need }
  148.  *   <materials>
  149.  *   category:CategoryOfCraft                           (Name i.e. Blacksmith)
  150.  *   goldCost:costInGold                                (Number)
  151.  *   success:successRateBase                            (Number, 0 = 0%, 100 = 100%)
  152.  *   successGain:successRateChangePerLevelDifference    (Number, %)
  153.  *   level:levelRequired                                (Number)
  154.  *   xp:craftingExpEarned                               (Number)
  155.  *   xpDeprac:lossOfExpPerLevelDifference               (Number)
  156.  *   craftLevel:craftingLevelRequired                   (Number)
  157.  *   pxp:PlayerExpEarned                                (Number)
  158.  *   craftMultiple:allowMultipleCrafts                  (Boolean i.e. true)
  159.  *  <recipe>
  160.  *
  161.  *  Everything from goldCost to craftMultiple is optional (will be set to default 0-1 values)
  162.  *
  163.  *  Simplest recipe (example):
  164.  *   <recipe>
  165.  *    <material>
  166.  *     {type:"armor", id:3, amount:3, cons:false}
  167.  *    <material>
  168.  *    category:Blacksmith
  169.  *   <recipe>
  170.  *
  171.  *  Full Recipe (example):
  172.  *   <recipe>
  173.  *    <materials>
  174.  *    {type:"weapon", id:3, amount:3, cons:false}
  175.  *    {type:"armor", id:2, amount:3, cons:false}
  176.  *    <materials>
  177.  *    goldCost:0
  178.  *    success:80
  179.  *    successGain:2
  180.  *    level:1
  181.  *    category:Alchemy
  182.  *    xp:10
  183.  *    xpDeprac:2
  184.  *    craftLevel:1
  185.  *    pxp:5
  186.  *    craftMultiple:true
  187.  *   <recipe>
  188.  *
  189.  */
  190.  
  191. var $gameRecipes = null;
  192.  
  193. (function() {
  194.  
  195. var parameters = PluginManager.parameters('RecipeCrafting');
  196. var categoryNames = eval("[" + (parameters['Categories'] || '"Alchemy","Blacksmith","Tailor"') + "]");
  197. var categoryIcons = eval("[" + (parameters['Category Icons'] || "219,223,225") + "]");
  198. var xpFormula = parameters['Crafting XP Formula'] || "100 * lvl";
  199. var craftMultiple = (parameters['Craft Multiple'] || "true").toLowerCase() == "true";
  200. var craftFromMenu = parameters['Menu Craft Options'] || "craft";
  201. var tempdParam = "gold:true, chance:true, plevel:true, clevel:true"
  202. var displayParam = eval( "( { " + (parameters['Display Parameters'] || tempdParam) + " } )");
  203. var playerLevelIcon = parameters['Player Level Icon'] || 82;
  204. //Custom Text Inputs(DragonPC)
  205. var reqlevel = String(parameters['Required Level Text'] || 'Required level:');
  206. var reqmaterial = String(parameters['Required Material Text'] || 'Required material:');
  207. var sucRate = String(parameters['Success Rate Text'] || 'Success rate:');
  208. var craCost = String(parameters['Crafting Cost Text'] || 'Crafting costs:');
  209. var craText = String(parameters['Crafting Text'] || 'Craft');
  210. var craftedText = String(parameters['Crafted Text'] || 'Crafted!');
  211. var craFailed = String(parameters['Crafting Failed'] || 'Crafting failed!');
  212. var MLT = String(parameters['Max Level Test'] || 'MAX LEVEL');
  213. //End Custom Text(DragonPC)
  214. //Custom Sound(DragonPC)
  215. var success = String(parameters['Crafting Succeded Sound'] || 'Item3');
  216. var failure = String(parameters['Crafting Failed Sound'] || 'Scream');
  217. var failureVol = Number(parameters['Fail Sound Volume']);
  218. var successVol = Number(parameters['Success Sound Volume']);
  219. //End Custom Sound(DragonPC)
  220. //User Definable Max Level(DragonPC)
  221. var UDML = Number(parameters['User Definable Max Level']);
  222. //End User Definable Max Level
  223. //User Definable Colors(DragonPC)
  224. var colorCPV1 = Number(parameters['Success 0-20 Color']);
  225. var colorCPV2 = Number(parameters['Success 20-40 Color']);
  226. var colorCPV3 = Number(parameters['Success 40-60 Color']);
  227. var colorCPV4 = Number(parameters['Success 60-80 Color']);
  228. var colorCPV5 = Number(parameters['Success 80-100 Color']);
  229. //END User Definable Colors
  230. var categoryEventName = "";
  231.  
  232. function Recipe() {
  233. this.initialize.apply(this, arguments);
  234. }
  235. Recipe.prototype.initialize = function(id, type, recipe) {
  236. this._id = id;
  237. this._type = type;
  238. this._result = new Material(recipe.result);
  239. this._materials = [];
  240. for(var i = 0;i < recipe.materials.length;i++) {
  241. this._materials.push(new Material(recipe.materials[i]));
  242. }
  243. this._goldCost = recipe.goldCost ? Number(recipe.goldCost[1]) : 0;
  244. this._success = recipe.success ? Number(recipe.success[1]) : 100;
  245. this._successGain = recipe.successGain ? Number(recipe.successGain[1]) : 0;
  246. this._level = recipe.level ? Number(recipe.level[1]) : 0;
  247. this._category = recipe.category ? recipe.category[1] : categoryNames[0];
  248. this._xp = recipe.xp ? Number(recipe.xp[1]) : 100;
  249. this._xpDeprac = Number(recipe.xpDeprac) ? recipe.xpDeprac[1] : 0;
  250. //Changed EXP Gain To NON-EXESSIVE levels I.E. 0 (DragonPC) Changes!
  251. this._craftLevel = recipe.craftLevel ? Number(recipe.craftLevel[1]) : 0; //Number(recipe.craftLevel) ? recipe.craftLevel[1] : 1;
  252. this._pxp = recipe.playerXp ? Number(recipe.playerXp[1]) : 0; //Number(recipe.playerXp) ? recipe.playerXp[1] : 1;
  253. //End exp Changes End Change!
  254. this._craftMultiple = (recipe.multiple ? recipe.multiple[1] : "true").toLowerCase() == "true";
  255. }
  256. Recipe.prototype.name = function() { return this._result.name(); }
  257. Recipe.prototype.hasMaterials = function() {
  258. for(var i = 0;i < this._materials.length;i++) {
  259. var material = this._materials[i];
  260. if($gameParty.numItemsCrafting(material._item) < material._amount) {return false;}
  261. }
  262. return true;
  263. }
  264. Recipe.prototype.hasGold = function() { return $gameParty.gold() >= this._goldCost;}
  265. Recipe.prototype.hasCraftLevel = function() { return this._craftLevel <= $gameParty.craftLevel(this.categoryId());}
  266. Recipe.prototype.hasLevel = function() { return this._level <= $gameParty.highestLevel() && this.hasCraftLevel();}
  267. Recipe.prototype.craftable = function() { return this.hasGold() && this.hasMaterials() && this.hasLevel();}
  268. Recipe.prototype.amountCraftable = function() {
  269. var amount = 0;
  270. for(var i = 0;i < this._materials.length;i++) {
  271. var material = this._materials[i];
  272. var amountNext = $gameParty.numItemsCrafting(material._item) / material._amount
  273. if(amountNext > amount) {amount = amountNext;}
  274. }
  275. var amountGold = this._goldCost > 0 ? $gameParty.gold() / this._goldCost : 99;
  276. if(amountGold < amount) {amount = amountGold;}
  277. return Math.floor(amount);
  278. }
  279. Recipe.prototype.craft = function(failRate) {
  280. failRate = failRate || 0;
  281. this.removeMaterials();
  282. if(failRate < this.successRate()) {
  283. return this.addResult();
  284. }
  285. return null;
  286.  }
  287.  
  288. Recipe.prototype.removeMaterials = function() {
  289. for(var i = 0;i < this._materials.length;i++) {
  290. var material = this._materials[i];
  291. if(material._consumed) {
  292. $gameParty.gainItem(material._item, -material._amount);
  293. }
  294. }
  295. $gameParty.gainGold(-this._goldCost);
  296. }
  297. Recipe.prototype.addResult = function() {
  298. var newItem = this._result;
  299. $gameParty.gainItem(newItem._item,newItem._amount);
  300. $gameParty.gainCraftExp(this.categoryId(), this.xpGain());
  301. for(var i = 0;i < $gameParty.members().length;i++) {
  302. $gameParty.members()[i].gainExp(this._pxp);
  303. }
  304. return newItem._item;
  305. }
  306. Recipe.prototype.categoryId = function() { return categoryNames.indexOf(this._category);}
  307. Recipe.prototype.xpGain = function() {
  308. //User Definable Max Level(DragoncPC) Changes!
  309. if ($gameParty.craftLevel(this.categoryId()) < UDML) {
  310.             var levelDiff = $gameParty.craftLevel(this.categoryId()) - this._craftLevel;
  311. return Math.max(this._xp - this._xpDeprac * levelDiff,0);
  312.         }
  313. else {
  314. return Math.max (0, 0);
  315. }
  316. //User Definable Max Level end End Change
  317.  
  318. }
  319. Recipe.prototype.successRate = function() {
  320. var levelDiff = $gameParty.craftLevel(this.categoryId()) - this._craftLevel;
  321. return Math.min(this._success + this._successGain * levelDiff,100);
  322. }
  323.  
  324. function Material() {
  325. this.initialize.apply(this, arguments);
  326. }
  327. Material.prototype.initialize = function(material) {
  328. if(material.type == "item") {this._item = $dataItems[material.id];}
  329. if(material.type == "weapon") {this._item = $dataWeapons[material.id];}
  330. if(material.type == "armor") {this._item = $dataArmors[material.id];}
  331. this._amount = material.amount;
  332. this._consumed = material.consumed || true;
  333. }
  334. Material.prototype.name = function() {
  335. return this._item.name;
  336. }
  337.  
  338. var crafting_game_party_initialize = Game_Party.prototype.initialize;
  339. Game_Party.prototype.initialize = function() {
  340. crafting_game_party_initialize.call(this);
  341. this._craftingLevel = new Array(categoryNames.length);
  342. this._craftingExp = new Array(categoryNames.length);
  343. for(var i = 0;i < categoryNames.length;i++) {
  344. this._craftingLevel[i] = 1;
  345. this._craftingExp[i] = 0;
  346. }
  347. }
  348. Game_Party.prototype.craftLevel = function(id) { return this._craftingLevel[id]; }
  349. Game_Party.prototype.craftExp = function(id) { return this._craftingExp[id]; }
  350. Game_Party.prototype.craftExpNext = function(id) {
  351. var string = xpFormula.replace(/\lvl/g, this.craftLevel(id));
  352. return eval(string);
  353. }
  354. Game_Party.prototype.gainCraftExp = function(id, value) {
  355. this._craftingExp[id] += value;
  356. while(this.craftExp(id) >= this.craftExpNext(id)) {
  357. this._craftingExp[id] -= this.craftExpNext(id);
  358. this._craftingLevel[id]++;
  359. }
  360. }
  361. Game_Party.prototype.numItemsCrafting = function(item) {
  362. if(Object.keys(PluginManager.parameters('YEP_ItemCore')).length > 0) {
  363. return this.numIndependentItems(item);
  364. } else {
  365. return this.numItems(item);
  366. }
  367. }
  368.  
  369. var crafting_DataManager_createGameObjects = DataManager.createGameObjects;
  370. DataManager.createGameObjects = function() {
  371. crafting_DataManager_createGameObjects.call(this);
  372. $gameRecipes = this.createRecipes();
  373. }
  374. DataManager.createRecipes = function() {
  375. var recipes = [];
  376. for(var i = 1;i < $dataItems.length;i++) {
  377. if(!$dataItems[i]) {continue;}
  378. var recipeData = $dataItems[i].note.match(/<recipe>([^.]+)<recipe>/);
  379. if(recipeData) {
  380. recipes.push(new Recipe(i, "item", this.createRecipeStruct(i, "item", recipeData)));
  381. }
  382. }
  383. for(var i = 1;i < $dataWeapons.length;i++) {
  384. if(!$dataWeapons[i]) {continue;}
  385. var recipeData = $dataWeapons[i].note.match(/<recipe>([^.]+)<recipe>/);
  386. if(recipeData) {
  387. recipes.push(new Recipe(i, "weapon", this.createRecipeStruct(i, "weapon", recipeData)));
  388. }
  389. }
  390. for(var i = 1;i < $dataArmors.length;i++) {
  391. if(!$dataArmors[i]) {continue;}
  392. var recipeData = $dataArmors[i].note.match(/<recipe>([^.]+)<recipe>/);
  393. if(recipeData) {
  394. recipes.push(new Recipe(i, "armor", this.createRecipeStruct(i, "armor", recipeData)));
  395. }
  396. }
  397. return recipes;
  398. }
  399. DataManager.createRecipeStruct = function(id, type, recipeData) {
  400. var recipeStruct = {};
  401. recipeStruct.result = {type:type, id:id, amount:1}
  402. var materialData = recipeData[1].match(/<materials>([^.]+)<materials>/);
  403. materialData = eval( "[" + materialData[1].split("}").join("},") + "]" );
  404. recipeStruct.materials = materialData;
  405. recipeStruct.goldCost = recipeData[1].match(/goldCost:(.+)/);
  406. recipeStruct.success = recipeData[1].match(/success:(.+)/);
  407. recipeStruct.successGain = recipeData[1].match(/successGain:(.+)/);
  408. recipeStruct.level = recipeData[1].match(/level:(.+)/);
  409. recipeStruct.category = recipeData[1].match(/category:(.+)/);
  410. recipeStruct.xp = recipeData[1].match(/xp:(.+)/);
  411. recipeStruct.xpDeprac = recipeData[1].match(/xpDeprac:(.+)/);
  412. recipeStruct.craftLevel = recipeData[1].match(/craftLevel:(.+)/);
  413. recipeStruct.playerXp = recipeData[1].match(/pxp:(.+)/);
  414. recipeStruct.multiple = recipeData[1].match(/craftMultiple:(.+)/);
  415. return recipeStruct;
  416. }
  417.  
  418. function Window_RecipeList() {
  419. this.initialize.apply(this, arguments);
  420. }
  421. Window_RecipeList.prototype = Object.create(Window_Selectable.prototype);
  422. Window_RecipeList.prototype.constructor = Window_RecipeList;
  423. Window_RecipeList.prototype.initialize = function(x, y, w, h) {
  424. Window_Selectable.prototype.initialize.call(this, x, y, w, h);
  425. this.resetRecipes();
  426. }
  427. Window_RecipeList.prototype.maxItems = function() {
  428. return this._data ? this._data.length : 1;
  429. }
  430. Window_RecipeList.prototype.item = function() {
  431. return this._data && this._index >= 0 ? this._data[this._index] : null;
  432. }
  433. Window_RecipeList.prototype.currentItemEnabled = function() {
  434. return this.enable(this._data[this._index]);
  435. }
  436. Window_RecipeList.prototype.include = function(item) {
  437. if(!item.hasCraftLevel()) { return false; }
  438. //if(!$gameParty.recipeKnown(item)) {return false;}
  439. if(this._category == "all") {return true;}
  440. return this._category == item._category;
  441. }
  442. Window_RecipeList.prototype.setCategory = function(category) {
  443. if(category == this._category) { return; }
  444. this._category = category;
  445. this.resetRecipes();
  446. }
  447. Window_RecipeList.prototype.resetRecipes = function() {
  448. this._data = [];
  449. for(var i = 0;i < $gameRecipes.length;i++) {
  450. var recipe = $gameRecipes[i];
  451. if(this.include(recipe)) {this._data.push(recipe);}
  452. }
  453. this.refresh();
  454. }
  455. Window_RecipeList.prototype.isEnabled = function(item) {
  456. if(item) { return item.craftable(); }
  457. return false;
  458. }
  459. Window_RecipeList.prototype.drawItem = function(index) {
  460. var item = this._data[index];
  461. if(item) {
  462. rect = this.itemRect(index);
  463. rect.width -= 4;
  464. this.changePaintOpacity(this.isEnabled(item));
  465. this.drawItemName(item._result._item, rect.x, rect.y);
  466. if(item.amountCraftable() > 0) {
  467. this.drawText("x"+String(item.amountCraftable(),rect.x,rect.y,this.contents.width,"right"));
  468. }
  469. }
  470. }
  471. Window_RecipeList.prototype.currentItem = function() {
  472. return this._index >= 0 ? this._data[this._index] : null;
  473. }
  474. Window_RecipeList.prototype.processOk = function() {
  475. if (this.isCurrentItemEnabled()) {
  476. this.playOkSound();
  477. this.updateInputData();
  478. this.callOkHandler();
  479. } else {
  480. this.playBuzzerSound();
  481. }
  482. }
  483. Window_RecipeList.prototype.refresh = function() {
  484. this.createContents();
  485. Window_Selectable.prototype.refresh.call(this);
  486. }
  487. Window_RecipeList.prototype.contentsHeight = function() {
  488. return this.maxItems() * this.lineHeight();
  489. }
  490. Window_RecipeList.prototype.isCurrentItemEnabled = function() {
  491. return this.isEnabled(this.currentItem());
  492. }
  493.  
  494. function Window_RecipeDetail() {
  495. this.initialize.apply(this, arguments);
  496. }
  497. Window_RecipeDetail.prototype = Object.create(Window_Base.prototype);
  498. Window_RecipeDetail.prototype.constructor = Window_RecipeDetail;
  499. Window_RecipeDetail.prototype.initialize = function(x, y, w, h) {
  500. Window_Base.prototype.initialize.call(this, x, y, w, h);
  501. this._recipe = null;
  502. }
  503. Window_RecipeDetail.prototype.setRecipe = function(recipe) {
  504. if(recipe == this._recipe) {return;}
  505. this._recipe = recipe;
  506. this.refresh();
  507. }
  508. Window_RecipeDetail.prototype.refresh = function() {
  509. this.contents.clear();
  510. if(this._recipe) {
  511. if(displayParam.clevel || displayParam.plevel) {this.drawCraftLevel();}
  512. this.drawMaterials();
  513. if(displayParam.chance) { this.drawSuccessRate(); }
  514. if(displayParam.gold) {this.drawGoldCost();}
  515. }
  516. }
  517. Window_RecipeDetail.prototype.drawCraftLevel = function() {
  518. this.changePaintOpacity(this._recipe.hasLevel());
  519. this.changeTextColor(this.systemColor());
  520. //Custom Text Variable(DragonPC) Changes!
  521. this.drawText(reqlevel,0,0,this.contents.width);
  522. //End Custom Text End Change!
  523. this.changeTextColor(this.normalColor());
  524. var xx = 0;
  525. var text = "";
  526. if(displayParam.plevel) {
  527. this.drawText(String(this._recipe._level),0,0,this.contents.width,"right");
  528. this.drawIcon(playerLevelIcon,this.contents.width - 24 - Window_Base._iconWidth,0);
  529. xx += 68; //HERE
  530. // ADDED A SPACE! RIGHT HERE             --V Changes!
  531. text = String(this._recipe._craftLevel);
  532. text2 = " |";
  533. } else {
  534. text = String(this._recipe._craftLevel);
  535. }
  536. if(displayParam.clevel) {
  537. this.drawText(text,-15,0,this.contents.width - xx,"right");
  538. this.changeTextColor(this.systemColor());
  539. this.drawText(text2,0,0,this.contents.width - xx,"right");
  540. this.changeTextColor(this.normalColor());
  541. //End Changes End Changes
  542. this.drawIcon(categoryIcons[this._recipe.categoryId()],this.contents.width - 75 - xx,0); //HERE
  543. }
  544. }
  545. Window_RecipeDetail.prototype.drawMaterials = function() {
  546. // Changed From 0 to 20 (DragonPC) Changes!
  547. var yy = 20;
  548. if(displayParam.clevel || displayParam.plevel) {yy = this.contents.fontSize + 20;}
  549. //Change END. End Change
  550. this.changePaintOpacity(this._recipe.craftable());
  551. this.changeTextColor(this.systemColor());
  552. //Custom Text Variable(DragonPC) Changes!
  553. this.drawText(reqmaterial,0,yy,this.width);
  554. //end Custom End Change
  555. yy += this.contents.fontSize + this.textPadding();
  556. for(var i = 0;i < this._recipe._materials.length;i++) {
  557. var item = this._recipe._materials[i];
  558. this.changePaintOpacity($gameParty.numItemsCrafting(item._item) >= item._amount);
  559. this.changeTextColor(this.normalColor());
  560. this.drawIcon(item._item.iconIndex,0,yy);
  561. this.drawText(item._item.name,Window_Base._iconWidth,yy,this.width);
  562. //Changed Text Color to show green for more than and red for not enough.(DragonPC) Changes!
  563. var ItemAmount = $gameParty.numItemsCrafting(item._item);
  564. var AmtNeeded = item._amount;
  565.  
  566. if (ItemAmount >= AmtNeeded) {
  567.                 this.changeTextColor(this.textColor(3));
  568. this.drawText(String(ItemAmount),-50,yy,this.contents.width,"right");
  569.             }
  570. else {
  571. this.changeTextColor(this.textColor(18));
  572. this.drawText(String(ItemAmount),-50,yy,this.contents.width,"right");
  573. }
  574. this.changeTextColor(this.normalColor());
  575. var string = " / " + String(AmtNeeded);
  576. this.drawText(string,0,yy,this.contents.width,"right");
  577. //End Changes End Changes
  578. yy += this.contents.fontSize  + this.textPadding();
  579. }
  580. }
  581. Window_RecipeDetail.prototype.drawSuccessRate = function() {
  582. //Custom Variable(DragonPC)
  583. var CPV = this._recipe.successRate()
  584. //End Custom Variable
  585. this.changePaintOpacity(this._recipe.craftable());
  586. this.changeTextColor(this.systemColor());
  587. //Changed yy Variable to -5 to prevent Clipping(DragonPC) Changes!
  588. var yy = this.contents.height - this.contents.fontSize - this.textPadding() - 5;
  589. //End Change End Change
  590. //Custom Text Variable(DragonPC) Changes!
  591. this.drawText(sucRate,0,yy,this.contents.width);
  592. //End Custom Text Entry End Change
  593.  
  594. //User Definable Colors(DragonPC) Changes!
  595. if (CPV > 0) {
  596. this.changeTextColor(this.textColor(colorCPV1));//code
  597. }
  598. if (CPV > 20) {
  599. this.changeTextColor(this.textColor(colorCPV2));//code
  600. }
  601. if (CPV > 40) {
  602. this.changeTextColor(this.textColor(colorCPV3));//code
  603. }
  604. if (CPV > 60) {
  605. this.changeTextColor(this.textColor(colorCPV4));//code
  606. }
  607. if (CPV > 80) {
  608. this.changeTextColor(this.textColor(colorCPV5));//code
  609. }
  610.  
  611. this.drawText(CPV + "%",0,yy,this.contents.width,"right");
  612. this.changeTextColor(this.normalColor());
  613. //END User Definable Colors(DragonPC) End Change
  614. }
  615.  
  616. Window_RecipeDetail.prototype.drawGoldCost = function() {
  617. if(this._recipe._goldCost > 0) {
  618. this.changePaintOpacity(this._recipe.hasGold());
  619. this.changeTextColor(this.systemColor());
  620. //Custom Text Variable (DragonPC) Changes!
  621. this.drawText(craCost,0,this.contents.height-this.contents.fontSize*2 - 15,this.contents.width);
  622. //Custom Text End Change End
  623.  
  624. if (this._recipe._goldCost > $gameParty.gold()) {
  625. this.changeTextColor(this.textColor(18));
  626.             }
  627. else {
  628. this.changeTextColor(this.textColor(3))
  629. }
  630. this.drawText(this._recipe._goldCost, - 40,this.contents.height-this.contents.fontSize*2 - 15,this.contents.width, 'right')
  631. this.drawIcon(Yanfly.Icon.Gold,Graphics.boxWidth/2-68,this.contents.height-this.contents.fontSize*2 - 15)
  632. this.changeTextColor(this.normalColor());
  633. }
  634. }
  635. Window_RecipeDetail.prototype.drawCurrencyValue = function(value, unit, x, y, width) {
  636. var unitWidth = Math.min(80, this.textWidth(unit));
  637. this.resetTextColor();
  638. this.changePaintOpacity(this._recipe.hasGold());
  639. this.drawText(value, x, y, width - unitWidth - 6, 'right');
  640. this.changeTextColor(this.systemColor());
  641. this.drawText(unit, x + width - unitWidth, y, unitWidth, 'right');
  642. }
  643.  
  644. function Window_RecipeConfirm() {
  645. this.initialize.apply(this, arguments);
  646. }
  647. Window_RecipeConfirm.prototype = Object.create(Window_Selectable.prototype);
  648. Window_RecipeConfirm.prototype.constructor = Window_RecipeConfirm;
  649. Window_RecipeConfirm.prototype.initialize = function(x, y, w, h) {
  650. Window_Selectable.prototype.initialize.call(this, x, y, w, h);
  651. this._amount = 1;
  652. this.refresh();
  653. }
  654. Window_RecipeConfirm.prototype.itemMax = function() {return 1;}
  655. Window_RecipeConfirm.prototype.enable = function() {return true;}
  656. Window_RecipeConfirm.prototype.refresh = function() {
  657. Window_Selectable.prototype.refresh.call(this);
  658. //Custom Text Variable(DragonPC) Changes!
  659. this.drawText(craText,0,0,this.contents.width,"center");
  660. //Custom Text End Change End
  661. if(this._recipe && this._recipe.craftable()) {
  662. this.drawText("x" + String(this._amount),0,0,this.contents.width,"right");
  663. }
  664. }
  665. Window_RecipeConfirm.prototype.activate = function() {
  666. Window_Selectable.prototype.activate.call(this);
  667. this.select(0);
  668. }
  669. Window_RecipeConfirm.prototype.deactivate = function() {
  670. Window_Selectable.prototype.deactivate.call(this);
  671. this.deselect();
  672. }
  673. Window_RecipeConfirm.prototype.setRecipe = function(recipe) {
  674. if(recipe == this._recipe) { return; }
  675. this._recipe = recipe;
  676. this._amount = 1;
  677. this.refresh();
  678. }
  679. Window_RecipeConfirm.prototype.isCursorMovable = function() {
  680. return this.isOpenAndActive() && craftMultiple && this._recipe._craftMultiple;
  681. }
  682. Window_RecipeConfirm.prototype.cursorDown = function(wrap) { this.changeAmount(-10);}
  683. Window_RecipeConfirm.prototype.cursorUp = function(wrap) { this.changeAmount(10);}
  684. Window_RecipeConfirm.prototype.cursorRight = function(wrap) { this.changeAmount(1);}
  685. Window_RecipeConfirm.prototype.cursorLeft = function(wrap) { this.changeAmount(-1);}
  686. Window_RecipeConfirm.prototype.changeAmount = function(value) {
  687. SoundManager.playCursor();
  688. this._amount += value;
  689. this._amount = Math.min(Math.max(this._amount,1),this._recipe.amountCraftable());
  690. this.refresh();
  691. }
  692.  
  693. function Scene_Crafting() {
  694. this.initialize.apply(this, arguments);
  695. }
  696. Scene_Crafting.prototype = Object.create(Scene_MenuBase.prototype);
  697. Scene_Crafting.prototype.constructor = Scene_Crafting;
  698. Scene_Crafting.prototype.initialize = function() {
  699. Scene_MenuBase.prototype.initialize.call(this);
  700. }
  701. Scene_Crafting.prototype.create = function() {
  702. Scene_MenuBase.prototype.create.call(this);
  703. this._helpWindow = new Window_Help();
  704. var width = Graphics.width / 2;
  705. var height = Graphics.height - this._helpWindow.height;
  706. this._listWindow = new Window_RecipeList(0,this._helpWindow.height+72,width,height-72*2);
  707. this._listWindow.setHandler('ok',this.listSuccess.bind(this));
  708. this._listWindow.setHandler('cancel',this.cancel.bind(this));
  709. if(!displayParam.clevel) { this._listWindow.height += this._listWindow.fittingHeight(1); }
  710. this._listWindow.createContents();
  711. this._detailWindow = new Window_RecipeDetail(width,this._listWindow.y,width,height-72*2);
  712. if(!displayParam.gold) { this._detailWindow.height += this._detailWindow.fittingHeight(1); }
  713. this._detailWindow.createContents();
  714. height = this._detailWindow.y + this._detailWindow.height;
  715. this._confirmWindow = new Window_RecipeConfirm(width,height,width,72);
  716. this._confirmWindow.setHandler('ok',this.craftSuccess.bind(this));
  717. this._confirmWindow.setHandler('cancel',this.confirmCancel.bind(this));
  718. if(displayParam.gold) {
  719. this._goldWindow = new Window_Gold();
  720. this._goldWindow.width = width;
  721. this._goldWindow.y = Graphics.height - 72;
  722. this._goldWindow.x = width;
  723. }
  724. this._popupWindow = new Window_RecPopup();
  725. this._popupWindow.setHandler('ok',this.popupOk.bind(this));
  726. this._popupWindow.setHandler('cancel',this.popupOk.bind(this));
  727. this._commandWindow = new Window_RecCategory();
  728. this._commandWindow.setHandler('ok',this.commandOk.bind(this));
  729. this._commandWindow.setHandler('cancel',this.commandCancel.bind(this));
  730. if(displayParam.clevel) {this._gaugeWindow = new Window_RecGauge();}
  731. this.addWindow(this._helpWindow);
  732. this.addWindow(this._listWindow);
  733. this.addWindow(this._detailWindow);
  734. this.addWindow(this._confirmWindow);
  735. if(this._goldWindow) {this.addWindow(this._goldWindow);}
  736. this.addWindow(this._popupWindow);
  737. this.addWindow(this._commandWindow);
  738. if(this._gaugeWindow) {this.addWindow(this._gaugeWindow);}
  739. }
  740. Scene_Crafting.prototype.popupOk = function() {
  741. this._popupWindow.deactivate();
  742. this._popupWindow.close();
  743. this._listWindow.activate();
  744. }
  745. Scene_Crafting.prototype.update = function() {
  746. Scene_Base.prototype.update.call(this);
  747. if(this._listWindow.currentItem()) {this._helpWindow.setText(this._listWindow.currentItem()._result._item.description);}
  748. if(this._commandWindow.isOpenAndActive()) {
  749. this._helpWindow.setText("");
  750. }
  751. this._detailWindow.setRecipe(this._listWindow.currentItem());
  752. this._confirmWindow.setRecipe(this._listWindow.currentItem());
  753. this._listWindow.setCategory(categoryNames[this._commandWindow._index]);
  754. if(this._gaugeWindow) { this._gaugeWindow.setCategory(categoryNames[this._commandWindow._index]);}
  755. if(this._listWindow.currentItem()) {
  756. if(this._listWindow.currentItem().craftable()) {
  757. this._confirmWindow.opacity = 255;
  758. this._confirmWindow.contentsOpacity = 255;
  759. } else {
  760. this._confirmWindow.opacity = 75;
  761. this._confirmWindow.contentsOpacity = 75;
  762. }
  763. }
  764. }
  765. Scene_Crafting.prototype.listSuccess = function() {
  766. this._listWindow.deactivate();
  767. if(this._goldWindow) {this._goldWindow.close();}
  768. this._confirmWindow.activate();
  769. }
  770. Scene_Crafting.prototype.craftSuccess = function() {
  771. var amount = 0;
  772. var item = null;
  773. for(var i = 0;i < this._confirmWindow._amount;i++) {
  774. var item2 = this._listWindow.currentItem().craft(Math.random() * 100);
  775. if(item2) { amount++;item = item2;}
  776. }
  777. if(item) {
  778. this._popupWindow.setText(item, amount);
  779. } else {
  780. this._popupWindow.setTextFail();
  781. }
  782. this._confirmWindow.changeAmount(-1000);
  783. if(this._goldWindow) {this._goldWindow.refresh();}
  784. this._listWindow.refresh();
  785. if(this._gaugeWindow) {this._gaugeWindow.refresh();}
  786. this._popupWindow.activate();
  787. this._detailWindow.refresh();
  788. }
  789. Scene_Crafting.prototype.confirmCancel = function() {
  790. this._confirmWindow.deactivate();
  791. if(this._goldWindow) {this._goldWindow.open();}
  792. this._listWindow.activate();
  793. }
  794. Scene_Crafting.prototype.commandCancel = function() {
  795. this.popScene();
  796. }
  797. Scene_Crafting.prototype.cancel = function() {
  798. this._listWindow.select(-1);
  799. this._helpWindow.setText("");
  800. this._commandWindow.activate();
  801. }
  802. Scene_Crafting.prototype.commandOk = function() {
  803. this._listWindow.select(0);
  804. this._listWindow.activate();
  805. }
  806.  
  807. function Scene_CraftingSpecific() {
  808. this.initialize.apply(this, arguments);
  809. }
  810. Scene_CraftingSpecific.prototype = Object.create(Scene_Crafting.prototype);
  811. Scene_CraftingSpecific.prototype.constructor = Scene_CraftingSpecific;
  812. Scene_CraftingSpecific.prototype.initialize = function() {
  813. Scene_Crafting.prototype.initialize.call(this);
  814. }
  815. Scene_CraftingSpecific.prototype.create = function() {
  816. Scene_Crafting.prototype.create.call(this);
  817. this._commandWindow._index = categoryNames.indexOf(categoryEventName);
  818. this._commandWindow.deactivate();
  819. this._commandWindow.visible = false;
  820. this._listWindow.height += this._listWindow.fittingHeight(1);
  821. this._listWindow.y -= this._listWindow.fittingHeight(1);
  822. this._detailWindow.height += this._listWindow.fittingHeight(1);
  823. this._detailWindow.y -= this._listWindow.fittingHeight(1);
  824. this._listWindow.createContents();
  825. this._detailWindow.createContents();
  826. this._listWindow.select(0);
  827. this._listWindow.activate();
  828. }
  829. Scene_CraftingSpecific.prototype.cancel = function() { this.popScene(); }
  830.  
  831.  
  832. function Window_RecCategory() {
  833. this.initialize.apply(this, arguments);
  834. }
  835. Window_RecCategory.prototype = Object.create(Window_HorzCommand.prototype);
  836. Window_RecCategory.prototype.constructor = Window_RecCategory;
  837. Window_RecCategory.prototype.initialize = function() {
  838. Window_HorzCommand.prototype.initialize.call(this, 0, this.fittingHeight(2));
  839. }
  840. Window_RecCategory.prototype.windowWidth = function() { return Graphics.width; }
  841. Window_RecCategory.prototype.windowHeight = function() { return this.fittingHeight(1); }
  842. Window_RecCategory.prototype.makeCommandList = function() {
  843. for(var i = 0;i < categoryNames.length;i++) {
  844. this.addCommand(categoryNames[i],categoryNames[i]);
  845. }
  846. }
  847. Window_RecCategory.prototype.itemWidth = function() {return this.width / 5;}
  848. Window_RecCategory.prototype.drawItem = function(index) {
  849. this.changePaintOpacity(this.isCommandEnabled(index));
  850. var rect = this.itemRectForText(index);
  851. this.drawText(this.commandName(index),rect.x,rect.y,rect.width);
  852. this.drawIcon(categoryIcons[index],rect.x-Window_Base._iconWidth,rect.y+2);
  853. }
  854. Window_RecCategory.prototype.itemRectForText = function(index) {
  855. var rect = this.itemRect(index);
  856. rect.x += Window_Base._iconWidth;
  857. rect.width -= Window_Base._iconWidth;
  858. return rect;
  859. }
  860.  
  861. function Window_RecPopup() {
  862. this.initialize.apply(this, arguments);
  863. }
  864. Window_RecPopup.prototype = Object.create(Window_Selectable.prototype);
  865. Window_RecPopup.prototype.constructor = Window_RecPopup;
  866. Window_RecPopup.prototype.initialize = function() {
  867. //Fixed Popup to not truncate text CHANGES
  868. Window_Selectable.prototype.initialize.call(this, Graphics.width/2-this.windowWidth()/2,Graphics.height/2-this.windowHeight()/2,300,this.fittingHeight(1));
  869. this.openness = 0;
  870. this.deactivate();
  871. }
  872. Window_RecPopup.prototype.windowWidth = function() {return 300;}
  873. //end changes end changes
  874. Window_RecPopup.prototype.windowHeight = function() {return this.fittingHeight(1);}
  875. Window_RecPopup.prototype.setText = function(item, amount) {
  876. this.contents.clear();
  877. // Added Sound on Success(DragonPC) CHANGES!!
  878. var SuccessSound = {
  879. name:   success,
  880. volume: successVol,
  881. pitch:  100,
  882. pan:    0,
  883.   };
  884.  
  885.   AudioManager.playSe(SuccessSound);
  886. //Sound End Change end
  887. //Custom Text Variable(DragonPC) Changes!
  888. var text = String(amount) + "x " + item.name + " " + craftedText;
  889. //Custom Text Variable End Change End
  890. var width = this.textWidth(text) + Window_Base._iconWidth;
  891. console.log(width);
  892. this.width = width + this.standardPadding() * 2;
  893. console.log(this.width);
  894. this.x = (Graphics.width-width)/2
  895. this.createContents();
  896. this.drawText(text,Window_Base._iconWidth,0,this.contents.width);
  897. this.drawIcon(item.iconIndex,0,0);
  898. this.open();
  899. }
  900. Window_RecPopup.prototype.setTextFail = function() {
  901. this.contents.clear();
  902.          //Added Failure Sound(DragonPC) Changes!!!
  903. var FailureSound = {
  904. name:   failure,
  905. volume: failureVol,
  906. pitch:  100,
  907. pan:    0,
  908. };
  909.  
  910. AudioManager.playSe(FailureSound);
  911. //End Changes End Changes!!  
  912.  
  913. //Custom Text Variable(DragoncPC) (Changed Popup Minimum Value to prevent Truncation of text) Changes!
  914. var text = craFailed;
  915. var width = this.textWidth(text) + 60;
  916. //Custome Text End End Change
  917. this.width = width + this.textPadding() * 2;
  918. this.x = (Graphics.width-width)/2;
  919. this.createContents();
  920. this.drawText(text,18,0,this.contents.width);
  921. this.open();
  922. }
  923. Window_RecPopup.prototype.processOk = function() {
  924. if (this.isCurrentItemEnabled()) {
  925. this.updateInputData();
  926. this.deactivate();
  927. this.callOkHandler();
  928. } else {
  929. this.playBuzzerSound();
  930. }
  931. }
  932.  
  933. function Window_RecGauge() {
  934. this.initialize.apply(this, arguments);
  935. }
  936. Window_RecGauge.prototype = Object.create(Window_Base.prototype);
  937. Window_RecGauge.prototype.constructor = Window_RecGauge;
  938. Window_RecGauge.prototype.initialize = function() {
  939. Window_Selectable.prototype.initialize.call(this, 0,Graphics.height-this.fittingHeight(1),Graphics.width/2,this.fittingHeight(1));
  940. this._category = "all";
  941. }
  942. Window_RecGauge.prototype.refresh = function() {
  943. this.contents.clear();
  944. if(this._category == "all") {return;}
  945. this.drawIcon(categoryIcons[this.catIndex()],0,0);
  946. //Changed Guage Width so level 100+ will not Overlap(DragonPC) Changes!
  947. this.drawText($gameParty.craftLevel(this.catIndex()),Window_Base._iconWidth,0,this.contents.width);
  948. if ($gameParty.craftLevel(this.catIndex()) === UDML) {
  949. this.changeTextColor(this.textColor(20));
  950. this.drawText(MLT,0,0,this.contents.width,"right");
  951. this.changeTextColor(this.normalColor());
  952. }
  953. else{
  954. var rate = $gameParty.craftExp(this.catIndex()) / $gameParty.craftExpNext(this.catIndex());
  955. this.drawGauge(80,-3,this.contents.width-80,rate,this.tpGaugeColor1(),this.tpGaugeColor2());
  956. text = String($gameParty.craftExp(this.catIndex())) + "/" + String($gameParty.craftExpNext(this.catIndex()));
  957. this.drawText(text,0,0,this.contents.width,"right");
  958. }
  959.  
  960. //End Change End Change
  961. }
  962. Window_RecGauge.prototype.setCategory = function(cat) {
  963. if(cat == this._category) {return;}
  964. this._category = cat;
  965. this.refresh();
  966. }
  967. Window_RecGauge.prototype.catIndex = function() {
  968. return categoryNames.indexOf(this._category);
  969. }
  970.  
  971. var crafting_window_menucommand_addoriginalcommands = Window_MenuCommand.prototype.addOriginalCommands;
  972. Window_MenuCommand.prototype.addOriginalCommands = function() {
  973. crafting_window_menucommand_addoriginalcommands.call(this);
  974. if(craftFromMenu != "off") { this.addCommand("Crafting","crafting"); }
  975. }
  976.  
  977. var crafting_scene_menu_createcommandwindow = Scene_Menu.prototype.createCommandWindow;
  978. Scene_Menu.prototype.createCommandWindow = function() {
  979. crafting_scene_menu_createcommandwindow.call(this);
  980. this._commandWindow.setHandler("crafting",this.commandRecipe.bind(this));
  981. }
  982. Scene_Menu.prototype.commandRecipe = function() {
  983. SceneManager.push(Scene_Crafting);
  984. }
  985.  
  986. var RecipeCrafting_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  987. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  988. RecipeCrafting_Game_Interpreter_pluginCommand.call(this, command, args);
  989. if(command === 'crafting' && args[0] === 'call') {
  990. categoryEventName = args[1]
  991. SceneManager.push(Scene_CraftingSpecific);
  992. }
  993. }
  994.  
  995. //YEP-ITEMCORE
  996. Game_Party.prototype.numIndependentItems = function(item) {
  997. if(!item) return null;
  998. if (DataManager.isIndependent(item)) {
  999. if (DataManager.isItem(item)) var group = this.items();
  1000. if (DataManager.isWeapon(item)) var group = this.weapons();
  1001. if (DataManager.isArmor(item)) var group = this.armors();
  1002. var baseItemId = item.id;
  1003. var amount = 0;
  1004. for (var i = 0; i < group.length; ++i) {
  1005. var item = group[i];
  1006. if (!item) continue;
  1007. if (!item.baseItemId) continue;
  1008. if (item.baseItemId !== baseItemId) continue;
  1009. if (this.checkItemIsEquipped(item)) continue;
  1010. amount++;
  1011. }
  1012. return amount;
  1013. } else {
  1014. return this.numItems(item);
  1015. }
  1016. }
  1017. })();
Advertisement
Add Comment
Please, Sign In to add comment