Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Turntable Lottery 分享给新手们的RMMV抽奖插件

psb

Please rename the picture after downloading. 请把图片下载以后重新改名,Ui_prize.png

以下是插件
JavaScript:
//==================================================================================================================

/*:

 * @plugindesc 转盘抽奖(新) 。

 * 

 * @author 中国腾讯QQ 2144972924

 * 

 * @help

 * 〓 物品的备注 〓

 * 1,在 道具/武器/防具 备注栏备注:<不出现在转盘抽奖>

 *    表示该物品不会出现在转盘抽奖中。

 *

 * 2,设置的变量值限制物品出现。

 *     一般物品备注:<一般的抽奖物品:n>

 *     珍贵物品备注:<珍贵的抽奖物品:n>

 *     n 表示限制的值,当设置的游戏变量值达到这个 n 时,这个物品才有几率出现在抽奖中。

 *     例:备注一个普通物品变量值大于等于 3 时才出现:<一般的抽奖物品:3>

 *         备注一个珍贵物品变量值大于等于 0 时才出现:<珍贵的抽奖物品:0>

 *-------------------------------------------------------------------------------

 * @param varId

 * @desc 控制转盘物品的变量ID。

 * @default 10

 *-------------------------------------------------------------------------------

 * @param vabRate

 * @desc 珍贵物品出现在转盘上的几率。

 * @default 30

 *-------------------------------------------------------------------------------

 * @param type

 * @desc 抽奖消耗的类型(金钱写:GOLD; 物品写:ITEM)。

 * @default GOLD

 *-------------------------------------------------------------------------------

 * @param data

 * @desc 抽奖消耗类型所对应的值(金钱写:需要的金钱数; 物品写:消耗的物品ID)。

 * @default 1000

 *-------------------------------------------------------------------------------

 * @param seName

 * @desc 转针转动时播放的SE。

 * @default Cursor2

*/

//==================================================================================================================

;var XdRsData = XdRsData || {};

XdRsData.ttl = XdRsData.ttl || {};

//==================================================================================================================

XdRsData.ttl.pepr    =    PluginManager.parameters('XdRs_Turntable_Lottery');

XdRsData.ttl.varId   =   +XdRsData.ttl.pepr['varId']   || 10;

XdRsData.ttl.vabRate =   +XdRsData.ttl.pepr['vabRate'] || 30;

XdRsData.ttl.data    =   +XdRsData.ttl.pepr['data']    || 10;

XdRsData.ttl.type    = ''+XdRsData.ttl.pepr['type']    || 'GOLD';

XdRsData.ttl.seName  = ''+XdRsData.ttl.pepr['seName']  || '';

//==================================================================================================================

XdRsData.ttl.place = [[270,66],[354,120],[386,218],[355,320],[268,370],

                      [170,370],[90,315],[55,218],[90,125],[170,66]];

XdRsData.ttl.canDiscern = function(item) {

    return DataManager.isItem(item) || DataManager.isWeapon(item) || DataManager.isArmor(item);

};

XdRsData.ttl.itemDiscern = function(item) {

    if (!this.canDiscern(item)) return 0;

    if (!!item.note.match(<span style="color: #0066FF;">/<不出现在转盘抽奖>/)) return 0;

    if (!item.note.match(<span style="color: #0066FF;">/<一般的抽奖物品:(\d+)>/)) {return 1;}

    else{return $gameVariables.value(this.varId) >= (+RegExp.$1) ? 1 : 0;}

    if (!!item.note.match(<span style="color: #0066FF;">/<珍贵的抽奖物品:(\d+)>/)){

        return $gameVariables.value(this.varId) >= (+RegExp.$1) ? 2 : 0;

    }

    return 1;

};

XdRsData.ttl.allItems = function() {

    return $dataItems.concat($dataWeapons,$dataArmors);

};

XdRsData.ttl.prizesKind = function(kind) {

    return this.allItems().filter(function(item){return XdRsData.ttl.itemDiscern(item) === kind;});

};

XdRsData.ttl.prizes = function() {

    var prizes = [],objPrizes,item;

    var vab = this.prizesKind(2),cml = this.prizesKind(1);

    if ((vab.length + cml.length) <= 10) {prizes.concat(cml,vab);}

    else{

        while (prizes.length < 10){

            if (!!vab.length && Math.randomInt(100) < XdRsData.ttl.vabRate) {objPrizes = vab;}

            else{objPrizes = cml;}

            item = objPrizes[Math.randomInt(objPrizes.length)];   

            if (!prizes.contains(item)) prizes.push(item);

        }

    }

    return prizes.map(function(item){return XdRsData.ttl.setData(item);});

};

XdRsData.ttl.setData = function(obj) {

    if (!obj) return null;

    var data = {}; data['id'] = obj.id;

    switch (true){

        case DataManager.isItem(obj)  :data['type'] = 1;break;

        case DataManager.isWeapon(obj):data['type'] = 2;break;

        case DataManager.isArmor(obj) :data['type'] = 3;break;

    }

    return data;

};

XdRsData.ttl.prizeObj = function(data) {

    if (!data) return null;

    switch (data.type){

        case 1:return $dataItems[data.id];

        case 2:return $dataWeapons[data.id];

        case 3:return $dataArmors[data.id];

    }

};

XdRsData.ttl.playType = function() {

    return this.type === 'GOLD' ? 0 : 1;

};

XdRsData.ttl.canStart = function() {

    if (!this.playType()) return $gameParty.gold() >= this.data;

    return $gameParty.hasItem($dataItems[this.data]);

};

XdRsData.ttl.expend = function() {

    if (!this.playType()) {$gameParty.loseGold(this.data);}

    else{$gameParty.loseItem($dataItems[this.data],1);}

};

//==================================================================================================================

Game_System.prototype.savePrizes = function(items) {

    if (!!this._prizeItems) this._prizeItems.length = 0;

    this._prizeItems = items.slice(0);

};

Game_System.prototype.clearPrizes = function() {

    if (!this._prizeItems || !this._prizeItems.length) return;

    this._prizeItems.length = 0;

};

Game_System.prototype.prizes = function() {

    return this._prizeItems || [];

};

//==================================================================================================================

XdRsData.ttl.GiPluginCommand = Game_Interpreter.prototype.pluginCommand;

Game_Interpreter.prototype.pluginCommand = function(command, args) {

    XdRsData.ttl.GiPluginCommand.call(this, command, args);

    if (command === 'Prize_open') {SceneManager.push(Scene_Prize);}

};

//==================================================================================================================

function Xr_Window() {

    this.initialize.apply(this, arguments);

}

Xr_Window.prototype = Object.create(Sprite.prototype);

Xr_Window.prototype.constructor = Xr_Window;

Xr_Window.prototype.initialize = function(x, y, windowName, rect) {

    Sprite.prototype.initialize.call(this);

    this.move(x, y);

    this._windowName = windowName;

    this.setBitmap();

    this.setRect(rect);

    this.createContents(rect);

};

Xr_Window.prototype.createContents = function(rect) {

    this.con = new Sprite(new Bitmap(rect.width, rect.height));

    this.addChild(this.con);

};

Xr_Window.prototype.update = function() {

   Sprite.prototype.update.call(this);

};

Xr_Window.prototype.show = function() {

    this.visible = this.con.visible = true;

};

Xr_Window.prototype.hide = function() {

    this.visible = this.con.visible = false;

};

Xr_Window.prototype.setAnchor = function (ax, ay) {

    this.anchor.x = ax; this.anchor.y = ay;

};

Xr_Window.prototype.setBitmap = function () {

    this.bitmap = ImageManager.loadPicture(this._windowName, 0);

};

Xr_Window.prototype.setRect = function(rect) {

    this.setFrame(rect.x, rect.y, rect.width, rect.height);

};

Xr_Window.prototype.setTxtColor = function(color) {

    this.con.bitmap.textColor = color || 'rgb(255,255,255)';

};

Xr_Window.prototype.setTxtSize = function(n) {

    this.con.bitmap.fontSize = n;

};

Xr_Window.prototype.clear = function() {

    this.con.bitmap.clear();

};

Xr_Window.prototype.drawText = function(text, x, y, width, height, align) {

    this.con.bitmap.drawText(text, x, y, width, height, align);

};

Xr_Window.prototype.drawIcon = function(iconIndex, x, y) {

    var bitmap = ImageManager.loadSystem('IconSet');

    var sx = iconIndex % 16 * 32;

    var sy = Math.floor(iconIndex / 16) * 32;

    this.con.bitmap.blt(bitmap, sx, sy, 32, 32, x, y);

};

Xr_Window.prototype.touchedInRect = function(rect) {

    var x = rect.x + this.x;

    var y = rect.y + this.y;

    return TouchInput.x >= x && TouchInput.y >= y &&

           TouchInput.x < (x + rect.width) && TouchInput.y < (y + rect.height);

};

Xr_Window.prototype.touchedInThis = function() {

    var x = this.canvasToLocalX(TouchInput.x) + this.width * this.anchor.x;

    var y = this.canvasToLocalY(TouchInput.y) + this.height * this.anchor.y;

    return x >= 0 && y >= 0 && x < this.width && y < this.height;

};

Xr_Window.prototype.canvasToLocalX = function(x) {

    var node = this;

    while (node) {

        x -= node.x;

        node = node.parent;

    }

    return x;

};

Xr_Window.prototype.canvasToLocalY = function(y) {

    var node = this;

    while (node) {

        y -= node.y;

        node = node.parent;

    }

    return y;

};

//==========================================================================================================

function Scene_Prize() {

    this.initialize.apply(this, arguments);

}

Scene_Prize.prototype = Object.create(Scene_Base.prototype);

Scene_Prize.prototype.constructor = Scene_Prize;

Scene_Prize.prototype.initialize = function() {

    Scene_Base.prototype.initialize.call(this);

    this._uiName = 'Ui_prize';

    this.iniRect();this.iniSpin();

};

Scene_Prize.prototype.iniRect = function() {

    this._fortuneRect   = new Rectangle(0,0,474,473);

    this._indicatorRect = new Rectangle(474,0,183,240);

    this._startRect1    = new Rectangle(474,240,129,127);

    this._startRect2    = new Rectangle(474,367,129,127);

    this._prizeRect     = new Rectangle(0,493,460,203);

    this._surRect       = new Rectangle(114,153,145,40);

};

Scene_Prize.prototype.iniSpin = function() {

    this.randRotation();

    this._speed = 9;

    this._spinStart = false;

};

Scene_Prize.prototype.randRotation = function() {

    var num = Math.randomInt(10);

    this._rotation = num * 36 + 18;

};

Scene_Prize.prototype.create = function() {

    Scene_Base.prototype.create.call(this);

    this.createBackground();

    this.createWindows();

    this.createItems();

};

Scene_Prize.prototype.createBackground = function() {

    this._backgroundSprite = new Sprite();

    this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();

    this.addChild(this._backgroundSprite);

};

Scene_Prize.prototype.createItems = function() {

    this._prizes = [];

    if (!!$gameSystem.prizes().length) {this._prizes = $gameSystem.prizes().slice(0);}

    else {this._prizes = XdRsData.ttl.prizes();

        $gameSystem.savePrizes(this._prizes);

    }

    this.drawItems();

};

Scene_Prize.prototype.createWindows = function() {

    var x = Graphics.width <span style="color: #0066FF;">/ 2,y = Graphics.height / 2;

    var fx = x - this._fortuneRect.width <span style="color: #0066FF;">/ 2, fy = y - this._fortuneRect.height / 2;

    this._windowFortune = new Xr_Window(fx, fy, this._uiName, this._fortuneRect);

    this._windowIndicator = new Xr_Window(x, y, this._uiName, this._indicatorRect);

    this._windowIndicator.setAnchor(0.5, 0.62);

    this._windowIndicator.rotation = this._rotation * Math.PI / 180;

    var rect = XdRsData.ttl.canStart() ? this._startRect1 : this._startRect2;

    this._windowStart = new Xr_Window(x, y, this._uiName, rect);

    this._windowStart.setAnchor(0.5,0.5);

    this._windowPrize = new Xr_Window(215, 200, this._uiName, this._prizeRect);

    this._windowPrize.hide();

    this.addChild(this._windowFortune);

    this.addChild(this._windowIndicator);

    this.addChild(this._windowStart);

    this.addChild(this._windowPrize);

};

Scene_Prize.prototype.drawItems = function() {

    this._windowFortune.clear();

    for (var i=0; i < 10; i++) {

        if (!this._prizes[i]) continue;

        var item = XdRsData.ttl.prizeObj(this._prizes[i]);

        this._windowFortune.drawIcon(item.iconIndex, XdRsData.ttl.place[i][0], XdRsData.ttl.place[i][1]);

    }

};

Scene_Prize.prototype.start = function() {

    Scene_Base.prototype.start.call(this);

    SceneManager.clearStack();

    this.drawItems();

};

Scene_Prize.prototype.spinSpeed = function() {

    switch (true) {

    case this._spinCount > 450 : return 9;

    case this._spinCount > 300 : return 6;

    case this._spinCount > 200 : return 4;

    case this._spinCount > 160 : return 3;

    case this._spinCount > 120 : return 2;

    }

    return 1;

};

Scene_Prize.prototype.startSpinning = function() {

    SoundManager.playOk();

    $gameSystem.clearPrizes();

    XdRsData.ttl.expend();

    this._spinCount = Math.randomInt(80) + 580;

    this._spinStart = true;

    this._windowStart.setRect(this._startRect2);

};

Scene_Prize.prototype.update = function() {

    Scene_Base.prototype.update.call(this);

    if (this._windowPrize.visible) {this.updateShow();return;}

    if (this._spinStart) {this.updateSpinning();}

    this.updateInput();

};

Scene_Prize.prototype.updateShow = function() {

    if (this._windowPrize.touchedInRect(this._surRect) && TouchInput.isTriggered() || Input.isRepeated('ok')) {

           SoundManager.playOk();

           this.createItems();

           this._windowPrize.hide();

        }

};

Scene_Prize.prototype.updateSpinning = function() {

    if ((this._rotation + 18) % 36 === 0) {

        if (!!XdRsData.ttl.seName) {

            var name = XdRsData.ttl.seName;

            AudioManager.playSe({"name":name,"volume":100,"pitch":100,"pan":0});

        }

        this._speed = this.spinSpeed();

    }

    this._rotation = (this._rotation + this._speed) % 360;

    this._windowIndicator.rotation = this._rotation * Math.PI / 180;

    if (this._spinCount > 0) {this._spinCount -= 1;}

    else {if ((this._rotation + 18) % 36 === 0) {this._spinStart = false;

    var rect = XdRsData.ttl.canStart() ? this._startRect1 : this._startRect2;

    this._windowStart.setRect(rect);

    this.showPrize();}}

};

Scene_Prize.prototype.showPrize = function() {

    if (this.prize() === null) {return;}

    this._windowPrize.drawIcon(this.prize().iconIndex, 172, 100);

    this._windowPrize.show();

    this.addPrize();

};

Scene_Prize.prototype.prize = function() {

    if (this._prizes.length === 0) return null;

    var index = (this._rotation - 18) % 360 / 36;

    if (!this._prizes[index]) return null;

    return XdRsData.ttl.prizeObj(this._prizes[index]);

};

Scene_Prize.prototype.addPrize = function() {

    SoundManager.playEquip();

    $gameParty.gainItem(this.prize(), 1);

};

Scene_Prize.prototype.updateInput = function() {

    if (!this._spinStart) {

        if (this._windowStart.touchedInThis() && TouchInput.isTriggered() || Input.isRepeated('ok')) {

            if (!XdRsData.ttl.canStart()){SoundManager.playBuzzer(); return;}

            this.startSpinning();

        }

        if (TouchInput.isCancelled() || Input.isRepeated('cancel')) {

            SoundManager.playCancel();

            SceneManager.goto(Scene_Map);

        }

    }

};

//=============================================================================================================================
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top