查看: 6217|回复: 0

[有事请教] 存档后,抽奖无法获取物品

[复制链接]
梦石
0
星屑
6447
在线时间
1702 小时
注册时间
2018-1-16
回帖
364
发表于 2021-4-1 19:11:31 | 显示全部楼层 |阅读模式
悬赏100星屑未解决
本帖最后由 l734273398 于 2021-4-2 05:20 编辑

如题,存档之后,再抽奖就无法再获取物品,游戏中不小心打开了抽奖界面,存档后,抽奖无效,然后就这个存档就废了?咳咳咳


  1. /*:
  2. * @plugindesc 转盘式抽奖。 进入转盘抽奖场景:插件命令  Prize_open  。
  3. *
  4. * @author 芯☆淡茹水
  5. *
  6. * @help 进入转盘抽奖场景:插件命令  Prize_open  。
  7. *---------------------------------------------------------------
  8. * @param 抽奖消耗类型
  9. * @desc 转盘的消耗类型。 消耗金钱写 gold ; 消耗道具写 item  。
  10. * @default gold
  11. *---------------------------------------------------------------
  12. * @param 消耗的金钱
  13. * @desc 消耗类型是 消耗金钱 时,抽一次奖所消耗的金钱。
  14. * @default 1000
  15. *
  16. * @param 消耗的道具ID
  17. * @desc 消耗类型是 消耗道具 时,抽奖所消耗的道具ID,每次消耗的道具数量为 1。
  18. * @default 1
  19. *
  20. *
  21. * @param 珍贵物品出现几率
  22. * @desc 转盘中出现珍贵物品的几率,默认为 10 。
  23. * @default 10
  24. */
  25. //========================================================================
  26. // ☆ 可用于抽奖的物品设置。☆
  27. // item 一般道具; p_item 珍贵道具; weapon 一般武器; p_weapon 珍贵武器; armor 一般防具; p_armor 珍贵防具。
  28. var XdrsPrizeItems = { 'item'    : [1,2,3],
  29.                        'p_item'  : [4],
  30.                        'weapon'  : [1,2,3],
  31.                        'p_weapon': [4],
  32.                        'armor'   : [1,2,3],
  33.                        'p_armor' : [4]
  34.    
  35. };
  36. //========================================================================
  37. // 物品图标显示的位置。
  38. var XdrsPrizePlace = [[270,66],[354,120],[386,218],[355,320],[268,370],
  39.                       [170,370],[90,315],[55,218],[90,125],[170,66]];
  40. //========================================================================
  41. var XdrsPrizeDate = XdrsPrizeDate || {};
  42. var xrpepr = PluginManager.parameters('Rotary_draw');
  43. XdrsPrizeDate.useType = String(xrpepr['抽奖消耗类型']) || 'gold';
  44. XdrsPrizeDate.useGold = parseInt(xrpepr['消耗的金钱']) || 1000;
  45. XdrsPrizeDate.useItem = parseInt(xrpepr['消耗的道具ID']) || 1;
  46. XdrsPrizeDate.prRate = parseInt(xrpepr['珍贵物品出现几率']) || 10;

  47. //========================================================================
  48. XdrsGiPluginCommand = Game_Interpreter.prototype.pluginCommand;
  49. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  50.     XdrsGiPluginCommand.call(this, command, args);
  51.     if (command === 'Prize_open') {SceneManager.push(Scene_Prize);}
  52. };

  53. //=========================================================================
  54. // 奖品的储存。
  55. //=========================================================================
  56. var XdrsSysInitialize = Game_System.prototype.initialize;
  57. Game_System.prototype.initialize = function() {
  58.     XdrsSysInitialize.call(this);
  59.     this.clearPrizes();
  60. };
  61. Game_System.prototype.prizes = function() {
  62.     return this._prizeItems;
  63. };
  64. Game_System.prototype.clearPrizes = function() {
  65.     this._prizeItems = [];
  66. };
  67. Game_System.prototype.savePrizes = function(items) {
  68.     this._prizeItems = items.concat();
  69. };

  70. //=========================================================================

  71. function Xr_Window() {
  72.     this.initialize.apply(this, arguments);
  73. }
  74. Xr_Window.prototype = Object.create(Sprite.prototype);
  75. Xr_Window.prototype.constructor = Xr_Window;
  76. Xr_Window.prototype.initialize = function(x, y, windowName, rect) {
  77.     Sprite.prototype.initialize.call(this);
  78.     this.move(x, y);
  79.     this._windowName = windowName;
  80.     this.setBitmap();
  81.     this.setRect(rect);
  82.     this.createContents(rect);
  83.     this.iniData();
  84. };
  85. Xr_Window.prototype.createContents = function(rect) {
  86.     this.contents = new Sprite(new Bitmap(rect.width, rect.height));
  87.     this.addChild(this.contents);
  88. };
  89. Xr_Window.prototype.iniData = function() {
  90.     this.setTxtSize(28);
  91. };
  92. Xr_Window.prototype.update = function() {
  93.    Sprite.prototype.update.call(this);
  94. };
  95. Xr_Window.prototype.show = function() {
  96.     this.visible = this.contents.visible = true;
  97. };
  98. Xr_Window.prototype.hide = function() {
  99.     this.visible = this.contents.visible = false;
  100. };
  101. Xr_Window.prototype.setAnchor = function (ax, ay) {
  102.     this.anchor.x = this.contents.anchor = ax;
  103.     this.anchor.y = this.contents.anchor = ay;
  104. };
  105. Xr_Window.prototype.setBitmap = function () {
  106.     this.bitmap = ImageManager.loadPicture(this._windowName, 0);
  107. };
  108. Xr_Window.prototype.setRect = function(rect) {
  109.     this.setFrame(rect.x, rect.y, rect.width, rect.height);
  110. };
  111. Xr_Window.prototype.setTxtColor = function(n) {
  112.     var px = 96 + (n % 8) * 12 + 6;
  113.     var py = 144 + Math.floor(n / 8) * 12 + 6;
  114.     this._txtColor = this.bitmap.getPixel(px, py);
  115. };
  116. Xr_Window.prototype.setTxtSize = function(n) {
  117.     this.contents.bitmap.fontSize = n;
  118. };
  119. Xr_Window.prototype.setFontFace = function(name) {
  120.     this.contents.bitmap.fontFace = name;
  121. };
  122. Xr_Window.prototype.clear = function() {
  123.     this.contents.bitmap.clear();
  124. };
  125. Xr_Window.prototype.drawText = function(text, x, y, width, height, align) {
  126.     this.contents.bitmap.drawText(text, x, y, width, height, align);
  127. };
  128. Xr_Window.prototype.drawIcon = function(iconIndex, x, y) {
  129.     var bitmap = ImageManager.loadSystem('IconSet');
  130.     var sx = iconIndex % 16 * 32;
  131.     var sy = Math.floor(iconIndex / 16) * 32;
  132.     this.contents.bitmap.blt(bitmap, sx, sy, 32, 32, x, y);
  133. };
  134. Xr_Window.prototype.touchedInRect = function(rect) {
  135.     var x = rect.x + this.x;
  136.     var y = rect.y + this.y;
  137.     return TouchInput.x >= x && TouchInput.y >= y &&
  138.            TouchInput.x < (x + rect.width) && TouchInput.y < (y + rect.height);
  139. };
  140. Xr_Window.prototype.touchedInThis = function() {
  141.     var x = this.canvasToLocalX(TouchInput.x) + this.width * this.anchor.x;
  142.     var y = this.canvasToLocalY(TouchInput.y) + this.height * this.anchor.y;
  143.     return x >= 0 && y >= 0 && x < this.width && y < this.height;
  144. };
  145. Xr_Window.prototype.canvasToLocalX = function(x) {
  146.     var node = this;
  147.     while (node) {
  148.         x -= node.x;
  149.         node = node.parent;
  150.     }
  151.     return x;
  152. };
  153. Xr_Window.prototype.canvasToLocalY = function(y) {
  154.     var node = this;
  155.     while (node) {
  156.         y -= node.y;
  157.         node = node.parent;
  158.     }
  159.     return y;
  160. };
  161. //================================================================
  162. //  转盘抽奖。
  163. //================================================================
  164. function Scene_Prize() {
  165.     this.initialize.apply(this, arguments);
  166. }

  167. Scene_Prize.prototype = Object.create(Scene_Base.prototype);
  168. Scene_Prize.prototype.constructor = Scene_Prize;

  169. Scene_Prize.prototype.initialize = function() {
  170.     this._uiName = 'Ui_prize';
  171.     this.iniRect();
  172.     this.iniSpin();
  173.     Scene_Base.prototype.initialize.call(this);
  174. };
  175. Scene_Prize.prototype.iniRect = function() {
  176.     this._fortuneRect   = new Rectangle(0,0,474,473);
  177.     this._indicatorRect = new Rectangle(474,0,183,240);
  178.     this._startRect1    = new Rectangle(474,240,129,127);
  179.     this._startRect2    = new Rectangle(474,367,129,127);
  180.     this._prizeRect     = new Rectangle(0,493,460,203);
  181.     this._surRect       = new Rectangle(114,153,145,40);
  182. };
  183. Scene_Prize.prototype.iniSpin = function() {
  184.     this._rotation = 18;
  185.     this._speed = 9;
  186.     this._spinStart = false;
  187. };
  188. Scene_Prize.prototype.create = function() {
  189.     Scene_Base.prototype.create.call(this);
  190.     this.createBackground();
  191.     this.createWindows();
  192.     this.createItems();
  193. };
  194. Scene_Prize.prototype.createBackground = function() {
  195.     this._backgroundSprite = new Sprite();
  196.     this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
  197.     this.addChild(this._backgroundSprite);
  198. };
  199. Scene_Prize.prototype.createItems = function() {
  200.     this._prizes = [];
  201.     if ($gameSystem.prizes().length > 0) {
  202.         this._prizes = $gameSystem.prizes().concat();
  203.     }
  204.     else {
  205.         while (this._prizes.length < 10) {this.randPrize();}
  206.         $gameSystem.savePrizes(this._prizes);
  207.     }
  208.     this.drawItems();
  209. };
  210. Scene_Prize.prototype.randPrize = function() {
  211.     var data = [];
  212.     var num = this.randNum(0, 2);
  213.     switch (true) {
  214.     case num === 0 :
  215.         var itemName = this.randNum(0, 99) < XdrsPrizeDate.prRate ? 'p_item' : 'item' ;
  216.         data = XdrsPrizeItems[itemName].concat();
  217.         item = $dataItems[data[this.randNum(0, data.length-1)]];
  218.         this._prizes.push(item);
  219.         break;
  220.     case num === 1 :
  221.         var weaponName = this.randNum(0, 99) < XdrsPrizeDate.prRate ? 'p_weapon' : 'weapon' ;
  222.         data = XdrsPrizeItems[weaponName].concat();
  223.         weapon = $dataWeapons[data[this.randNum(0, data.length-1)]];
  224.         this._prizes.push(weapon);
  225.         break;
  226.     case num === 2 :
  227.         var armorName = this.randNum(0, 99) < XdrsPrizeDate.prRate ? 'p_armor' : 'armor' ;
  228.         data = XdrsPrizeItems[armorName].concat();
  229.         armor = $dataArmors[data[this.randNum(0, data.length-1)]];
  230.         this._prizes.push(armor);
  231.         break;
  232.     }
  233.    
  234. };
  235. Scene_Prize.prototype.createWindows = function() {
  236.     var x = Graphics.width / 2;
  237.     var y = Graphics.height / 2;
  238.     this._windowFortune = new Xr_Window(168, 74, this._uiName, this._fortuneRect);
  239.     this._windowIndicator = new Xr_Window(x, y, this._uiName, this._indicatorRect);
  240.     this._windowIndicator.setAnchor(0.5, 0.62);
  241.     this._windowIndicator.rotation = this._rotation * Math.PI / 180;
  242.     var rect = this.canStart() ? this._startRect1 : this._startRect2;
  243.     this._windowStart = new Xr_Window(x, y, this._uiName, rect);
  244.     this._windowStart.setAnchor(0.5, 0.5);
  245.     this._windowPrize = new Xr_Window(215, 200, this._uiName, this._prizeRect);
  246.     this._windowPrize.hide();
  247.     this.addChild(this._windowFortune);
  248.     this.addChild(this._windowIndicator);
  249.     this.addChild(this._windowStart);
  250.     this.addChild(this._windowPrize);
  251. };
  252. Scene_Prize.prototype.drawItems = function() {
  253.     this._windowFortune.clear();
  254.     for (var i=0; i < 10; i++) {
  255.         if (this._prizes[i] === undefined) {continue;}
  256.         this._windowFortune.drawIcon(this._prizes[i].iconIndex, XdrsPrizePlace[i][0], XdrsPrizePlace[i][1]);
  257.     }
  258. };
  259. Scene_Prize.prototype.start = function() {
  260.     Scene_Base.prototype.start.call(this);
  261.     SceneManager.clearStack();
  262. };
  263. Scene_Prize.prototype.randNum = function(min, max) {
  264.     var r1 = max - min;   
  265.     var r2 = Math.random();   
  266.     return (Math.round(r2 * r1) + min);   
  267. };
  268. Scene_Prize.prototype.setSpinCount = function(min, max) {
  269.     var r1 = max - min;   
  270.     var r2 = Math.random();   
  271.     this._spinCount = (Math.round(r2 * r1) + min);   
  272. };
  273. Scene_Prize.prototype.spinSpeed = function() {
  274.     switch (true) {
  275.     case this._spinCount > 450 : return 9;
  276.     case this._spinCount > 300 : return 6;
  277.     case this._spinCount > 200 : return 4;
  278.     case this._spinCount > 160 : return 3;
  279.     case this._spinCount > 120 : return 2;
  280.     }
  281.     return 1;
  282. };
  283. Scene_Prize.prototype.startSpinning = function() {
  284.     SoundManager.playOk();
  285.     $gameSystem.clearPrizes();
  286.     this.useItem();
  287.     this.setSpinCount(580, 660);
  288.     this._spinStart = true;
  289.     this._windowStart.setRect(this._startRect2);
  290. };
  291. Scene_Prize.prototype.update = function() {
  292.     if (this._windowPrize.visible) {
  293.         this.updateShow();
  294.         return;
  295.     }
  296.     if (this._spinStart) {this.updateSpinning();}
  297.     this.updateInput();
  298.     Scene_Base.prototype.update.call(this);
  299. };
  300. Scene_Prize.prototype.updateShow = function() {
  301.     if (this._windowPrize.touchedInRect(this._surRect) && TouchInput.isTriggered() || Input.isRepeated('ok')) {
  302.            SoundManager.playOk();
  303.            this.createItems();
  304.            this._windowPrize.hide();
  305.         }
  306. };
  307. Scene_Prize.prototype.updateSpinning = function() {
  308.     if ((this._rotation + 18) % 36 === 0) {
  309.         SoundManager.playCursor();
  310.         this._speed = this.spinSpeed();
  311.     }
  312.     this._rotation = (this._rotation + this._speed) % 360;
  313.     this._windowIndicator.rotation = this._rotation * Math.PI / 180;
  314.     if (this._spinCount > 0) {this._spinCount -= 1;}
  315.     else {if ((this._rotation + 18) % 36 === 0) {this._spinStart = false;
  316.     var rect = this.canStart() ? this._startRect1 : this._startRect2;
  317.     this._windowStart.setRect(rect);
  318.     this.showPrize();}}
  319. };
  320. Scene_Prize.prototype.showPrize = function() {
  321.     if (this.prize() === null) {return;}
  322.     this._windowPrize.drawIcon(this.prize().iconIndex, 172, 100);
  323.     this._windowPrize.show();
  324.     this.addPrize();
  325. };
  326. Scene_Prize.prototype.prize = function() {
  327.     if (this._prizes.length === 0) {return null;}
  328.     var index = (this._rotation - 18) % 360 / 36;
  329.     return this._prizes[index];
  330. };
  331. Scene_Prize.prototype.addPrize = function() {
  332.     SoundManager.playEquip();
  333.     $gameParty.gainItem(this.prize(), 1);
  334. };
  335. Scene_Prize.prototype.updateInput = function() {
  336.     if (!this._spinStart) {
  337.         if (this._windowStart.touchedInThis() && TouchInput.isTriggered() || Input.isRepeated('ok')) {
  338.             if (!this.canStart()) {SoundManager.playBuzzer(); return;}
  339.             this.startSpinning();
  340.         }
  341.         if (TouchInput.isCancelled() || Input.isRepeated('cancel')) {
  342.             SoundManager.playCancel();
  343.             SceneManager.goto(Scene_Map);
  344.         }
  345.     }
  346. };
  347. Scene_Prize.prototype.canStart = function() {
  348.     if (XdrsPrizeDate.useType === 'gold') {return $gameParty.gold() >= XdrsPrizeDate.useGold;}
  349.     else if (XdrsPrizeDate.useType === 'item') {return $gameParty.hasItem($dataItems[XdrsPrizeDate.useItem]);}
  350.     else {return false;}
  351. };
  352. Scene_Prize.prototype.useItem = function() {
  353.     if (XdrsPrizeDate.useType === 'gold') {$gameParty.loseGold(XdrsPrizeDate.useGold);}
  354.     else if (XdrsPrizeDate.useType === 'item') {$gameParty.loseItem($dataItems[XdrsPrizeDate.useItem], 1);}
  355. };
  356. //=================================================================================
复制代码

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

本版积分规则

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

在本版发帖返回顶部