/**
* Created by Administrator on 2016/9/10.
*/
//==========================================================================================================
// RandomWeapon.js
//==========================================================================================================
/*:
* @plugindesc 随机获取一把武器.
* @author DYART
*
* @param price
* @desc 每次购买所需要的钱.
* @default 1000
* @help This plugin does not provide plugin commands. 这个插件没有提供插件命令。
* 使用方法: 在事件指令里输入: RandomWeapon get
*/
//这东西是定义一个对象,然后把插件里面的东西都藏在这对象里面,防止和别人起名字冲突了.
var RandomWeapon = window.RandomWeapon || { };
//外面调用的话,都要用RandomWeapon.来调用
//读取参数的对象
RandomWeapon.parameters = PluginManager.parameters( 'RandomWeapon');
//这是我们允许随机获得武器的id,id是根据dataWeapons.js里面的id属性确定的.
RandomWeapon.weaponsList = [1,2,3,4];
//每次随机的价格.从参数里面获得
RandomWeapon.price = parseInt (RandomWeapon.parameters[ 'price' ] || '1000' ) ;
RandomWeapon._Game_Interpreter_pluginCommand =Game_Interpreter. prototype.pluginCommand;
Game_Interpreter . prototype. pluginCommand = function(command, args ) {
RandomWeapon._Game_Interpreter.pluginCommand.call ( this, command, args);
if (command === 'RandomWeapon') {
switch (args[0]) {
case ' get ': //命令 get
RandomWeapon.getWeapon( );
break;
}
}
};
//这是获得武器的函数,在面向对象里面,我们叫它"方法".
RandomWeapon.getWeapon = function () {
if ($gameParty.gold()<RandomWeapon.price)//判断钱够不够,不够直接跳出去
{
return ;
}else{//钱够的话,
//来个临时变量,先获得0¬1之间的随机数,然后乘以允许获得的武器数量,然后取整数部分,做为我们随机选定的武器ID
var id = Math.ceil (Math.random()*(RandomWeapon.weaponsList.length) );
//获得item,RPGMakerMV的核心函数,前一个参数是从json里面得到武器的对象,后一个参数是数量,我们只要一个.
$gameParty.gainItem($dataWeapons[RandomWeapon.weaponsList[id]],1);
//最后把钱扣掉
$gameParty.loseGold(RandomWeapon.price);
}
}