设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3097|回复: 7
打印 上一主题 下一主题

[有事请教] 自定义添加商品的代码是什么

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1428
在线时间
1705 小时
注册时间
2011-8-17
帖子
818
跳转到指定楼层
1
发表于 2019-6-26 11:45:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
就是按ID添加商品,ID可用变量变换,不知道有代码么
roguelike求生RPG研发中....

Lv4.逐梦者

梦石
0
星屑
15512
在线时间
3951 小时
注册时间
2015-9-14
帖子
1333

开拓者

2
发表于 2019-6-26 23:44:07 | 只看该作者
事件頁,商店販賣商品,直接用資料庫物品,武器,防具ID,
用變量轉換ID作何用途,限制販賣數量?特殊用途用插件.
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1428
在线时间
1705 小时
注册时间
2011-8-17
帖子
818
3
 楼主| 发表于 2019-6-27 12:00:33 | 只看该作者
wabcmcc 发表于 2019-6-26 23:44
事件頁,商店販賣商品,直接用資料庫物品,武器,防具ID,
用變量轉換ID作何用途,限制販賣數量?特殊用途用插件. ...

就是想要制作随机的商品而已
roguelike求生RPG研发中....
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
15512
在线时间
3951 小时
注册时间
2015-9-14
帖子
1333

开拓者

4
发表于 2019-6-27 12:21:53 | 只看该作者
就是想要制作随机的商品而已

變量ID=5個商店
(各商店設置販賣商品不同)
用分歧:
變量ID 1=1 商店
變量ID 2=2 商店
變量ID 3=3 商店
變量ID 4=4 商店
變量ID 5=5 商店

点评

这种商品多了,没啥意义,局限性太大,谢谢,我已经找到插件了  发表于 2019-7-1 15:12
这方法好,不考虑随机商品,而是考虑随机商店,棒!!  发表于 2019-6-27 22:41

评分

参与人数 1+1 收起 理由
白嫩白嫩的 + 1 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3453
在线时间
1159 小时
注册时间
2016-8-9
帖子
2390

开拓者

5
发表于 2019-7-2 00:47:37 | 只看该作者
黑舞嗜 发表于 2019-6-27 12:00
就是想要制作随机的商品而已

求楼主分享一下插件 谢谢
酸酸甜甜就④哇噢
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1428
在线时间
1705 小时
注册时间
2011-8-17
帖子
818
6
 楼主| 发表于 2019-7-2 09:40:49 | 只看该作者
白嫩白嫩的 发表于 2019-7-2 00:47
求楼主分享一下插件 谢谢
  1. //=============================================================================
  2. // SupponShopStock.js
  3. //=============================================================================

  4. /*:
  5. * @plugindesc 在庫システムを有するお店を設定します。version 1.03
  6. * @author Suppon
  7. *
  8. * @param Label of stock Number
  9. * @desc 在庫数の表記を設定します
  10. * @default 在庫数
  11. *
  12. * @param Label of sold out
  13. * @desc 売り切れの表記を設定します
  14. * @default 売り切れ
  15. *
  16. * @help
  17. * このプラグインを使用するときは以下のようにプラグインコマンドを入力してください。
  18. *
  19. * <ショップの作成例>
  20. * SupponSS makeShop 1 2
  21. * IDが1、ショップタイプが2のショップを作ります。IDにはabcのような文字も使えます。
  22. * ショップタイプ0は購買専門(売却不可)
  23. * ショップタイプ1は購買、売却可能
  24. * ショップタイプ2は購買、売却可能、全ての売却品がショップの商品に加わります。
  25. * ショップタイプを省略した場合は1になります。
  26. *
  27. * <アイテムの追加例>
  28. * SupponSS addItem 1 2 3 4
  29. * IDが1のショップにアイテムIDが2のアイテムを加えます。
  30. * 在庫数はID3の変数に割り当て、在庫を4個に設定します。
  31. * 3の部分を-1にすると変数は使わず、在庫は内部のデータで処理されます。
  32. * 最後の4の部分を省略すると現在の変数が適用されます。
  33. *
  34. * <武器の追加例>
  35. * SupponSS addWeapon 1 2 3 4
  36. *
  37. * <防具の追加例>
  38. * SupponSS addArmor 1 2 3 4
  39. *
  40. * <アイテムの削除例>
  41. * SupponSS removeItem 1 2
  42. * IDが1のショップのアイテムIDが2のアイテムを削除します。
  43. *
  44. * <武器の削除例>
  45. * SupponSS removeWeapon 1 2
  46. *
  47. * <防具の削除例>
  48. * SupponSS removeArmor 1 2
  49. *
  50. * <ショップの起動例>
  51. * SupponSS openShop 1
  52. * IDが1のショップを起動します。
  53. *
  54. * <ショップの削除例>
  55. * SupponSS deleteShop 1
  56. * IDが1のショップを削除します。
  57. *
  58. *
  59. */

  60. (function() {
  61.     var parameters = PluginManager.parameters('SupponShopStock');
  62.     var StockLabel = String(parameters['Label of stock Number']||'在庫数');
  63.     var SoldOutLabel = String(parameters['Label of sold out']||'売り切れ');
  64.    
  65.     var _Game_Interpreter_pluginCommand =Game_Interpreter.prototype.pluginCommand;
  66.     Game_Interpreter.prototype.pluginCommand = function(command1, args) {
  67.         _Game_Interpreter_pluginCommand.call(this, command1, args);
  68.         args = args.filter(function(n){
  69.             return n!=='';
  70.         });
  71.         if(!$gameSystem._supponSS){$gameSystem._supponSS=[]};
  72.         if (command1 === 'SupponSS') {
  73.             var command2 = args.shift();
  74.             switch (command2) {
  75.             case 'makeShop':
  76.                 $gameSystem.supponSSmakeShop(args);
  77.                 break;
  78.             case 'addItem':
  79.                 args.splice(1,0,0);
  80.                 $gameSystem.supponSSaddGoods(args);
  81.                 break;
  82.             case 'addWeapon':
  83.                 args.splice(1,0,1);
  84.                 $gameSystem.supponSSaddGoods(args);
  85.                 break;
  86.             case 'addArmor':
  87.                 args.splice(1,0,2);
  88.                 $gameSystem.supponSSaddGoods(args);
  89.                 break;
  90.             case 'removeItem':
  91.                 args.splice(1,0,0);
  92.                 $gameSystem.supponSSremoveGoods(args);
  93.                 break;
  94.             case 'removeWeapon':
  95.                 args.splice(1,0,1);
  96.                 $gameSystem.supponSSremoveGoods(args);
  97.                 break;
  98.             case 'removeArmor':
  99.                 args.splice(1,0,2);
  100.                 $gameSystem.supponSSremoveGoods(args);
  101.                 break;
  102.             case 'deleteShop':
  103.                 $gameSystem.supponSSdeleteShop(args);
  104.                 break;
  105.             case 'openShop':
  106.                 $gameSystem.supponSSopenShop(args);
  107.                 break;
  108.             }
  109.         }
  110.     };
  111.    
  112.    
  113.     Game_System.prototype.supponSScheckData = function(){
  114.         this._supponSS = this._supponSS || [];
  115.     }

  116.     Game_System.prototype.supponSSmakeShop = function(args){
  117.         this.supponSScheckData();
  118.         var redundancy = this._supponSS.some(function(element){
  119.             return element[0] === args[0];
  120.         })
  121.         if(redundancy){return};
  122.         if(!args[1]){args[1]=1};
  123.         this._supponSS.push([args[0],[],args[1]]);//[shopid, goods, shoptype]
  124.     }
  125.    
  126.     //args => [shopId, 種類, itemId, 変数id]
  127.     //shop => [id, goods, type]
  128.     //good => [種類, itemId, 価格指定, 価格, 変数id, 在庫数]
  129.     Game_System.prototype.supponSSaddGoods = function(args){
  130.         var shop = this.supponSSsearchShop(args);
  131.         args.shift();
  132.         args.splice(2,0,0,0);
  133.         if(shop){
  134.             var redundancy = false;
  135.             shop[1].forEach(function(element){
  136.                 if(element[0]==args[0] && element[1]==args[1]){
  137.                     element = args;
  138.                     redundancy = true;
  139.                 }
  140.             })
  141.             if(args[5]){
  142.                 args[4]>0 ? $gameVariables.setValue(Number(args[4]),Number(args[5])) :0;
  143.             } else {
  144.                 args[5] = 0;
  145.             }
  146.             if(!redundancy){shop[1].push(args)}
  147.         }
  148.     }
  149.    
  150.     Game_System.prototype.supponSSremoveGoods = function(args){
  151.         var shop = this.supponSSsearchShop(args);
  152.         if(!shop){return};
  153.         //shop[1] => goods
  154.         shop[1] = shop[1].filter(function(element){
  155.             return !(args[1]==element[0] && args[2]==element[1]);
  156.         })
  157.     }
  158.    
  159.     Game_System.prototype.supponSSsearchShop = function(args){
  160.         this.supponSScheckData();
  161.         var shop = null;
  162.         this._supponSS.forEach(function(element){
  163.             if(args[0]===element[0]){shop=element}
  164.         })
  165.         if(!shop){
  166.             console.log('Not exist shop of '+args[0]+' !!');
  167.         }
  168.         return shop;
  169.     }
  170.    
  171.     Game_System.prototype.supponSSdeleteShop = function(args){
  172.         this._supponSS = this._supponSS.filter(function(element){
  173.             return !(element[0]==args[0]);
  174.         })
  175.     }
  176.    
  177.     Game_System.prototype.supponSSopenShop = function(args){
  178.         var shop = this.supponSSsearchShop(args);
  179.         if(shop){
  180.             SceneManager.push(Scene_supponSSshop);
  181.             var purchaseOnly = shop[2]==0;
  182.             SceneManager.prepareNextScene(shop, purchaseOnly);   
  183.         }
  184.         
  185.     }
  186.    
  187.     function Scene_supponSSshop() {
  188.         this.initialize.apply(this, arguments);
  189.     };
  190.    
  191.     SceneManager.isSupponSS = function(){
  192.         return this._scene.constructor === Scene_supponSSshop;
  193.     }

  194.     Scene_supponSSshop.prototype = Object.create(Scene_Shop.prototype);
  195.     Scene_supponSSshop.prototype.constructor = Scene_supponSSshop;

  196.     Scene_supponSSshop.prototype.initialize = function() {
  197.         Scene_Shop.prototype.initialize.call(this);
  198.         this._trade = '';// 'buy' or 'sell';
  199.     };
  200.    
  201.     Scene_supponSSshop.prototype.prepare = function(shop, purchaseOnly) {
  202.         this._shop = shop;
  203.         this._goods = this._shop[1];
  204.         this._purchaseOnly = purchaseOnly;
  205.         this._item = null;
  206.     };
  207.    
  208.     Scene_supponSSshop.prototype.commandBuy = function() {
  209.         this._trade = 'buy';
  210.         Scene_Shop.prototype.commandBuy.call(this);
  211.     };
  212.    
  213.     Scene_supponSSshop.prototype.commandSell = function() {
  214.         this._trade = 'sell';
  215.         Scene_Shop.prototype.commandSell.call(this);
  216.     };
  217.    
  218.     Scene_supponSSshop.prototype.stockNumber = function(){
  219.         if (this._trade == 'buy'){
  220.             return this._buyWindow.stockNumber();
  221.         } else if (this._trade == 'sell'){
  222.             var goodsElement = this.goodsElement();
  223.             if(goodsElement){
  224.                 if(goodsElement[4] > 0){
  225.                     return $gameVariables.value(Number(goodsElement[4]));
  226.                 } else if (goodsElement[4] == -1) {
  227.                     return goodsElement[5];
  228.                 }
  229.             } else {
  230.                 return null;
  231.             }
  232.         }
  233.     }
  234.    
  235.     Scene_supponSSshop.prototype.stockId = function(){
  236.         if (this._trade == 'buy'){
  237.             return this._buyWindow.stockId();
  238.         } else if (this._trade == 'sell'){
  239.             var goodsElement = this.goodsElement()
  240.             if (goodsElement){
  241.                 if(goodsElement[4] > 0){
  242.                     return goodsElement[4];
  243.                 }
  244.             }
  245.         }
  246.     }
  247.    
  248.     Scene_supponSSshop.prototype.goodsElement = function(){
  249.         if (this._trade == 'buy'){
  250.             return this._goods[this._buyWindow.index()];
  251.         } else if (this._trade == 'sell'){
  252.             return this.searchGoodsElement();
  253.         }
  254.     }
  255.    
  256.     Scene_supponSSshop.prototype.searchGoodsElement = function(){
  257.         var type = this.itemTypeAndId()[0];
  258.         var id = this.itemTypeAndId()[1];
  259.         var goodsElement = null;
  260.         this._goods.forEach(function(element){
  261.             if(element[0]==type && element[1]==id){
  262.                 goodsElement = element;
  263.             }
  264.         })
  265.         return goodsElement;
  266.     }
  267.    
  268.     Scene_supponSSshop.prototype.itemTypeAndId = function(){
  269.         if(DataManager.isItem(this._item)){
  270.             var type = 0;
  271.         } else if (DataManager.isWeapon(this._item)){
  272.             var type = 1;
  273.         } else if (DataManager.isArmor(this._item)){
  274.             var type = 2;
  275.         } else {
  276.             var type = null;
  277.         }
  278.         return [type, (this._item ? this._item.id : null)];
  279.     }
  280.    
  281.     Scene_supponSSshop.prototype.makeGoodsElement = function(){
  282.         var type = this.itemTypeAndId()[0];
  283.         var id = this.itemTypeAndId()[1];
  284.         return [type, id, 0, 0, -1, 0];
  285.     }

  286.     Scene_supponSSshop.prototype.doBuy = function(number) {
  287.         Scene_Shop.prototype.doBuy.call(this, number);
  288.         this.processStockBuy(number);
  289.         //gameVariables.setValue(this._stockId, this.itemStock()-number);
  290.     };
  291.    
  292.     Scene_supponSSshop.prototype.processStockBuy = function(number){
  293.         var element = this.goodsElement();
  294.         if(this.stockId() > 0){
  295.             $gameVariables.setValue(this.stockId(), this.stockNumber()-number)
  296.         } else if (this.stockId() == -1){
  297.             var lastStock = element[5];
  298.             element[5] = lastStock-number;
  299.         }
  300.     }
  301.    
  302.     Scene_supponSSshop.prototype.maxBuy = function() {
  303.         var max = $gameParty.maxItems(this._item) - $gameParty.numItems(this._item);
  304.         max = Math.min(max, this.stockNumber());
  305.         var price = this.buyingPrice();
  306.         if (price > 0) {
  307.             return Math.min(max, Math.floor(this.money() / price));
  308.         } else {
  309.             return max;
  310.         }
  311.     };

  312.     Scene_supponSSshop.prototype.doSell = function(number) {
  313.         $gameParty.gainGold(number * this.sellingPrice());
  314.         $gameParty.loseItem(this._item, number);
  315.         this.processStockSell(number);
  316.     };
  317.    
  318.     Scene_supponSSshop.prototype.processStockSell = function(number){
  319.         var goodsElement = this.goodsElement();
  320.         if (goodsElement){
  321.             if(goodsElement[4]>0){
  322.                 var lastNumber = $gameVariables.value(goodsElement[4]);
  323.                 $gameVariables.setValue(goodsElement[4],lastNumber+number);
  324.             } else if (goodsElement[4] == -1){
  325.                 goodsElement[5] = Number(goodsElement[5])+number;
  326.             }
  327.         } else if (this._shop[2]==2){
  328.             goodsElement = this.makeGoodsElement();
  329.             goodsElement[5]=number;
  330.             this._goods.push(goodsElement);
  331.         }
  332.     }
  333.    
  334.     Window_ShopBuy.prototype.stockId = function() {
  335.         if (this._shopGoods.length>0){
  336.             return this._shopGoods[this._index][4];
  337.         } else {
  338.             return null
  339.         }
  340.     };
  341.    
  342.     Window_ShopBuy.prototype.stockNumber = function() {
  343.         if (this.stockId()>0){
  344.             return $gameVariables.value(this.stockId());
  345.         } else if (this.stockId() == -1){
  346.             return this._shopGoods[this._index][5];
  347.         }
  348.     };
  349.    
  350.     var _Window_ShopBuy_drawItem = Window_ShopBuy.prototype.drawItem;
  351.     Window_ShopBuy.prototype.drawItem = function(index) {
  352.         if(!SceneManager.isSupponSS()){
  353.             _Window_ShopBuy_drawItem.call(this, index);
  354.             return;
  355.         }
  356.         var item = this._data[index];
  357.         var rect = this.itemRect(index);
  358.         var priceWidth = 96;
  359.         rect.width -= this.textPadding();
  360.         if(this._shopGoods[index][4]>0){
  361.             var stockNumber = $gameVariables.value(this._shopGoods[index][4]);
  362.         } else if (this._shopGoods[index][4] == -1){
  363.             var stockNumber = this._shopGoods[index][5]
  364.         }        
  365.         this.changePaintOpacity(this.isEnabled(item) && stockNumber>0 );
  366.         this.drawItemName(item, rect.x, rect.y, rect.width - priceWidth);
  367.         var text = (stockNumber>0 ? this.price(item) : SoldOutLabel);
  368.         this.drawText(text, rect.x + rect.width - priceWidth,
  369.                       rect.y, priceWidth, 'right');
  370.         this.changePaintOpacity(true);
  371.     };
  372.    
  373.     var _Window_ShopBuy_isCurrentItemEnabled = Window_ShopBuy.prototype.isCurrentItemEnabled;
  374.     Window_ShopBuy.prototype.isCurrentItemEnabled = function() {
  375.         if(SceneManager.isSupponSS()){
  376.             return (_Window_ShopBuy_isCurrentItemEnabled.call(this) && this.stockNumber()>0)
  377.         } else {
  378.             return _Window_ShopBuy_isCurrentItemEnabled.call(this)
  379.         }
  380.     };
  381.    
  382.     var _Window_ShopBuy_updateHelp = Window_ShopBuy.prototype.updateHelp;
  383.     Window_ShopBuy.prototype.updateHelp = function() {
  384.         if (this._statusWindow && SceneManager.isSupponSS()) {
  385.             this._statusWindow.setStock(this.stockNumber());
  386.         }
  387.         _Window_ShopBuy_updateHelp.call(this);
  388.     };
  389.    
  390.     var _Window_ShopStatus_initialize = Window_ShopStatus.prototype.initialize;
  391.     Window_ShopStatus.prototype.initialize = function(x, y, width, height) {
  392.         this._stockNumber = null;
  393.         _Window_ShopStatus_initialize.call(this, x, y, width, height);
  394.     };
  395.    
  396.     Window_ShopStatus.prototype.setStock = function(number) {
  397.         this._stockNumber = number;
  398.     };
  399.    
  400.     Window_ShopStatus.prototype.stockNumber = function(){
  401.         return SceneManager._scene.stockNumber();
  402.     }
  403.    
  404.     var _Window_ShopStatus_drawPossession = Window_ShopStatus.prototype.drawPossession;
  405.     Window_ShopStatus.prototype.drawPossession = function(x, y) {
  406.         _Window_ShopStatus_drawPossession.call(this, x, y);
  407.         if(!SceneManager.isSupponSS() || !this._stockNumber){return}
  408.         var width = this.contents.width - this.textPadding() - x;
  409.         var possessionWidth = this.textWidth('0000');
  410.         this.changeTextColor(this.systemColor());
  411.         this.drawText(StockLabel, x, y+this.lineHeight(), width - possessionWidth);
  412.         this.resetTextColor();
  413.         this.drawText(this._stockNumber, x, y+this.lineHeight(), width, 'right');
  414.     };
  415.    
  416.     var _Scene_Shop_onSellOk = Scene_Shop.prototype.onSellOk;
  417.     Scene_Shop.prototype.onSellOk = function() {
  418.         _Scene_Shop_onSellOk.call(this);
  419.         if (this._statusWindow && SceneManager.isSupponSS()) {
  420.             this._statusWindow.setStock(this._statusWindow.stockNumber());
  421.             this._statusWindow.refresh();
  422.         }
  423.     };
  424.    
  425. })();
复制代码

评分

参与人数 1+1 收起 理由
白嫩白嫩的 + 1 楼主帅帅的!

查看全部评分

roguelike求生RPG研发中....
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-26 19:32

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表