扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 59|回复: 0

[转载发布] 简单的物品掉落扩展插件

[复制链接]
累计送礼:
0 个
累计收礼:
0 个
  • TA的每日心情
    开心
    昨天 00:43
  • 签到天数: 144 天

    连续签到: 3 天

    [LV.7]常住居民III

    2397

    主题

    462

    回帖

    1万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    6
    卡币
    12392
    OK点
    16
    推广点
    0
    同能卷
    0
    积分
    15279

    灌水之王

    发表于 7 天前 | 显示全部楼层 |阅读模式
    偷懒做的简单插件。

    使用方法:
    按照以下格式添加到数据库 敌人 的备注栏

    每样物品以 物品类别-物品id:权重 格式添加,物品之间用逗号分隔
    例如:
    表示该敌人将会从id3的武器,id1的道具和id2的防具中选择两样掉落
    注: i=道具 w=武器 a=防具

    功能:
    1.根据权重判断掉落。权重数字越大掉落的概率越大。
    2.允许掉落任意数量的物品。在备注栏定义 掉落数 即可。

    JAVASCRIPT 代码
    1. //===========================================================
    2. //RPG Maker MV Improved Loot System
    3. //使用方法:
    4. //按照以下格式添加到数据库 敌人 的备注栏
    5. //
    6. //每样物品以 物品类别-物品id:权重 格式添加,物品之间用','分隔
    7. //例如:
    8. //i:道具 w:武器 a:防具
    9. //author:dukesward
    10. //version: 1.0
    11. //===========================================================
    12. //rpg_objects.js::4267
    13. var Game_Enemy_Alias = Game_Enemy_Alias || {},
    14.         ITEM_TYPE_MAPPING = {
    15.                 'i': 'Items',
    16.                 'w': 'Weapons',
    17.                 'a': 'Armors'
    18.         };
    19. Array.prototype.removeItem = function(item){
    20.         var temp = [];
    21.         for(var i inthis){
    22.                 if(this.hasOwnProperty(i) && this[i] !== item) temp.push(this[i]);
    23.         }
    24.         return temp;
    25. };
    26. Game_Enemy_Alias.setup = Game_Enemy.prototype.setup;
    27. Game_Enemy.prototype.setup = function(enemyId, x, y){
    28.         Game_Enemy_Alias.setup.call(this, enemyId, x, y);
    29.         //load loot data from enemy metadata
    30.         this.processLoot();
    31. }
    32. Game_Enemy.prototype.processLoot = function(){
    33.         var loot = this.enemy().meta.loot,
    34.               re = /([0-9])\[(.*)\]/,
    35.               match = loot ? loot.match(re) : null;
    36.         //set number of drop items and drop item list
    37.         if(match){
    38.                 this._lootNumber = parseInt(match[1]);
    39.                 this._lootList = match[2].split(',');
    40.         }
    41. }
    42. //rpg_objects::4327
    43. Game_Enemy.prototype.makeDropItems = function(){
    44.         var list = this._lootList,
    45.               dropped = [],
    46.               debug = 0;
    47.         while(dropped.length < this._lootNumber && list.length > 0){
    48.                 var prevRate = 0, temp = [], total = this.calculateTotalRate(list);
    49.                 var rand = Math.random();
    50.                 inner:
    51.                 for(var i in list){
    52.                         if(list.hasOwnProperty(i)){
    53.                                 var tokens = list[i].split(':');
    54.                                 prevRate = temp[1] || 0;
    55.                                 //caculate drop rate for each item in dropitem list
    56.                                 temp = this.calculateDropRate(tokens[1], total, prevRate);
    57.                                 if(this.isDropped(rand, temp)){
    58.                                         var info = tokens[0].split('-'),
    59.                                                 type = info[0] ? ITEM_TYPE_MAPPING[info[0]] : null,
    60.                                                 item = info[1] ? window['$data'+type][info[1]] : null;
    61.                                         //add dropped item into dropped, meanwhile remove from list
    62.                                         dropped.push(item);
    63.                                         list = list.removeItem(list[i]);
    64.                                         break inner;
    65.                                 }
    66.                         }
    67.                 }
    68.         }
    69.         return dropped;
    70. }
    71. Game_Enemy.prototype.calculateTotalRate = function(items){
    72.         var total = 0;
    73.         //loop through items and add all rates up
    74.         for(var i in items){
    75.                 if(items.hasOwnProperty(i)){
    76.                         var tokens = items[i].split(':'),
    77.                                 rate = parseInt(tokens[1]) || 0;
    78.                         total += rate;
    79.                 }
    80.         }
    81.         return total;
    82. }
    83. Game_Enemy.prototype.calculateDropRate = function(rate, total, prev){
    84.         var temp = prev,
    85.                 rate = parseInt(rate) || 0,
    86.                 rateToAdd = Math.round(rate/total*100)/100 + prev;
    87.         //the range of drop rate is determined by both current and prev items
    88.         return[temp, rateToAdd];
    89. };
    90. Game_Enemy.prototype.isDropped = function(rand, range){
    91.         return rand > range[0] && rand < range[1];
    92. }
    复制代码

                本帖来自P1论坛作者dukesward,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=388947  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2025-6-7 14:28 , Processed in 0.132754 second(s), 54 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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