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

Project1

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

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

[复制链接]

Lv4.逐梦者

梦石
0
星屑
5297
在线时间
1266 小时
注册时间
2018-1-16
帖子
366
跳转到指定楼层
1
发表于 2021-4-1 19:11:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
100星屑
本帖最后由 l734273398 于 2021-4-2 05:20 编辑

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


JAVASCRIPT 代码复制
  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. //========================================================================
  49. XdrsGiPluginCommand = Game_Interpreter.prototype.pluginCommand;
  50. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  51.     XdrsGiPluginCommand.call(this, command, args);
  52.     if (command === 'Prize_open') {SceneManager.push(Scene_Prize);}
  53. };
  54.  
  55. //=========================================================================
  56. // 奖品的储存。
  57. //=========================================================================
  58. var XdrsSysInitialize = Game_System.prototype.initialize;
  59. Game_System.prototype.initialize = function() {
  60.     XdrsSysInitialize.call(this);
  61.     this.clearPrizes();
  62. };
  63. Game_System.prototype.prizes = function() {
  64.     return this._prizeItems;
  65. };
  66. Game_System.prototype.clearPrizes = function() {
  67.     this._prizeItems = [];
  68. };
  69. Game_System.prototype.savePrizes = function(items) {
  70.     this._prizeItems = items.concat();
  71. };
  72.  
  73. //=========================================================================
  74.  
  75. function Xr_Window() {
  76.     this.initialize.apply(this, arguments);
  77. }
  78. Xr_Window.prototype = Object.create(Sprite.prototype);
  79. Xr_Window.prototype.constructor = Xr_Window;
  80. Xr_Window.prototype.initialize = function(x, y, windowName, rect) {
  81.     Sprite.prototype.initialize.call(this);
  82.     this.move(x, y);
  83.     this._windowName = windowName;
  84.     this.setBitmap();
  85.     this.setRect(rect);
  86.     this.createContents(rect);
  87.     this.iniData();
  88. };
  89. Xr_Window.prototype.createContents = function(rect) {
  90.     this.contents = new Sprite(new Bitmap(rect.width, rect.height));
  91.     this.addChild(this.contents);
  92. };
  93. Xr_Window.prototype.iniData = function() {
  94.     this.setTxtSize(28);
  95. };
  96. Xr_Window.prototype.update = function() {
  97.    Sprite.prototype.update.call(this);
  98. };
  99. Xr_Window.prototype.show = function() {
  100.     this.visible = this.contents.visible = true;
  101. };
  102. Xr_Window.prototype.hide = function() {
  103.     this.visible = this.contents.visible = false;
  104. };
  105. Xr_Window.prototype.setAnchor = function (ax, ay) {
  106.     this.anchor.x = this.contents.anchor = ax;
  107.     this.anchor.y = this.contents.anchor = ay;
  108. };
  109. Xr_Window.prototype.setBitmap = function () {
  110.     this.bitmap = ImageManager.loadPicture(this._windowName, 0);
  111. };
  112. Xr_Window.prototype.setRect = function(rect) {
  113.     this.setFrame(rect.x, rect.y, rect.width, rect.height);
  114. };
  115. Xr_Window.prototype.setTxtColor = function(n) {
  116.     var px = 96 + (n % 8) * 12 + 6;
  117.     var py = 144 + Math.floor(n / 8) * 12 + 6;
  118.     this._txtColor = this.bitmap.getPixel(px, py);
  119. };
  120. Xr_Window.prototype.setTxtSize = function(n) {
  121.     this.contents.bitmap.fontSize = n;
  122. };
  123. Xr_Window.prototype.setFontFace = function(name) {
  124.     this.contents.bitmap.fontFace = name;
  125. };
  126. Xr_Window.prototype.clear = function() {
  127.     this.contents.bitmap.clear();
  128. };
  129. Xr_Window.prototype.drawText = function(text, x, y, width, height, align) {
  130.     this.contents.bitmap.drawText(text, x, y, width, height, align);
  131. };
  132. Xr_Window.prototype.drawIcon = function(iconIndex, x, y) {
  133.     var bitmap = ImageManager.loadSystem('IconSet');
  134.     var sx = iconIndex % 16 * 32;
  135.     var sy = Math.floor(iconIndex / 16) * 32;
  136.     this.contents.bitmap.blt(bitmap, sx, sy, 32, 32, x, y);
  137. };
  138. Xr_Window.prototype.touchedInRect = function(rect) {
  139.     var x = rect.x + this.x;
  140.     var y = rect.y + this.y;
  141.     return TouchInput.x >= x && TouchInput.y >= y &&
  142.            TouchInput.x < (x + rect.width) && TouchInput.y < (y + rect.height);
  143. };
  144. Xr_Window.prototype.touchedInThis = function() {
  145.     var x = this.canvasToLocalX(TouchInput.x) + this.width * this.anchor.x;
  146.     var y = this.canvasToLocalY(TouchInput.y) + this.height * this.anchor.y;
  147.     return x >= 0 && y >= 0 && x < this.width && y < this.height;
  148. };
  149. Xr_Window.prototype.canvasToLocalX = function(x) {
  150.     var node = this;
  151.     while (node) {
  152.         x -= node.x;
  153.         node = node.parent;
  154.     }
  155.     return x;
  156. };
  157. Xr_Window.prototype.canvasToLocalY = function(y) {
  158.     var node = this;
  159.     while (node) {
  160.         y -= node.y;
  161.         node = node.parent;
  162.     }
  163.     return y;
  164. };
  165. //================================================================
  166. //  转盘抽奖。
  167. //================================================================
  168. function Scene_Prize() {
  169.     this.initialize.apply(this, arguments);
  170. }
  171.  
  172. Scene_Prize.prototype = Object.create(Scene_Base.prototype);
  173. Scene_Prize.prototype.constructor = Scene_Prize;
  174.  
  175. Scene_Prize.prototype.initialize = function() {
  176.     this._uiName = 'Ui_prize';
  177.     this.iniRect();
  178.     this.iniSpin();
  179.     Scene_Base.prototype.initialize.call(this);
  180. };
  181. Scene_Prize.prototype.iniRect = function() {
  182.     this._fortuneRect   = new Rectangle(0,0,474,473);
  183.     this._indicatorRect = new Rectangle(474,0,183,240);
  184.     this._startRect1    = new Rectangle(474,240,129,127);
  185.     this._startRect2    = new Rectangle(474,367,129,127);
  186.     this._prizeRect     = new Rectangle(0,493,460,203);
  187.     this._surRect       = new Rectangle(114,153,145,40);
  188. };
  189. Scene_Prize.prototype.iniSpin = function() {
  190.     this._rotation = 18;
  191.     this._speed = 9;
  192.     this._spinStart = false;
  193. };
  194. Scene_Prize.prototype.create = function() {
  195.     Scene_Base.prototype.create.call(this);
  196.     this.createBackground();
  197.     this.createWindows();
  198.     this.createItems();
  199. };
  200. Scene_Prize.prototype.createBackground = function() {
  201.     this._backgroundSprite = new Sprite();
  202.     this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
  203.     this.addChild(this._backgroundSprite);
  204. };
  205. Scene_Prize.prototype.createItems = function() {
  206.     this._prizes = [];
  207.     if ($gameSystem.prizes().length > 0) {
  208.         this._prizes = $gameSystem.prizes().concat();
  209.     }
  210.     else {
  211.         while (this._prizes.length < 10) {this.randPrize();}
  212.         $gameSystem.savePrizes(this._prizes);
  213.     }
  214.     this.drawItems();
  215. };
  216. Scene_Prize.prototype.randPrize = function() {
  217.     var data = [];
  218.     var num = this.randNum(0, 2);
  219.     switch (true) {
  220.     case num === 0 :
  221.         var itemName = this.randNum(0, 99) < XdrsPrizeDate.prRate ? 'p_item' : 'item' ;
  222.         data = XdrsPrizeItems[itemName].concat();
  223.         item = $dataItems[data[this.randNum(0, data.length-1)]];
  224.         this._prizes.push(item);
  225.         break;
  226.     case num === 1 :
  227.         var weaponName = this.randNum(0, 99) < XdrsPrizeDate.prRate ? 'p_weapon' : 'weapon' ;
  228.         data = XdrsPrizeItems[weaponName].concat();
  229.         weapon = $dataWeapons[data[this.randNum(0, data.length-1)]];
  230.         this._prizes.push(weapon);
  231.         break;
  232.     case num === 2 :
  233.         var armorName = this.randNum(0, 99) < XdrsPrizeDate.prRate ? 'p_armor' : 'armor' ;
  234.         data = XdrsPrizeItems[armorName].concat();
  235.         armor = $dataArmors[data[this.randNum(0, data.length-1)]];
  236.         this._prizes.push(armor);
  237.         break;
  238.     }
  239.  
  240. };
  241. Scene_Prize.prototype.createWindows = function() {
  242.     var x = Graphics.width / 2;
  243.     var y = Graphics.height / 2;
  244.     this._windowFortune = new Xr_Window(168, 74, this._uiName, this._fortuneRect);
  245.     this._windowIndicator = new Xr_Window(x, y, this._uiName, this._indicatorRect);
  246.     this._windowIndicator.setAnchor(0.5, 0.62);
  247.     this._windowIndicator.rotation = this._rotation * Math.PI / 180;
  248.     var rect = this.canStart() ? this._startRect1 : this._startRect2;
  249.     this._windowStart = new Xr_Window(x, y, this._uiName, rect);
  250.     this._windowStart.setAnchor(0.5, 0.5);
  251.     this._windowPrize = new Xr_Window(215, 200, this._uiName, this._prizeRect);
  252.     this._windowPrize.hide();
  253.     this.addChild(this._windowFortune);
  254.     this.addChild(this._windowIndicator);
  255.     this.addChild(this._windowStart);
  256.     this.addChild(this._windowPrize);
  257. };
  258. Scene_Prize.prototype.drawItems = function() {
  259.     this._windowFortune.clear();
  260.     for (var i=0; i < 10; i++) {
  261.         if (this._prizes[i] === undefined) {continue;}
  262.         this._windowFortune.drawIcon(this._prizes[i].iconIndex, XdrsPrizePlace[i][0], XdrsPrizePlace[i][1]);
  263.     }
  264. };
  265. Scene_Prize.prototype.start = function() {
  266.     Scene_Base.prototype.start.call(this);
  267.     SceneManager.clearStack();
  268. };
  269. Scene_Prize.prototype.randNum = function(min, max) {
  270.     var r1 = max - min;   
  271.     var r2 = Math.random();   
  272.     return (Math.round(r2 * r1) + min);   
  273. };
  274. Scene_Prize.prototype.setSpinCount = function(min, max) {
  275.     var r1 = max - min;   
  276.     var r2 = Math.random();   
  277.     this._spinCount = (Math.round(r2 * r1) + min);   
  278. };
  279. Scene_Prize.prototype.spinSpeed = function() {
  280.     switch (true) {
  281.     case this._spinCount > 450 : return 9;
  282.     case this._spinCount > 300 : return 6;
  283.     case this._spinCount > 200 : return 4;
  284.     case this._spinCount > 160 : return 3;
  285.     case this._spinCount > 120 : return 2;
  286.     }
  287.     return 1;
  288. };
  289. Scene_Prize.prototype.startSpinning = function() {
  290.     SoundManager.playOk();
  291.     $gameSystem.clearPrizes();
  292.     this.useItem();
  293.     this.setSpinCount(580, 660);
  294.     this._spinStart = true;
  295.     this._windowStart.setRect(this._startRect2);
  296. };
  297. Scene_Prize.prototype.update = function() {
  298.     if (this._windowPrize.visible) {
  299.         this.updateShow();
  300.         return;
  301.     }
  302.     if (this._spinStart) {this.updateSpinning();}
  303.     this.updateInput();
  304.     Scene_Base.prototype.update.call(this);
  305. };
  306. Scene_Prize.prototype.updateShow = function() {
  307.     if (this._windowPrize.touchedInRect(this._surRect) && TouchInput.isTriggered() || Input.isRepeated('ok')) {
  308.            SoundManager.playOk();
  309.            this.createItems();
  310.            this._windowPrize.hide();
  311.         }
  312. };
  313. Scene_Prize.prototype.updateSpinning = function() {
  314.     if ((this._rotation + 18) % 36 === 0) {
  315.         SoundManager.playCursor();
  316.         this._speed = this.spinSpeed();
  317.     }
  318.     this._rotation = (this._rotation + this._speed) % 360;
  319.     this._windowIndicator.rotation = this._rotation * Math.PI / 180;
  320.     if (this._spinCount > 0) {this._spinCount -= 1;}
  321.     else {if ((this._rotation + 18) % 36 === 0) {this._spinStart = false;
  322.     var rect = this.canStart() ? this._startRect1 : this._startRect2;
  323.     this._windowStart.setRect(rect);
  324.     this.showPrize();}}
  325. };
  326. Scene_Prize.prototype.showPrize = function() {
  327.     if (this.prize() === null) {return;}
  328.     this._windowPrize.drawIcon(this.prize().iconIndex, 172, 100);
  329.     this._windowPrize.show();
  330.     this.addPrize();
  331. };
  332. Scene_Prize.prototype.prize = function() {
  333.     if (this._prizes.length === 0) {return null;}
  334.     var index = (this._rotation - 18) % 360 / 36;
  335.     return this._prizes[index];
  336. };
  337. Scene_Prize.prototype.addPrize = function() {
  338.     SoundManager.playEquip();
  339.     $gameParty.gainItem(this.prize(), 1);
  340. };
  341. Scene_Prize.prototype.updateInput = function() {
  342.     if (!this._spinStart) {
  343.         if (this._windowStart.touchedInThis() && TouchInput.isTriggered() || Input.isRepeated('ok')) {
  344.             if (!this.canStart()) {SoundManager.playBuzzer(); return;}
  345.             this.startSpinning();
  346.         }
  347.         if (TouchInput.isCancelled() || Input.isRepeated('cancel')) {
  348.             SoundManager.playCancel();
  349.             SceneManager.goto(Scene_Map);
  350.         }
  351.     }
  352. };
  353. Scene_Prize.prototype.canStart = function() {
  354.     if (XdrsPrizeDate.useType === 'gold') {return $gameParty.gold() >= XdrsPrizeDate.useGold;}
  355.     else if (XdrsPrizeDate.useType === 'item') {return $gameParty.hasItem($dataItems[XdrsPrizeDate.useItem]);}
  356.     else {return false;}
  357. };
  358. Scene_Prize.prototype.useItem = function() {
  359.     if (XdrsPrizeDate.useType === 'gold') {$gameParty.loseGold(XdrsPrizeDate.useGold);}
  360.     else if (XdrsPrizeDate.useType === 'item') {$gameParty.loseItem($dataItems[XdrsPrizeDate.useItem], 1);}
  361. };
  362. //=================================================================================

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

本版积分规则

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

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

GMT+8, 2024-5-15 01:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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