查看: 2907|回复: 0

[已经过期] 这个装备镶嵌宝石的脚本遇到了点问题

[复制链接]
梦石
0
星屑
1788
在线时间
1313 小时
注册时间
2012-8-4
回帖
724
发表于 2016-5-19 20:36:24 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
就是 假如 你有 5把铜剑一把铁剑 ,1个铜剑合了一个攻击宝石 ,然后另外4把也有宝石了,铁剑没有

不想其他4把铜剑也会有宝石,怎么改


脚本
  1. //=============================================================================
  2. // Bobstah Plugins
  3. // BOB_SocketsEx.js
  4. // Version: 1.0
  5. //=============================================================================
  6. var Imported = Imported || {};
  7. Imported.BOB_SocketsEx = true;

  8. var Bobstah = Bobstah || {};
  9. Bobstah.SocketsEx = Bobstah.SocketsEx || {};

  10. //=============================================================================
  11. /*:
  12. * @plugindesc Implements a socketing system inspired by Diablo II.
  13. * @author Bobstah
  14. *
  15. * @param Socket Menu Name
  16. * @desc The name of the socket menu item in the main menu.
  17. * @default Sockets
  18. *
  19. * @param Empty Socket Icon
  20. * @desc The icon to use for empty sockets.
  21. * @default 160
  22. *
  23. * @param Empty Socket Text
  24. * @desc The text to display when a socket is empty.
  25. * @default Empty
  26. *
  27. * @help
  28. * ============================================================================
  29. * Introduction
  30. * ============================================================================
  31. * This plugin allows you to socket armors with a type of none
  32. * into other weapons or armors that have sockets.
  33. *
  34. * To create socketable item or to add sockets to an item, see
  35. * the Notetags section below.
  36. *
  37. * ============================================================================
  38. * How it works
  39. * ============================================================================
  40. * Whenever you socket an item into a weapon or armor, all of the item's
  41. * stat changes and traits are copied onto the parent item. If you
  42. * unsocket the source of the stat changes and traits, they are
  43. * removed from the parent item.
  44. *
  45. * For example:
  46. * Let's say that we create an armor with a type of none, and set the
  47. * <SocketEx> tag on it. It can now be socketed into weapons and armor
  48. * that contain sockets.
  49. *
  50. * For this exmaple, we're going to name the above item Gem. If
  51. * we say Gem gives +5 atk and +5 def, and we socket it into
  52. * a Shield, that shield gains an additional +5 atk and
  53. * +5 def. If Gem granted a skill and decreased Crit Rate,
  54. * these changes would be copied onto the source item as well.
  55. *
  56. * The icon that the Gem uses will replace the empty socket icon
  57. * in all item views.
  58. *
  59. * ============================================================================
  60. * Notetags
  61. * ============================================================================
  62. * Socket Gems must be an Armor item with a Type of 'None'. Once
  63. * that is set, add the following to make it a socketable item:
  64. * <SocketEx>
  65. *
  66. * Optionally, you can restrict it to be only for weapons or armor:
  67. * <SocketEx Weapon>
  68. * <SocketEx Armor>
  69. *
  70. * You can drill down even further and restrict it to a limited number
  71. * of weapon and armor types:
  72. * <SocketEx Weapon: ID, ID, etc>
  73. * <SocketEx Armor: ID, ID, etc>
  74. *
  75. * To give a weapon or armor sockets, use the following notetag:
  76. *  <Sockets: X>
  77. * Where X is the number of sockets the item has.
  78. */

  79. //=============================================================================
  80. // Parameter Variables
  81. //=============================================================================

  82. Bobstah.Parameters = PluginManager.parameters('BOB_SocketsEx');
  83. Bobstah.Param = Bobstah.Param || {};

  84. Bobstah.Param.SocketsEx_CommandName = String(Bobstah.Parameters['Socket Menu Name']);
  85. Bobstah.Param.SocketsEx_EmptyIcon = Number(Bobstah.Parameters['Empty Socket Icon']);
  86. Bobstah.Param.SocketsEx_EmptyName = Bobstah.Parameters['Empty Socket Text'];

  87. //=============================================================================
  88. // Plugin Functions - General
  89. //=============================================================================
  90. Bobstah.SocketsEx.commandName = function() {
  91.         return Bobstah.Param.SocketsEx_CommandName;
  92. };

  93. Bobstah.SocketsEx.commandSymbol = function() {
  94.         return "SocketsEx";
  95. };

  96. //=============================================================================
  97. // Plugin Functions - Socket Info Objects & Nodes
  98. //=============================================================================
  99. Bobstah.SocketsEx.createSocketInfoObject = function() {
  100.         return new SocketsExSocketable();
  101. };

  102. Bobstah.SocketsEx.createSocketInfoNode = function(socketIds, evl) {
  103.         evl = evl || false;
  104.         var obj = {
  105.                 'ids': socketIds,
  106.                 'eval': evl
  107.         };
  108.         return obj;
  109. };

  110. //=============================================================================
  111. // Plugin Functions - Sockets Ex Objects & Nodes
  112. //=============================================================================
  113. Bobstah.SocketsEx.createSocketsExObject = function(defaultSockets, evl) {
  114.         return new SocketsEx(defaultSockets, evl);
  115. };

  116. Bobstah.SocketsEx.createSocketsExNode = function() {
  117.         return new SocketsExSocket();
  118.        
  119.         return obj;
  120. };

  121. //=============================================================================
  122. // Plugin Objects - SocketsEx
  123. //=============================================================================
  124. function SocketsEx(defaultSockets, evl) {
  125.         this._defaultSockets = defaultSockets;
  126.         this._sockets = [],
  127.         this._eval = evl,
  128.         this._ready = false
  129. }

  130. SocketsEx.prototype.hasSockets = function() {
  131.         return this._sockets.length > 0;
  132. };

  133. SocketsEx.prototype.setupSockets = function(sockets, evl) {
  134.         if (evl === true) {
  135.                 this._defaultSockets = sockets;
  136.                 this._eval = evl;
  137.         } else {
  138.                 this._createEmptySockets(sockets);
  139.                 this._ready = true;
  140.         }
  141. };

  142. SocketsEx.prototype.isSocketFull = function(socketId) {
  143.         if (this._sockets[socketId]) {
  144.                 return this._sockets[socketId].isFull();
  145.         }
  146.         return false;
  147. };

  148. SocketsEx.prototype._createEmptySockets = function(number) {
  149.         for (var i = 0; i < number; i++) {
  150.                 this._sockets.push(Bobstah.SocketsEx.createSocketsExNode());
  151.         }
  152. };

  153. SocketsEx.prototype.update = function(owner) {
  154.         for (var i = 0; i < this.sockets.length; i++) {
  155.                 this.processRemoval(owner, this.sockets[i]);
  156.                 this.sockets[i].removed();
  157.                 this.processApply(owner, this.sockets[i]);
  158.                 this.sockets[i].inserted();
  159.         }
  160. };


  161. SocketsEx.prototype.processApply = function(owner, socket) {
  162.         var params = socket.params();
  163.         if (params === null) { return; }
  164.         for (var p = 0; p < params.length; p++) {
  165.                 owner.params[p] += params[p];
  166.         }
  167.         var traits = socket.traits();
  168.         if (traits === null) { return; }
  169.         for (var t = 0; t < traits.length; t++) {
  170.                 owner.traits.push(traits[t]);
  171.         }
  172. };

  173. SocketsEx.prototype.processRemoval = function(owner, socket) {
  174.         var params = socket.params();
  175.         if (params !== null) {
  176.                 for (var p = 0; p < params.length; p++) {
  177.                         owner.params[p] -= params[p];
  178.                 }
  179.         }
  180.         var traits = socket.traits();
  181.         if (traits !== null) {
  182.                 for (var t = 0; t < traits.length; t++) {
  183.                         for (var n = 0; n < owner.traits.length; n++) {
  184.                                 var oTrait = owner.traits[n];
  185.                                 var sTrait = traits[t];
  186.                                 if (sTrait.code === oTrait.code) {
  187.                                         if (sTrait.dataId === oTrait.dataId) {
  188.                                                 if (sTrait.value === oTrait.value) {
  189.                                                         owner.traits.splice(n,1);
  190.                                                 }
  191.                                         }
  192.                                 }
  193.                         }
  194.                 }
  195.         }
  196. };

  197. Object.defineProperties(SocketsEx.prototype, {
  198.         sockets: {
  199.                 get: function() {
  200.                         if (this._ready === false) {
  201.                                 if (this._eval === true) {
  202.                                         //Do some evaling here, somehow.
  203.                                 } else {
  204.                                         this.setupSockets(this._defaultSockets, false);
  205.                                 }
  206.                         }
  207.                         return this._sockets;
  208.                 },
  209.                
  210.                 configurable: true
  211.         }
  212. });

  213. //=============================================================================
  214. // Plugin Objects - SocketsExSocket
  215. //=============================================================================
  216. function SocketsExSocket() {
  217.         this._sourceItem = null;
  218.         this._inserted = false;
  219.         this._removed = false;
  220.         this._lastItem = null;
  221. }

  222. SocketsExSocket.prototype.isFull = function() {
  223.         return this._sourceItem !== null;
  224. };

  225. SocketsExSocket.prototype.isEmpty = function() {
  226.         return !this.isFull();
  227. };

  228. SocketsExSocket.prototype.insertItem = function(item) {
  229.         //Plugin Param to check if item given back
  230.         var lastItem = this.removeItem();
  231.         this._sourceItem = item;
  232.         this._inserted = true;
  233.         return lastItem;
  234. };

  235. SocketsExSocket.prototype.removeItem = function() {
  236.         this._lastItem = this._sourceItem;
  237.         this._removed = true;
  238.         this._sourceItem = null;
  239.         return this._lastItem;
  240. };

  241. SocketsExSocket.prototype.params = function() {
  242.         var res = [];
  243.         if (this._removed) {
  244.                 if (this._lastItem !== null) {
  245.                         res = this._lastItem.params;
  246.                 } else {
  247.                         res = [];
  248.                 }
  249.         } else {
  250.                 if (this._inserted) {
  251.                         if (this._sourceItem !== null) {
  252.                                 res = this._sourceItem.params;
  253.                         } else {
  254.                                 res = [];
  255.                         }
  256.                 }
  257.         }
  258.         return res;
  259. };
  260.        
  261. SocketsExSocket.prototype.traits = function() {
  262.         var res = [];
  263.         if (this._removed) {
  264.                 if (this._lastItem !== null) {
  265.                         res = this._lastItem.traits;
  266.                 } else {
  267.                         res = [];
  268.                 }
  269.         } else {
  270.                 if (this._inserted) {
  271.                         if (this._sourceItem !== null) {
  272.                                 res = this._sourceItem.traits;
  273.                         } else {
  274.                                 res = [];
  275.                         }
  276.                 }
  277.         }
  278.         return res;
  279. };

  280. SocketsExSocket.prototype.removed = function() {
  281.         this._removed = false;
  282. };

  283. SocketsExSocket.prototype.inserted = function() {
  284.         this._inserted = false;
  285. };

  286. Object.defineProperties(SocketsExSocket.prototype, {
  287.         sourceId: {
  288.                 get: function() {
  289.                         return this._sourceId
  290.                 },
  291.                 configurable: true
  292.         },
  293.         item: {
  294.                 get: function() {
  295.                         return this._sourceItem
  296.                 },
  297.                 configurable: true
  298.         },
  299.         applied: {get: function() {
  300.                         return this._applied
  301.                 },
  302.                 configurable: true
  303.         }
  304. });

  305. //=============================================================================
  306. // Plugin Objects - SocketsExSocketable
  307. //=============================================================================
  308. function SocketsExSocketable() {
  309.         this._weaponTypes = [];
  310.         this._armorTypes = [];
  311.         this._skillTypes = [];
  312. }

  313. SocketsExSocketable.prototype.socketTypes = function(list) {
  314.         var res = [];
  315.         for (var i = 0; i < list.length; i++) {
  316.                 var obj = list[i];
  317.                 if (obj['eval'] === true) {
  318.                         res.push(eval(obj.ids));
  319.                 } else {
  320.                         for (n = 0; n < obj.ids.length; n++) {
  321.                                 res.push(obj.ids[n]);
  322.                         }
  323.                 }
  324.         }
  325.         return res;
  326. };

  327. SocketsExSocketable.prototype.skillTypes = function() {
  328.                 return this.socketTypes(this._skillTypes);
  329. };

  330. SocketsExSocketable.prototype.armorTypes = function() {
  331.                 return this.socketTypes(this._armorTypes);
  332. };

  333. SocketsExSocketable.prototype.weaponTypes = function() {
  334.                 return this.socketTypes(this._weaponTypes);
  335. };

  336. SocketsExSocketable.prototype.forSkill = function(id) {
  337.         return this.skillTypes().indexOf(id) !== -1 || this.skillTypes().indexOf(0) !== -1;
  338. };

  339. SocketsExSocketable.prototype.forArmor = function(id) {
  340.         return this.armorTypes().indexOf(id) !== -1 || this.armorTypes().indexOf(0) !== -1;
  341. };

  342. SocketsExSocketable.prototype.forWeapon = function(id) {
  343.         return this.weaponTypes().indexOf(id) !== -1  || this.weaponTypes().indexOf(0) !== -1;
  344. };

  345. SocketsExSocketable.prototype.addNode = function(socketType, socketNode) {
  346.         switch (socketType.toLowerCase()) {
  347.                 case "weapon":
  348.                         this._weaponTypes.push(socketNode);
  349.                 break;
  350.                
  351.                 case "armor":
  352.                         this._armorTypes.push(socketNode);
  353.                 break;
  354.                
  355.                 case "skill":
  356.                         this._skillTypes.push(socketNode);
  357.                 break;
  358.                
  359.                 case "all":
  360.                         this._weaponTypes.push(socketNode);
  361.                         this._armorTypes.push(socketNode);
  362.                         this._skillTypes.push(socketNode);
  363.                 break;
  364.         }
  365. };

  366. //=============================================================================
  367. // DataManager
  368. //=============================================================================
  369. Bobstah.SocketsEx.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  370. DataManager.isDatabaseLoaded = function() {
  371.     if (!Bobstah.SocketsEx.DataManager_isDatabaseLoaded.call(this)) return false;
  372.         DataManager.processBobstahSocketExSockets($dataWeapons);
  373.         DataManager.processBobstahSocketExSockets($dataArmors);
  374.        
  375.         DataManager.processBobstahSocketExSocketables($dataArmors);
  376.         return true;
  377. };

  378. DataManager.processBobstahSocketExSocketables = function(group) {
  379.         var socketregex = /<SocketEx\s*([A-z]*)\s*:?\s*(.*)\s*>/ig;
  380.         var commaregex = /(\d+)/ig;
  381.         var evalregex = /^\$\((.+)\)$/i;
  382.        
  383.         for (var n = 1; n < group.length; n++) {
  384.                 var obj = group[n];
  385.                
  386.                 if (obj.atypeId === 0) {
  387.                         var evl = false;
  388.                         obj.socketInfo = Bobstah.SocketsEx.createSocketInfoObject();
  389.                         while(info = socketregex.exec(obj.note)) {
  390.                                 var socketType = info[1] || 'all';
  391.                                
  392.                                 if (info[2].indexOf('$(') !== -1) {
  393.                                         info[2].match(evalregex);
  394.                                         var socketIds = RegExp.$1;
  395.                                         evl = true;
  396.                                 } else if (info[2].indexOf(',') !== -1) {
  397.                                         var socketIds = [];
  398.                                         while (id = commaregex.exec(info[2])) {
  399.                                                 socketIds.push(id[1]);
  400.                                         }
  401.                                 } else {
  402.                                         var socketIds = (info[2].length > 0 ? [Number(info[2])] : [0]);
  403.                                 }
  404.                                 var socketNode = Bobstah.SocketsEx.createSocketInfoNode(socketIds, evl);
  405.                                 obj.socketInfo.addNode(socketType, socketNode);
  406.                         }
  407.                 }
  408.         }
  409. };

  410. DataManager.processBobstahSocketExSockets = function(group) {
  411.         var socketregex = /<Sockets\s*:\s*(.+)>/i;
  412.         var evalregex = /^\$\((.+)\)$/i;
  413.        
  414.         for (var n = 1; n < group.length; n++) {
  415.                 var obj = group[n];

  416.                 obj.socketsEx = Bobstah.SocketsEx.createSocketsExObject();
  417.                 if (obj.atypeId === 0) { continue; }
  418.                 if (obj.note.match(socketregex)) {
  419.                         var sockets = RegExp.$1;
  420.                         if (sockets.indexOf('$()') !== -1) {
  421.                                 var evl = true;
  422.                         } else {
  423.                                 var evl = false;
  424.                         }
  425.                         obj.socketsEx.setupSockets(sockets, evl);
  426.                 }
  427.                
  428.         }
  429. };

  430. //=============================================================================
  431. // Window_Base
  432. //=============================================================================
  433. Window_Base.prototype.drawSockets = function(item, x, y, width, height) {
  434.         height = height || 36;
  435.         var numberWidth = (typeof(this.numberWidth) !== "undefined" ? this.numberWidth() : 0);
  436.         var sockets = Array.prototype.slice.call(item.socketsEx.sockets).reverse();
  437.         var ix = (x + width) - numberWidth - Window_Base._iconWidth;
  438.         var iy = y;
  439.         for (var i = 0; i < sockets.length; i++) {
  440.                 var socket = sockets[i];
  441.                 if (socket.isFull()) {
  442.                         var icon = socket.item.iconIndex;
  443.                 } else {
  444.                         var icon = Bobstah.Param.SocketsEx_EmptyIcon;
  445.                 }
  446.                 this.drawIcon(icon, ix, iy);
  447.                 ix -= Window_Base._iconWidth;
  448.         }
  449. };

  450. //=============================================================================
  451. // Window_MenuCommand
  452. //=============================================================================
  453. Bobstah.SocketsEx.WindowMenuCommand_addMainCommands = Window_MenuCommand.prototype.addMainCommands;
  454. Window_MenuCommand.prototype.addMainCommands = function() {
  455.         var enabled = this.areMainCommandsEnabled();
  456.         if (this.needsCommand('sockets')) {
  457.         this.addCommand('Sockets', 'SocketsEx', enabled);
  458.     }
  459.         return Bobstah.SocketsEx.WindowMenuCommand_addMainCommands.call(this);
  460. };

  461. Bobstah.SocketsEx.WindowMenuCommand_needsCommand = Window_MenuCommand.prototype.needsCommand;
  462. Window_MenuCommand.prototype.needsCommand = function(name) {
  463.         if (name === "sockets") {
  464.                 return true;
  465.         } else {
  466.                 return Bobstah.SocketsEx.WindowMenuCommand_needsCommand.call(this, name);
  467.         }
  468. };

  469. //=============================================================================
  470. // Window_ItemList
  471. //=============================================================================
  472. Bobstah.SocketsEx.WindowItemList_drawItem = Window_ItemList.prototype.drawItem;
  473. Window_ItemList.prototype.drawItem = function(index) {
  474.         item = this._data[index];
  475.         if (item && (DataManager.isWeapon(item) || DataManager.isArmor(item))) {
  476.                 if (item.socketsEx.hasSockets()) {
  477.                         var rect = this.itemRect(index);
  478.                         this.drawSockets(item, rect.x, rect.y, rect.width, rect.height);
  479.                 }
  480.         }
  481.         Bobstah.SocketsEx.WindowItemList_drawItem.call(this, index);
  482. };

  483. //=============================================================================
  484. // Window_EquipSlot
  485. //=============================================================================
  486. Bobstah.SocketsEx.WindowEquipSlot_drawItemName = Window_EquipSlot.prototype.drawItemName;
  487. Window_EquipSlot.prototype.drawItemName = function(item, x, y, w) {
  488.         if (item && (DataManager.isWeapon(item) || DataManager.isArmor(item))) {
  489.                 if (item.socketsEx.hasSockets()) {
  490.                         this.drawSockets(item, x, y, w);
  491.                 }
  492.         }
  493.         Bobstah.SocketsEx.WindowEquipSlot_drawItemName.call(this, item, x, y, w);
  494. };


  495. //=============================================================================
  496. // Scene_Menu
  497. //=============================================================================
  498. Bobstah.SocketsEx.SceneMenu_createCommandWindow = Scene_Menu.prototype.createCommandWindow;
  499. Scene_Menu.prototype.createCommandWindow = function() {
  500.         Bobstah.SocketsEx.SceneMenu_createCommandWindow.call(this);
  501.         this._commandWindow.setHandler('SocketsEx',   this.commandSocketsEx.bind(this));
  502. };

  503. Scene_Menu.prototype.commandSocketsEx = function() {
  504.     SceneManager.push(Scene_SocketEx);
  505. };

  506. //=============================================================================
  507. // Window_SocketExCategory
  508. //=============================================================================
  509. function Window_SocketExCategory() {
  510.     this.initialize.apply(this, arguments);
  511. }

  512. Window_SocketExCategory.prototype = Object.create(Window_ItemCategory.prototype);
  513. Window_SocketExCategory.prototype.constructor = Window_SocketExCategory;

  514. Window_SocketExCategory.prototype.makeCommandList = function() {
  515.         //this.addCommand('Skills',    'item');
  516.     this.addCommand(TextManager.weapon,  'weapon');
  517.     this.addCommand(TextManager.armor,   'armor');
  518. };

  519. Window_SocketExCategory.prototype.setGemWindow = function(gemWindow) {
  520.         if (gemWindow) { this._gemWindow = gemWindow; }
  521. };

  522. Window_SocketExCategory.prototype.select = function(index) {
  523.         Window_ItemCategory.prototype.select.call(this, index);
  524.         this.updateGemWindow();
  525. };

  526. Window_SocketExCategory.prototype.updateGemWindow = function() {
  527.         if (this._gemWindow) {
  528.                 this._gemWindow.setItemCategory(this.currentSymbol());
  529.         }
  530. };

  531. //=============================================================================
  532. // Window_SocketExList
  533. //=============================================================================
  534. function Window_SocketExList() {
  535.     this.initialize.apply(this, arguments);
  536. }

  537. Window_SocketExList.prototype = Object.create(Window_ItemList.prototype);
  538. Window_SocketExList.prototype.constructor = Window_SocketExList;

  539. Window_SocketExList.prototype.initialize = function(x, y, width, height) {
  540.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  541.     this._category = 'none';
  542.     this._data = [];
  543. };

  544. Window_SocketExList.prototype.makeItemList = function() {
  545.         Window_ItemList.prototype.makeItemList.call(this);
  546. };

  547. Window_SocketExList.prototype.maxCols = function() {
  548.     return 1;
  549. };

  550. Window_SocketExList.prototype.select = function(index) {
  551.     Window_Selectable.prototype.select.call(this, index);
  552.     this.callUpdateSocketList();
  553. };

  554. Window_SocketExList.prototype.includes = function(item) {
  555.     switch (this._category) {
  556.                 case 'weapon':
  557.                         if (DataManager.isWeapon(item)) {
  558.                                 if (item) {
  559.                                         return item.socketsEx.hasSockets();
  560.                                 }
  561.                                 return true;
  562.                         }
  563.                 break;
  564.                
  565.                 case 'armor':
  566.                         if (DataManager.isArmor(item)) {
  567.                                 if (item) {
  568.                                         return item.socketsEx.hasSockets();
  569.                                 }
  570.                                 return true;
  571.                         }
  572.                 break;
  573.                
  574.                 default:
  575.                         return false;
  576.                 break;
  577.     }
  578. };

  579. Window_SocketExList.prototype.isEnabled = function(item) {
  580.         return true;
  581. }

  582. Window_SocketExList.prototype.setSocketWindow = function(socketWindow) {
  583.         if (socketWindow) {
  584.                 this._socketWindow = socketWindow;
  585.         }
  586. };

  587. Window_SocketExList.prototype.setGemWindow = function(gemWindow) {
  588.         if (gemWindow) {
  589.                 this._gemWindow = gemWindow;
  590.         }
  591. };

  592. Window_SocketExList.prototype.callUpdateSocketList = function() {
  593.         if (this.active) {
  594.         if (this._socketWindow) { this.updateSocket(); }
  595.                 if (this._gemWindow) { this.updateGems(); }
  596.     }
  597. };

  598. Window_SocketExList.prototype.updateSocket = function() {
  599.          this.setSocketWindowItem(this.item());
  600. };

  601. Window_SocketExList.prototype.updateGems = function() {
  602.          this.setGemWindowItem(this.item());
  603. };

  604. Window_SocketExList.prototype.setSocketWindowItem = function(item) {
  605.         if (this._socketWindow) {
  606.         this._socketWindow.setItem(item);
  607.     }
  608. };

  609. Window_SocketExList.prototype.setGemWindowItem = function(item) {
  610.         if (this._gemWindow) {
  611.         this._gemWindow.setItem(item);
  612.     }
  613. };

  614. //=============================================================================
  615. // Window_SocketExSockets
  616. //=============================================================================
  617. function Window_SocketExSockets() {
  618.     this.initialize.apply(this, arguments);
  619. }

  620. Window_SocketExSockets.prototype = Object.create(Window_Selectable.prototype);
  621. Window_SocketExSockets.prototype.constructor = Window_SocketExSockets;

  622. Window_SocketExSockets.prototype.initialize = function(x, y, width, height) {
  623.         Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  624.         this._itemRef = null;
  625.     this._data = [];
  626. };

  627. Window_SocketExSockets.prototype.select = function(index) {
  628.     Window_Selectable.prototype.select.call(this, index);
  629.     this.callUpdateHelpWindow();
  630. };

  631. Window_SocketExSockets.prototype.item = function() {
  632.     var index = this.index();
  633.     return this._data && index >= 0 ? this._data[index] : null;
  634. };

  635. Window_SocketExSockets.prototype.maxCols = function() {
  636.     return 1;
  637. };

  638. Window_SocketExSockets.prototype.maxItems = function() {
  639.     return this._data ? this._data.length : 2;
  640. };

  641. Window_SocketExSockets.prototype.itemTextAlign = function() {
  642.         return 'left';
  643. };

  644. Window_SocketExSockets.prototype.itemNumberWidth = function() {
  645.         return this.textWidth('000');
  646. };

  647. Window_SocketExSockets.prototype.makeItemList = function() {
  648.         if (this._itemRef === null) { this._data = []; return; }
  649.         this._data = this._itemRef.socketsEx.sockets;
  650. };

  651. Window_SocketExSockets.prototype.setItem = function(item) {
  652.         if (item) {
  653.                 this._itemRef = item;
  654.                 this._index = 0;
  655.                 this.refresh();
  656.                 this.resetScroll();
  657.         }
  658. };

  659. Window_SocketExSockets.prototype.setGemWindow = function(gemWindow) {
  660.         if (gemWindow) {
  661.                 this._gemWindow = gemWindow;
  662.         }
  663. };

  664. Window_SocketExSockets.prototype.drawItem = function(index) {
  665.     var socket = this._data[index];
  666.         var numberWidth = 15;
  667.         var rect = this.itemRect(index);
  668.         rect.width -= this.textPadding();
  669.         var iw = this.itemNumberWidth();
  670.         var nx = rect.x + iw;
  671.         this.drawItemNumber(index, rect.x, rect.y, rect.width);
  672.         if (socket.isFull()) {
  673.                 srcItem = socket.item;
  674.                 this.drawItemName(srcItem, nx, rect.y, rect.width - numberWidth);
  675.         } else {
  676.                 this.drawEmptySocket(nx, rect.y, rect.width, rect.height);
  677.         }
  678.         this.changePaintOpacity(1);
  679. };

  680. Window_SocketExSockets.prototype.drawItemNumber = function(index, x, y, width) {
  681.         this.drawText((index+1)+'.', x, y, width - this.textWidth('00'), 'left');
  682. };

  683. Window_SocketExSockets.prototype.drawEmptySocket = function(x, y, width, height) {
  684.         var icon = Bobstah.Param.SocketsEx_EmptyIcon;
  685.         var name = Bobstah.Param.SocketsEx_EmptyName;
  686.         var nx = x + Window_Base._iconWidth
  687.         var nw = width - Window_Base._iconWidth;
  688.         var align =  this.itemTextAlign();
  689.         this.drawIcon(icon, x, y);
  690.         this.drawText(name, nx, y, nw, align);
  691. };

  692. Window_SocketExSockets.prototype.refresh = function() {
  693.     this.makeItemList();
  694.     this.createContents();
  695.     this.drawAllItems();
  696. };

  697. Window_SocketExSockets.prototype.callUpdateGemList = function() {
  698.         if (this.active) {
  699.                 if (this._gemWindow) { this.updateGems(); }
  700.     }
  701. };

  702. Window_SocketExSockets.prototype.updateGems = function() {
  703.          this.setGemWindowItem(this.item());
  704. };

  705. Window_SocketExSockets.prototype.setGemWindowItem = function(item) {
  706.         if (this._gemWindow) {
  707.         this._gemWindow.setItem(item);
  708.     }
  709. };

  710. Window_SocketExSockets.prototype.callUpdateHelpWindow = function() {
  711.         if (this.active) {
  712.                 if (this._helpWindow) { this.updateHelp(); }
  713.     }
  714. };

  715. Window_SocketExSockets.prototype.updateHelp = function() {
  716.         this._helpWindow.setItem(this.item().item);
  717. };

  718. Window_SocketExSockets.prototype.deselect = function() {
  719.         Window_Selectable.prototype.deselect.call(this);
  720.         this._data = [];
  721. }

  722. //=============================================================================
  723. // Window_SocketExGems
  724. //=============================================================================
  725. function Window_SocketExGems() {
  726.     this.initialize.apply(this, arguments);
  727. }

  728. Window_SocketExGems.prototype = Object.create(Window_SocketExList.prototype);
  729. Window_SocketExGems.prototype.constructor = Window_SocketExGems;

  730. Window_SocketExGems.prototype.initialize = function(x, y, width, height) {
  731.         Window_SocketExList.prototype.initialize.call(this, x, y, width, height);
  732. };

  733. Window_SocketExGems.prototype.includes = function(item) {
  734.         if (item === null) { return true; }
  735.         if (DataManager.isArmor(item)) {
  736.                 if (item.atypeId === 0) {
  737.                         switch (this._itemCategory) {
  738.                                 case "weapon":
  739.                                         return item.socketInfo.forWeapon(this._itemRef.wtypeId);
  740.                                 break;
  741.                                
  742.                                 case "armor":
  743.                                         return item.socketInfo.forArmor(this._itemRef.atypeId);
  744.                                 break;
  745.                                
  746.                                 default:
  747.                                         console.warn("Unknown category! "+this._itemCategory);
  748.                                         return true;
  749.                                 break;
  750.                         }
  751.                 }
  752.         }
  753.         return false;
  754. };

  755. Window_SocketExGems.prototype.makeItemList = function() {
  756.     if (this._itemRef === null) { return false; }
  757.         this._data = $gameParty.armors().filter(function(item) {
  758.         return this.includes(item);
  759.     }, this);
  760.     if (this.includes(null)) {
  761.         this._data.push(null);
  762.     }
  763. };

  764. Window_SocketExGems.prototype.setItem = function(item) {
  765.         if (item) {
  766.                 this._itemRef = item;
  767.                 this._index = 0;
  768.                 this.refresh();
  769.                 this.resetScroll();
  770.         }
  771. };

  772. Window_SocketExGems.prototype.setActor = function(actor) {
  773.         if (actor) {
  774.                 this._actor = actor;
  775.         }
  776. };

  777. Window_SocketExGems.prototype.select = function(index) {
  778.     this._index = index;
  779.     this._stayCount = 0;
  780.     this.ensureCursorVisible();
  781.     this.updateCursor();
  782.         this.callUpdateHelp();
  783. };

  784. Window_SocketExGems.prototype.setItemCategory = function(itemCategory) {
  785.         this._itemCategory = itemCategory;
  786. };

  787. //=============================================================================
  788. // Scene_SocketEx
  789. //=============================================================================
  790. function Scene_SocketEx() {
  791.     this.initialize.apply(this, arguments);
  792. }

  793. Scene_SocketEx.prototype = Object.create(Scene_ItemBase.prototype);
  794. Scene_SocketEx.prototype.constructor = Scene_SocketEx;

  795. Scene_SocketEx.prototype.initialize = function() {
  796.     Scene_ItemBase.prototype.initialize.call(this);
  797.         this._itemWidth = (Graphics.boxWidth * 0.7);
  798. };

  799. Scene_SocketEx.prototype.create = function() {
  800.     Scene_ItemBase.prototype.create.call(this);
  801.     this.createHelpWindow();
  802.     this.createCategoryWindow();
  803.     this.createItemWindow();
  804.         this.createSocketWindow();
  805.         this.createGemWindow();
  806. };

  807. Scene_SocketEx.prototype.createHelpWindow = function() {
  808.         Scene_ItemBase.prototype.createHelpWindow.call(this);
  809.         //this._helpWindow.width = this._itemWidth;
  810. };

  811. Scene_SocketEx.prototype.createCategoryWindow = function() {
  812.         this._categoryWindow = new Window_SocketExCategory();
  813.     this._categoryWindow.setHelpWindow(this._helpWindow);
  814.     this._categoryWindow.y = this._helpWindow.height;
  815.         this._categoryWindow.width = this._helpWindow.width;
  816.     this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
  817.     this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
  818.     this.addWindow(this._categoryWindow);
  819. };

  820. Scene_SocketEx.prototype.createItemWindow = function() {
  821.     var wy = this._categoryWindow.y + this._categoryWindow.height;
  822.     var wh = Graphics.boxHeight - wy;
  823.     this._itemWindow = new Window_SocketExList(0, wy, this._itemWidth, wh);
  824.     this._itemWindow.setHelpWindow(this._helpWindow);
  825.     this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
  826.     this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
  827.     this.addWindow(this._itemWindow);
  828.     this._categoryWindow.setItemWindow(this._itemWindow);
  829. };

  830. Scene_SocketEx.prototype.createSocketWindow = function() {
  831.     var wy = this._itemWindow.y;
  832.     var wh = this._itemWindow.height * 0.5;
  833.         var wx = this._itemWindow.x + this._itemWindow.width;
  834.         var ww = Graphics.boxWidth - wx;
  835.     this._socketWindow = new Window_SocketExSockets(wx, wy, ww, wh);
  836.     this._socketWindow.setHelpWindow(this._helpWindow);
  837.     this._socketWindow.setHandler('ok',     this.onSocketOk.bind(this));
  838.     this._socketWindow.setHandler('cancel', this.onSocketCancel.bind(this));
  839.     this.addWindow(this._socketWindow);
  840.     this._itemWindow.setSocketWindow(this._socketWindow);
  841. };

  842. Scene_SocketEx.prototype.createGemWindow = function() {
  843.     var wy = this._socketWindow.y + this._socketWindow.height;
  844.     var wh = this._socketWindow.height;
  845.         var wx = this._socketWindow.x;
  846.         var ww = this._socketWindow.width;
  847.     this._gemWindow = new Window_SocketExGems(wx, wy, ww, wh);
  848.     this._gemWindow.setHelpWindow(this._helpWindow);
  849.     this._gemWindow.setHandler('ok',     this.onGemOk.bind(this));
  850.     this._gemWindow.setHandler('cancel', this.onGemCancel.bind(this));
  851.     this.addWindow(this._gemWindow);
  852.     this._categoryWindow.setGemWindow(this._gemWindow);
  853.         this._itemWindow.setSocketWindow(this._socketWindow);
  854.         this._itemWindow.setGemWindow(this._gemWindow);
  855.         this._socketWindow.setGemWindow(this._gemWindow);
  856. };

  857. Scene_SocketEx.prototype.onCategoryOk = function() {
  858.         this._itemWindow.activate();
  859.     this._itemWindow.selectLast();
  860. };

  861. Scene_SocketEx.prototype.onItemOk = function() {
  862.         this._socketWindow.activate();
  863.         //this._socketWindow.selectLast();
  864. };

  865. Scene_SocketEx.prototype.onItemCancel = function() {
  866.     this._itemWindow.deselect();
  867.         this._socketWindow.setItem(null);
  868.         this._socketWindow.refresh();
  869.     this._categoryWindow.activate();
  870. };

  871. Scene_SocketEx.prototype.onSocketOk = function() {
  872.         this._gemWindow.activate();
  873.         //this._gemWindow.selectLast();
  874. };

  875. Scene_SocketEx.prototype.onSocketCancel = function() {
  876.     this._socketWindow.deselect();
  877.     this._itemWindow.activate();
  878. };

  879. Scene_SocketEx.prototype.onGemOk = function() {
  880.         var socket = this._socketWindow.item();
  881.         var item = this._socketWindow._itemRef;
  882.         var socketItem = this._gemWindow.item();
  883.         if (socketItem === null) {
  884.                 var oldItem = socket.removeItem();
  885.         } else {
  886.                 var oldItem = socket.insertItem(socketItem);
  887.                 $gameParty.loseItem(socketItem, 1, false);
  888.         }
  889.         if (oldItem) { $gameParty.gainItem(oldItem, 1); }
  890.         item.socketsEx.update(item);
  891.         SoundManager.playEquip();
  892.         this._itemWindow.refresh();
  893.         this._socketWindow.refresh();
  894.         this._gemWindow.refresh();
  895.         this._gemWindow.deselect();
  896.         this._socketWindow.activate();
  897. };

  898. Scene_SocketEx.prototype.onGemCancel = function() {
  899.     this._gemWindow.deselect();
  900.     this._socketWindow.activate();
  901. };
复制代码
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部