| 赞 | 4 |
| VIP | |
| 好人卡 | |
| 积分 | 1 |
| 经验 | |
| 最后登录 | 2020-10-7 |
| 在线时间 | 1028 小时 |
巫女会长
- 梦石
- 0
- 星屑
- 60
- 在线时间
- 1028 小时
- 注册时间
- 2009-10-24
- 回帖
- 3425

|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 dukesward 于 2016-2-1 08:05 编辑
偷懒做的简单插件。
使用方法:
按照以下格式添加到数据库 敌人 的备注栏
<loot:掉落数[物品1:权重1,物品2:权重2,...]>
每样物品以 物品类别-物品id:权重 格式添加,物品之间用逗号分隔
例如:
<loot:2[w-1:3,i-1:2,a-2:5]>表示该敌人将会从id3的武器,id1的道具和id2的防具中选择两样掉落
注: i=道具 w=武器 a=防具
功能:
1.根据权重判断掉落。权重数字越大掉落的概率越大。
2.允许掉落任意数量的物品。在备注栏定义 掉落数 即可。
- //===========================================================
- //RPG Maker MV Improved Loot System
- //使用方法:
- //按照以下格式添加到数据库 敌人 的备注栏
- //<loot:掉落数[物品1:权重1,物品2:权重2,...]>
- //每样物品以 物品类别-物品id:权重 格式添加,物品之间用','分隔
- //例如:<loot:2[w-1:3,i-1:2,a-2:5]>
- //i:道具 w:武器 a:防具
- //author:dukesward
- //version: 1.0
- //===========================================================
- //rpg_objects.js::4267
- var Game_Enemy_Alias = Game_Enemy_Alias || {},
- ITEM_TYPE_MAPPING = {
- 'i': 'Items',
- 'w': 'Weapons',
- 'a': 'Armors'
- };
-
- Array.prototype.removeItem = function(item) {
- var temp = [];
- for(var i in this) {
- if(this.hasOwnProperty(i) && this[i] !== item) temp.push(this[i]);
- }
- return temp;
- };
- Game_Enemy_Alias.setup = Game_Enemy.prototype.setup;
- Game_Enemy.prototype.setup = function(enemyId, x, y) {
- Game_Enemy_Alias.setup.call(this, enemyId, x, y);
- //load loot data from enemy metadata
- this.processLoot();
- }
- Game_Enemy.prototype.processLoot = function() {
- var loot = this.enemy().meta.loot,
- re = /([0-9])\[(.*)\]/,
- match = loot ? loot.match(re) : null;
- //set number of drop items and drop item list
- if(match) {
- this._lootNumber = parseInt(match[1]);
- this._lootList = match[2].split(',');
- }
- }
- //rpg_objects::4327
- Game_Enemy.prototype.makeDropItems = function() {
- var list = this._lootList,
- dropped = [],
- debug = 0;
-
- while(dropped.length < this._lootNumber && list.length > 0) {
- var prevRate = 0, temp = [], total = this.calculateTotalRate(list);
- var rand = Math.random();
- inner:
- for(var i in list) {
- if(list.hasOwnProperty(i)) {
- var tokens = list[i].split(':');
- prevRate = temp[1] || 0;
- //caculate drop rate for each item in dropitem list
- temp = this.calculateDropRate(tokens[1], total, prevRate);
- if(this.isDropped(rand, temp)) {
- var info = tokens[0].split('-'),
- type = info[0] ? ITEM_TYPE_MAPPING[info[0]] : null,
- item = info[1] ? window['$data'+type][info[1]] : null;
- //add dropped item into dropped, meanwhile remove from list
- dropped.push(item);
- list = list.removeItem(list[i]);
- break inner;
- }
- }
- }
- }
- return dropped;
- }
- Game_Enemy.prototype.calculateTotalRate = function(items) {
- var total = 0;
- //loop through items and add all rates up
- for(var i in items) {
- if(items.hasOwnProperty(i)) {
- var tokens = items[i].split(':'),
- rate = parseInt(tokens[1]) || 0;
- total += rate;
- }
- }
- return total;
- }
- Game_Enemy.prototype.calculateDropRate = function(rate, total, prev) {
- var temp = prev,
- rate = parseInt(rate) || 0,
- rateToAdd = Math.round(rate/total*100)/100 + prev;
- //the range of drop rate is determined by both current and prev items
- return [temp, rateToAdd];
- };
- Game_Enemy.prototype.isDropped = function(rand, range) {
- return rand > range[0] && rand < range[1];
- }
复制代码 |
评分
-
查看全部评分
|