查看: 3466|回复: 10

[有事请教] rpgmakermz如何新增载具车辆类,就像船一样的那种类型?

[复制链接]
梦石
0
星屑
74
在线时间
56 小时
注册时间
2022-1-26
回帖
13
发表于 2022-3-8 22:12:04 | 显示全部楼层 |阅读模式
悬赏20星屑未解决

梦石
0
星屑
7898
在线时间
1533 小时
注册时间
2013-12-3
回帖
306
发表于 2022-3-9 01:47:47 | 显示全部楼层
换个思路 做个载具外观的角色加入队伍带队
回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2022-3-9 14:21:48 | 显示全部楼层
本帖最后由 tseyik 于 2022-3-9 14:24 编辑

image_20160716_122618.jpeg
NpcFollower.js
  1. //=============================================================================
  2. // NpcFollower.js
  3. // ----------------------------------------------------------------------------
  4. // (C)2016 Triacontane
  5. // This software is released under the MIT License.
  6. // [url]http://opensource.org/licenses/mit-license.php[/url]
  7. // ----------------------------------------------------------------------------
  8. // Version
  9. // 1.2.0 2021/11/27 MZで動作するよう修正
  10. // 1.1.1 2019/11/02 1.1.0の修正でメンバーの入れ替えを実施すると表示が不正になる場合がある問題を修正
  11. // 1.1.0 2019/01/27 通常のフォロワーを表示せず、NPCフォロワーのみを表示できる機能を追加
  12. // 1.0.3 2018/08/06 コアスクリプトが1.6.0より古い場合にエラーになる記述を修正
  13. // 1.0.2 2017/01/17 プラグインコマンドが小文字でも動作するよう修正(byこまちゃん先輩)
  14. // 1.0.1 2016/07/17 セーブデータをロードした際のエラーになる現象の修正
  15. // 1.0.0 2016/07/14 初版
  16. // ----------------------------------------------------------------------------
  17. // [Blog]   : [url]https://triacontane.blogspot.jp/[/url]
  18. // [Twitter]: [url]https://twitter.com/triacontane/[/url]
  19. // [GitHub] : [url]https://github.com/triacontane/[/url]
  20. //=============================================================================

  21. /*:
  22. * @plugindesc NPCフォロワープラグイン
  23. * @target MZ
  24. * @url [url]https://github.com/triacontane/RPGMakerMV/tree/mz_master/NpcFollower.js[/url]
  25. * @base PluginCommonBase
  26. * @orderAfter PluginCommonBase
  27. * @author トリアコンタン
  28. *
  29. * @param MaxNpcNumber
  30. * @text 最大同時NPC数
  31. * @desc 同時に隊列に存在できるNPCの最大数です。
  32. * @default 1
  33. * @type number
  34. * @min 1
  35. *
  36. * @param HideNormalFollower
  37. * @text 通常フォロワーを表示しない
  38. * @desc 隊列歩行の設定にかかわらず通常のフォロワーを一切表示せず、NPCフォロワーのみを表示します。
  39. * @default false
  40. * @type boolean
  41. *
  42. * @command ADD_NPC
  43. * @text NPC追加
  44. * @desc 指定したアクターをNPCとして隊列に追加します。
  45. *
  46. * @arg actorId
  47. * @text アクターID
  48. * @desc 追加するアクターID
  49. * @default 1
  50. * @type actor
  51. *
  52. * @arg index
  53. * @text 隊列位置
  54. * @desc 追加する隊列位置(パーティの並び順)です。指定した位置の後ろに追加されます。
  55. * @default 0
  56. * @type number
  57. *
  58. * @command REMOVE_NPC
  59. * @text NPC削除
  60. * @desc 追加位置を指定してNPCを隊列から除去します。
  61. *
  62. * @arg index
  63. * @text 隊列位置
  64. * @desc 削除する隊列位置(パーティの並び順)です。
  65. * @default 0
  66. * @type number
  67. *
  68. * @help NpcFollower.js
  69. *
  70. * マップ上の隊列の好きな位置にパーティメンバー以外のNPCを追加します。
  71. * NPCはデータベース上はアクターで定義してプラグインコマンドから追加、削除します。
  72. * バトルメンバーではないので、メニュー画面や戦闘画面には影響を与えません。
  73. * また、隊列表示していない場合は何も表示されません。
  74. * 同一IDのアクターを複数追加することもできます。
  75. *
  76. * このプラグインの利用にはベースプラグイン『PluginCommonBase.js』が必要です。
  77. * 『PluginCommonBase.js』は、RPGツクールMZのインストールフォルダ配下の
  78. * 以下のフォルダに格納されています。
  79. * dlc/BasicResources/plugins/official
  80. *
  81. * 利用規約:
  82. *  作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
  83. *  についても制限はありません。
  84. *  このプラグインはもうあなたのものです。
  85. */

  86. (()=> {
  87.     'use strict';
  88.     const script = document.currentScript;
  89.     const param = PluginManagerEx.createParameter(script);

  90.     PluginManagerEx.registerCommand(script, 'ADD_NPC', args => {
  91.         $gameParty.addNpc(args.actorId, args.index);
  92.     });

  93.     PluginManagerEx.registerCommand(script, 'REMOVE_NPC', args => {
  94.         $gameParty.removeNpc(args.index);
  95.     });

  96.     //=============================================================================
  97.     // Game_Party
  98.     //  NPCの追加と削除を追加定義します。
  99.     //=============================================================================
  100.     const _Game_Party_initialize      = Game_Party.prototype.initialize;
  101.     Game_Party.prototype.initialize = function() {
  102.         _Game_Party_initialize.apply(this, arguments);
  103.         this.initNpc();
  104.     };

  105.     Game_Party.prototype.initNpc = function() {
  106.         this._npcs       = [];
  107.         this._npcIndexes = [];
  108.     };

  109.     Game_Party.prototype.isNpcInvalid = function() {
  110.         return !this._npcs;
  111.     };

  112.     Game_Party.prototype.initNpcIfNeed = function() {
  113.         if (this.isNpcInvalid()) {
  114.             this.initNpc();
  115.             $gamePlayer.followers().initNpc();
  116.         }
  117.     };

  118.     Game_Party.prototype.addNpc = function(actorId, index) {
  119.         if (this._npcs.length < param.MaxNpcNumber) {
  120.             this._npcs.push(actorId);
  121.             this._npcIndexes.push(index);
  122.             $gamePlayer.refresh();
  123.             $gameMap.requestRefresh();
  124.         } else {
  125.             throw new Error('登録可能な最大数を超えています。');
  126.         }
  127.     };

  128.     Game_Party.prototype.removeNpc = function(index) {
  129.         for (let i = 0, n = this._npcs.length; i < n; i++) {
  130.             if (this._npcIndexes[i] === index) {
  131.                 this._npcs.splice(i, 1);
  132.                 this._npcIndexes.splice(i, 1);
  133.                 i--;
  134.             }
  135.         }
  136.         $gamePlayer.refresh();
  137.         $gameMap.requestRefresh();
  138.     };

  139.     Game_Party.prototype.npcMembers = function() {
  140.         return this._npcs.map(function(id) {
  141.             return $gameActors.actor(id);
  142.         });
  143.     };

  144.     Game_Party.prototype.visibleMembers = function() {
  145.         return this._visibleMembers;
  146.     };

  147.     Game_Party.prototype.makeVisibleMembers = function() {
  148.         const battleMembers  = this.battleMembers();
  149.         const npcMembers     = this.npcMembers();
  150.         const visibleMembers = [];
  151.         for (let i = 0, n = this.maxBattleMembers() + 1; i < n; i++) {
  152.             for (let j = 0, m = npcMembers.length; j < m; j++) {
  153.                 if (this._npcIndexes[j] === i) {
  154.                     visibleMembers.push(npcMembers[j]);
  155.                 }
  156.             }
  157.             if (battleMembers.length > i && !param.HideNormalFollower) {
  158.                 visibleMembers.push(battleMembers[i]);
  159.             }
  160.         }
  161.         this._visibleMembers = visibleMembers;
  162.     };

  163.     //=============================================================================
  164.     // Game_Followers
  165.     //  NPCの最大数ぶんだけ余分にGame_Followerを作成します。
  166.     //=============================================================================
  167.     const _Game_Followers_initialize      = Game_Followers.prototype.initialize;
  168.     Game_Followers.prototype.initialize = function() {
  169.         _Game_Followers_initialize.apply(this, arguments);
  170.         if (param.HideNormalFollower) {
  171.             this._data = [];
  172.         }
  173.         this.initNpc();
  174.     };

  175.     Game_Followers.prototype.initNpc = function() {
  176.         const memberLength = this._data.length > 0 ? this._data.length + 1 : 0;
  177.         for (let i = 0; i < param.MaxNpcNumber; i++) {
  178.             this._data.push(new Game_Follower(memberLength + i));
  179.         }
  180.     };

  181.     //=============================================================================
  182.     // Game_Follower
  183.     //  NPC判定を追加定義します。
  184.     //=============================================================================
  185.     const _Game_Follower_actor      = Game_Follower.prototype.actor;
  186.     Game_Follower.prototype.actor = function() {
  187.         _Game_Follower_actor.apply(this, arguments);
  188.         return $gameParty.visibleMembers()[this._memberIndex];
  189.     };

  190.     //=============================================================================
  191.     // Game_Player
  192.     //  リフレッシュまえに表示メンバーを更新します。
  193.     //=============================================================================
  194.     const _Game_Player_refresh      = Game_Player.prototype.refresh;
  195.     Game_Player.prototype.refresh = function() {
  196.         $gameParty.makeVisibleMembers();
  197.         _Game_Player_refresh.apply(this, arguments);
  198.     };

  199.     //=============================================================================
  200.     // DataManager
  201.     //  プラグイン未適用のデータをロードした場合に必要なデータを初期化します。
  202.     //=============================================================================
  203.     const _DataManager_extractSaveContents = DataManager.extractSaveContents;
  204.     DataManager.extractSaveContents      = function(saveFileId) {
  205.         _DataManager_extractSaveContents.apply(this, arguments);
  206.         $gameParty.initNpcIfNeed();
  207.     };
  208. })();
复制代码
回复

使用道具 举报

梦石
0
星屑
74
在线时间
56 小时
注册时间
2022-1-26
回帖
13
 楼主| 发表于 2022-3-10 08:08:08 | 显示全部楼层
tseyik 发表于 2022-3-9 14:21
[fold=NpcFollower.js]//============================================================================ ...

没错就是这种!求插件

点评

下面就是  发表于 2022-3-10 11:21
回复

使用道具 举报

梦石
0
星屑
74
在线时间
56 小时
注册时间
2022-1-26
回帖
13
 楼主| 发表于 2022-3-10 09:24:50 | 显示全部楼层
HM495 发表于 2022-3-9 01:47
换个思路 做个载具外观的角色加入队伍带队

如何在载具状态下有shift效果(加速)
回复

使用道具 举报

梦石
0
星屑
7898
在线时间
1533 小时
注册时间
2013-12-3
回帖
306
发表于 2022-3-10 09:30:12 | 显示全部楼层
王丞相 发表于 2022-3-10 09:24
如何在载具状态下有shift效果(加速)

设置移动路线 玩家 更改移动速度
回复

使用道具 举报

梦石
0
星屑
74
在线时间
56 小时
注册时间
2022-1-26
回帖
13
 楼主| 发表于 2022-4-28 18:33:32 | 显示全部楼层
HM495 发表于 2022-3-10 09:30
设置移动路线 玩家 更改移动速度

感谢大佬啊
回复

使用道具 举报

梦石
0
星屑
1144
在线时间
110 小时
注册时间
2021-8-21
回帖
67
发表于 2022-4-29 12:00:30 | 显示全部楼层
本帖最后由 guihuasheng 于 2022-4-29 12:02 编辑

回复

使用道具 举报

梦石
0
星屑
1144
在线时间
110 小时
注册时间
2021-8-21
回帖
67
发表于 2022-4-29 12:01:41 | 显示全部楼层
/*
Title: Land Vehicles
Author: DKPlugins
Site: https://dk-plugins.ru
E-mail: kuznetsovdenis96@gmail.com
Version: 2.0.0
Release: 10.09.2020
First release: 23.08.2016
*/

/*ru
Название: Наземный Транспорт
Автор: DKPlugins
Сайт: https://dk-plugins.ru
E-mail: kuznetsovdenis96@gmail.com
Версия: 2.0.0
Релиз: 10.09.2020
Первый релиз: 23.08.2016
*/

/*:
* @plugindesc v.2.0.0 Adds a land vehicles
* @author DKPlugins
* @url https://dk-plugins.ru
* @target MZ
* @help

### Info about plugin ###
Title: DK_Land_Vehicles
Author: DKPlugins
Site: https://dk-plugins.ru
Version: 2.0.0
Release: 10.09.2020
First release: 23.08.2016

###=========================================================================
## Compatibility
###=========================================================================
RPG Maker MV: 1.5+
RPG Maker MZ: 1.0+

###===========================================================================
## Plugin commands (RPG Maker MV)
###===========================================================================
1. Change vehicle BGM: ChangeVehicleBGM [TYPE] [NAME] [VOLUME] [PITCH] [PAN]
TYPE - Type of vehicle
NAME - BGM name
VOLUME - Volume
PITCH - Pitch
PAN - Panorama
Example: ChangeVehicleBGM bike Ship1 90 100 0

2. Set vehicle location: SetVehicleLocation [TYPE] [MAP ID] [X] [Y]
TYPE - Type of vehicle
MAP ID - Map id
X - The X coordinate
Y - The Y coordinate
Example: SetVehicleLocation bike 2 1 1

3. Change vehicle image: ChangeVehicleImage [TYPE] [NAME] [INDEX]
TYPE - Type of vehicle
NAME - Image name
INDEX - Image index
Example: ChangeVehicleImage car Vehicle 0

4. Set vehicle speed: SetVehicleMoveSpeed [TYPE] [SPEED]
TYPE - Type of vehicle
SPEED - Speed
Example: SetVehicleMoveSpeed car 4

###===========================================================================
## License and terms of use
###===========================================================================
You can:
-To use the plugin for your non-commercial projects
-Change code of the plugin

You cannot:
-Delete or change any information about the plugin
-Distribute the plugin and its modifications

## Commercial license ##
To use the plugin in commercial projects, you must be my subscriber on patreon
https://www.patreon.com/dkplugins

###===========================================================================
## Support
###===========================================================================
Donate: https://dk-plugins.ru/donate
Become a patron: https://www.patreon.com/dkplugins

* @command ChangeVehicleBGM
* @desc Change vehicle BGM
*
* @arg type
* @text Type
* @desc Vehicle type
* @type combo
* @option bike
* @option car
* @default bike
*
* @arg bgm
* @text BGM
* @desc BGM
* @type struct<VehicleBGM>
* @default {"name":"","volume":"90","pitch":"100","pan":"0"}

* @command SetVehicleLocation
* @desc Set vehicle location
*
* @arg type
* @text Type
* @desc Vehicle type
* @type combo
* @option bike
* @option car
* @default bike
*
* @arg mapId
* @text Map Id
* @desc Map id
* @type number
* @min 1
* @default 1

* @arg x
* @text X
* @desc The X coordinate
* @type number
* @min 0
* @default 0

* @arg y
* @text Y
* @desc The Y coordinate
* @type number
* @min 0
* @default 0

* @command ChangeVehicleImage
* @desc Change vehicle image
*
* @arg type
* @text Type
* @desc Vehicle type
* @type combo
* @option bike
* @option car
* @default bike
*
* @arg characterName
* @text Graphic file
* @desc Graphic file
* @type file
* @dir img/characters
* @require 1
* @default Vehicle

* @arg characterIndex
* @text Graphic index
* @desc Graphic index. Numbering starts from 0.
* @type number
* @min 0
* @default 0

* @command SetVehicleMoveSpeed
* @desc Set vehicle speed
*
* @arg type
* @text Type
* @desc Vehicle type
* @type combo
* @option bike
* @option car
* @default bike
*
* @arg speed
* @text Speed
* @desc Vehicle speed
* @type number
* @min 1
* @default 5

* @param vehicles
* @text Vehicles
* @desc List of vehicles
* @type struct<Vehicle>[]
* @default []

*/

/*:ru
* @plugindesc v.2.0.0 Добавляет наземный транспорт
* @author DKPlugins
* @url https://dk-plugins.ru
* @target MZ
* @help

### Информация о плагине ###
Название: DK_Land_Vehicles
Автор: DKPlugins
Сайт: https://dk-plugins.ru
Версия: 2.0.0
Релиз: 10.09.2020
Первый релиз: 23.08.2016

###=========================================================================
## Совместимость
###=========================================================================
RPG Maker MV: 1.6+
RPG Maker MZ: 1.0+

###=========================================================================
## Команды плагина (RPG Maker MV)
###=========================================================================
1. Изменить BGM транспорта: ChangeVehicleBGM [TYPE] [NAME] [VOLUME] [PITCH] [PAN]
TYPE - Тип транспорта
NAME - Название BGM
VOLUME - Громкость
PITCH - Тон
PAN - Панорама
Пример: ChangeVehicleBGM bike Ship1 100 100 0

2. Переместить транспорт: SetVehicleLocation [TYPE] [MAP ID] [X] [Y]
TYPE - Тип транспорта
MAP ID - Номер карты
X - Координата X
Y - Координата Y
Пример: SetVehicleLocation bike 2 1 1

3. Изменить изображение транспорта: ChangeVehicleImage [TYPE] [NAME] [INDEX]
TYPE - Тип транспорта
NAME - Название изображения
INDEX - Индекс изображения
Пример: ChangeVehicleImage car Vehicle 0

4. Изменить скорость транспорта: SetVehicleMoveSpeed [TYPE] [SPEED]
TYPE - Тип транспорта
SPEED - Скорость
Пример: SetVehicleMoveSpeed car 4

###===========================================================================
## Лицензия и правила использования плагина
###===========================================================================
Вы можете:
-Использовать плагин в некоммерческих проектах
-Изменять код плагина

Вы не можете:
-Удалять или изменять любую информацию о плагине
-Распространять плагин и его модификации

## Коммерческая лицензия ##
Для использования плагина в коммерческих проектах необходимо быть моим подписчиком на патреоне
https://www.patreon.com/dkplugins

###=========================================================================
## Поддержка
###=========================================================================
Поддержать: https://dk-plugins.ru/donate
Стать патроном: https://www.patreon.com/dkplugins

* @command ChangeVehicleBGM
* @desc Изменить BGM транспорта
*
* @arg type
* @text Тип
* @desc Тип транспорта
* @type combo
* @option bike
* @option car
* @default bike
*
* @arg bgm
* @text BGM
* @desc BGM
* @type struct<VehicleBGM>
* @default {"name":"","volume":"90","pitch":"100","pan":"0"}

* @command SetVehicleLocation
* @desc Установить позицию транспорта
*
* @arg type
* @text Тип
* @desc Тип транспорта
* @type combo
* @option bike
* @option car
* @default bike
*
* @arg mapId
* @text Номер карты
* @desc Номер карты
* @type number
* @min 1
* @default 1

* @arg x
* @text X
* @desc Координата X
* @type number
* @min 0
* @default 0

* @arg y
* @text Y
* @desc Координата Y
* @type number
* @min 0
* @default 0

* @command ChangeVehicleImage
* @desc Change vehicle image
*
* @arg type
* @text Тип
* @desc Тип транспорта
* @type combo
* @option bike
* @option car
* @default bike
*
* @arg characterName
* @text Графика
* @desc Графика
* @type file
* @dir img/characters
* @require 1
* @default Vehicle

* @arg characterIndex
* @text Индекс графики
* @desc Индекс графики. Нумерация начинается с 0.
* @type number
* @min 0
* @default 0

* @command SetVehicleMoveSpeed
* @desc Установить скорость транспорта
*
* @arg type
* @text Тип
* @desc Тип транспорта
* @type combo
* @option bike
* @option car
* @default bike
*
* @arg speed
* @text Скорость
* @desc Скорость транспорта
* @type number
* @min 1
* @default 5

* @param vehicles
* @text Транспортные средства
* @desc Список транспортных средств
* @type struct<Vehicle>[]
* @default []

*/

/*~struct~Vehicle:

* @param type
* @text Type
* @desc Vehicle type. Unique for each vehicle!
* @type combo
* @option bike
* @option car
* @default bike

* @param mapId
* @text Map Id
* @desc Start map id
* @type number
* @min 1
* @default 1

* @param x
* @text X
* @desc Start X coordinate
* @type number
* @min 0
* @default 0

* @param y
* @text Y
* @desc Start Y coordinate
* @type number
* @min 0
* @default 0

* @param switch
* @text Switch
* @desc A switch that turns on when the player is using a vehicle
* @type switch
* @default 0

* @param bgm
* @text BGM
* @desc Background music
* @type struct<VehicleBGM>
* @default {"name":"","volume":"90","pitch":"100","pan":"0"}

* @param speed
* @text Speed
* @desc Speed of vehicle
* @type number
* @min 1
* @default 5

* @param characterName
* @text Graphic file
* @desc Graphic file
* @type file
* @dir img/characters
* @require 1
* @default Vehicle

* @param characterIndex
* @text Graphic index
* @desc Graphic index. Numbering starts from 0.
* @type number
* @min 0
* @default 0

* @param includedRegions
* @text Included Regions
* @desc Regions where vehicle can move. 0 - All Regions permitted.
* @type number[]
* @default ["0"]

* @param excludedRegions
* @text Excluded Regions
* @desc Regions where vehicle can not move. Has priority over included regions.
* @type number[]
* @min 1
* @default []

* @param visibilitySwitch
* @text Visibility Switch
* @desc Vehicle visibility switch
* @type switch
* @default 0

*/

/*~struct~Vehicle:ru

* @param type
* @text Тип транспорта
* @desc Тип транспорта. Уникальное значение для каждого транспорта!
* @type combo
* @option bike
* @option car
* @default bike

* @param mapId
* @text Номер карты
* @desc Стартовый номер карты
* @type number
* @min 1
* @default 1

* @param x
* @text Координата X
* @desc Стартовая координата X
* @type number
* @min 0
* @default 0

* @param y
* @text Координата Y
* @desc Стартовая координата Y
* @type number
* @min 0
* @default 0

* @param switch
* @text Переключатель
* @desc Переключатель, который включается, когда персонаж использует транспорт
* @type switch
* @default 0

* @param bgm
* @text Фоновая музыка
* @desc Фоновая музыка
* @type struct<VehicleBGM>
* @default {"name":"","volume":"90","pitch":"100","pan":"0"}

* @param speed
* @text Скорость
* @desc Скорость транспорта
* @type number
* @min 1
* @default 5
*
* @param characterName
* @text Графика
* @desc Графика
* @type file
* @dir img/characters
* @require 1

* @param characterIndex
* @text Индекс графики
* @desc Индекс графики. Нумерация начинается с 0.
* @type number
* @min 0
* @default 0

* @param includedRegions
* @text Доступные регионы
* @desc Регионы, где транспорт может двигаться. 0 - Все регионы разрешены
* @type number[]
* @default ["0"]

* @param excludedRegions
* @text Недоступные регионы
* @desc Регионы, где транспорт не может двигаться. Имеет приоритет над доступными регионами.
* @type number[]
* @min 1
* @default []

* @param Visibility Switch
* @text Переключатель видимости
* @desc Переключатель видимости транспорта
* @type switch
* @default 0

*/

/*~struct~VehicleBGM:

* @param name
* @text File
* @desc File
* @type file
* @dir audio/bgm/

* @param volume
* @text Volume
* @desc Volume
* @type number
* @min 0
* @max 100
* @default 90

* @param pitch
* @text Pitch
* @desc Pitch
* @type number
* @min 50
* @max 150
* @default 100

* @param pan
* @text Pan
* @text Panorama
* @desc Panorama
* @type number
* @min -100
* @max 100
* @default 0

*/

/*~struct~VehicleBGM:ru

* @param name
* @text Файл
* @desc Файл
* @type file
* @dir audio/bgm/

* @param volume
* @text Громкость
* @desc Громкость
* @type number
* @min 0
* @max 100
* @default 90

* @param pitch
* @text Темп
* @desc Темп
* @type number
* @min 50
* @max 150
* @default 100

* @param pan
* @text Панорама
* @desc Панорама
* @type number
* @min -100
* @max 100
* @default 0

*/

'use strict';

var Imported = Imported || {};
Imported['DK_Land_Vehicles'] = '2.0.0';

(function() {

    const parameters = PluginManager.parameters('DK_Land_Vehicles');
    const params = {
        vehicles: JSON.parse(parameters.vehicles).map((json) => {
            const data = JSON.parse(json);

            data.mapId = parseInt(data.mapId);
            data.x = parseInt(data.x);
            data.y = parseInt(data.y);
            data.speed = parseInt(data.speed);
            data.switch = parseInt(data.switch);
            data.includedRegions = JSON.parse(data.includedRegions).map(id => parseInt(id));
            data.excludedRegions = JSON.parse(data.excludedRegions).map(id => parseInt(id));
            data.characterIndex = parseInt(data.characterIndex);
            data.visibilitySwitch = parseInt(data.visibilitySwitch);

            if (data.bgm) {
                data.bgm = JSON.parse(data.bgm);
            }

            return data;
        })
    };

    //===========================================================================
    // Game_CharacterBase
    //===========================================================================

    const LandVehicles_Game_CharacterBase_isCollidedWithVehicles =
        Game_CharacterBase.prototype.isCollidedWithVehicles;
    Game_CharacterBase.prototype.isCollidedWithVehicles = function(x, y) {
        return LandVehicles_Game_CharacterBase_isCollidedWithVehicles.apply(this, arguments)
            || this.isCollidedWithLandVehicles(x, y);
    };

    Game_CharacterBase.prototype.isCollidedWithLandVehicles = function(x, y) {
        const vehicles = $gameMap.vehicles();

        for (let i = 0; i < vehicles.length; i++) {
            const vehicle = vehicles;

            if (vehicle.isLandVehicle() && vehicle.opacity() > 0 && vehicle.posNt(x, y)) {
                return true;
            }
        }

        return false;
    };

    //===========================================================================
    // Game Player
    //===========================================================================

    const LandVehicles_Game_Player_triggerTouchActionD1 =
        Game_Player.prototype.triggerTouchActionD1;
    Game_Player.prototype.triggerTouchActionD1 = function(x1, y1) {
        if (this.isCollidedWithLandVehicles(x1, y1)) {
            if (TouchInput.isTriggered() && this.getOnOffVehicle()) {
                return true;
            }
        }

        return LandVehicles_Game_Player_triggerTouchActionD1.apply(this, arguments);
    };

    const LandVehicles_Game_Player_triggerTouchActionD2 =
        Game_Player.prototype.triggerTouchActionD2;
    Game_Player.prototype.triggerTouchActionD2 = function(x2, y2) {
        if (this.isCollidedWithLandVehicles(x2, y2)) {
            if (TouchInput.isTriggered() && this.getOnVehicle()) {
                return true;
            }
        }

        return LandVehicles_Game_Player_triggerTouchActionD2.apply(this, arguments);
    };

    Game_Player.prototype.isInLandVehicle = function() {
        return !this.isInBoat() && !this.isInShip() && !this.isInAirship() &&
            this._vehicleType !== 'walk' && !this.isMoveRouteForcing();
    };

    const LandVehicles_Game_Player_isInVehicle = Game_Player.prototype.isInVehicle;
    Game_Player.prototype.isInVehicle = function() {
        return LandVehicles_Game_Player_isInVehicle.apply(this, arguments)
            || this.isInLandVehicle();
    };

    const LandVehicles_Game_Player_getOnVehicle = Game_Player.prototype.getOnVehicle;
    Game_Player.prototype.getOnVehicle = function() {
        const direction = this.direction();
        const x2 = $gameMap.roundXWithDirection(this.x, direction);
        const y2 = $gameMap.roundYWithDirection(this.y, direction);
        const type = $gameMap.landVehicleType(x2, y2);

        if (type) {
            this._vehicleType = type;
        }

        return LandVehicles_Game_Player_getOnVehicle.apply(this, arguments);
    };

    //===========================================================================
    // Game Vehicle
    //===========================================================================

    const LandVehicles_Game_Vehicle_initMoveSpeed =
        Game_Vehicle.prototype.initMoveSpeed;
    Game_Vehicle.prototype.initMoveSpeed = function() {
        if (this.isLandVehicle()) {
            this.setMoveSpeed(this.vehicle().speed);
        } else {
            LandVehicles_Game_Vehicle_initMoveSpeed.apply(this, arguments);
        }
    };

    const LandVehicles_Game_Vehicle_vehicle = Game_Vehicle.prototype.vehicle;
    Game_Vehicle.prototype.vehicle = function() {
        return LandVehicles_Game_Vehicle_vehicle.apply(this, arguments)
            || params.vehicles.find(v => v.type === this._type) || null;
    };

    const LandVehicles_Game_Vehicle_loadSystemSettings =
        Game_Vehicle.prototype.loadSystemSettings;
    Game_Vehicle.prototype.loadSystemSettings = function() {
        if (!this.isLandVehicle()) {
            return LandVehicles_Game_Vehicle_loadSystemSettings.apply(this, arguments);
        }

        const vehicle = this.vehicle();

        this._mapId = vehicle.mapId;

        this.setPosition(vehicle.x, vehicle.y);
        this.setImage(vehicle.characterName, vehicle.characterIndex);
    };

    const LandVehicles_Game_Vehicle_playBgm =
        Game_Vehicle.prototype.playBgm;
    Game_Vehicle.prototype.playBgm = function() {
        if (this.isLandVehicle()) {
            const bgm = this._bgm || this.vehicle().bgm;

            if (bgm && bgm.name) {
                AudioManager.playBgm(bgm);
            }
        } else {
            LandVehicles_Game_Vehicle_playBgm.apply(this, arguments);
        }
    };

    const LandVehicles_Game_Vehicle_update = Game_Vehicle.prototype.update;
    Game_Vehicle.prototype.update = function() {
        LandVehicles_Game_Vehicle_update.apply(this, arguments);

        const vehicle = this.vehicle();

        if (vehicle && vehicle.visibilitySwitch > 0) {
            if ($gameSwitches.value(vehicle.visibilitySwitch)) {
                this.setOpacity(255);
            } else {
                this.setOpacity(0);
            }
        }
    };

    const LandVehicles_Game_Vehicle_isMapPassable = Game_Vehicle.prototype.isMapPassable;
    Game_Vehicle.prototype.isMapPassable = function(x, y, d) {
        if (this.isLandVehicle()) {
            const x2 = $gameMap.roundXWithDirection(x, d);
            const y2 = $gameMap.roundYWithDirection(y, d);
            const vehicle = this.vehicle();
            const includedRegions = vehicle.includedRegions || [0];
            const excludedRegions = vehicle.excludedRegions || [];
            const regionId = $gameMap.regionId(x2, y2);

            return $gameMap.isPassable(x2, y2)
                && (includedRegions.includes(regionId) || includedRegions.includes(0))
                && !excludedRegions.includes(regionId);
        } else {
            return LandVehicles_Game_Vehicle_isMapPassable.apply(this, arguments);
        }
    };

    Game_Vehicle.prototype.isLandVehicle = function() {
        return !this.isBoat() && !this.isShip() && !this.isAirship();
    };

    const LandVehicles_Game_Vehicle_getOn = Game_Vehicle.prototype.getOn;
    Game_Vehicle.prototype.getOn = function() {
        LandVehicles_Game_Vehicle_getOn.apply(this, arguments);

        const vehicle = this.vehicle();

        if (vehicle && vehicle.switch > 0) {
            $gameSwitches.setValue(vehicle.switch, true);
        }
    };

    const LandVehicles_Game_Vehicle_getOff = Game_Vehicle.prototype.getOff;
    Game_Vehicle.prototype.getOff = function() {
        LandVehicles_Game_Vehicle_getOff.apply(this, arguments);

        const vehicle = this.vehicle();

        if (vehicle && vehicle.switch > 0) {
            $gameSwitches.setValue(vehicle.switch, false);
        }
    };

    //===========================================================================
    // Game_Map
    //===========================================================================

    const LandVehicles_Game_Map_createVehicles = Game_Map.prototype.createVehicles;
    Game_Map.prototype.createVehicles = function() {
        LandVehicles_Game_Map_createVehicles.apply(this, arguments);

        params.vehicles.forEach((vehicle) => {
            this._vehicles.push(new Game_Vehicle(vehicle.type));
        });
    };

    Game_Map.prototype.landVehicleType = function(x, y) {
        const vehicle = this.vehicles()
                             .find(v => v.opacity() > 0 && v.pos(x, y));

        return (vehicle ? vehicle._type : null);
    };

    const LandVehicles_Game_Map_vehicle = Game_Map.prototype.vehicle;
    Game_Map.prototype.vehicle = function(type) {
        const vehicle = LandVehicles_Game_Map_vehicle.apply(this, arguments);

        if (vehicle) {
            return vehicle;
        }

        const vehicles = this.vehicles();

        if (Number.isFinite(type)) {
            return vehicles[type];
        }

        return vehicles.find(v => v._type === type) || null;
    };

    if (Utils.RPGMAKER_NAME === 'MV') {

        const LandVehicles_Game_Interpreter_pluginCommand =
            Game_Interpreter.prototype.pluginCommand;
        Game_Interpreter.prototype.pluginCommand = function(command, args) {
            LandVehicles_Game_Interpreter_pluginCommand.apply(this, arguments);

            switch (command) {
                case 'ChangeVehicleBGM': {
                    const type = args[0];
                    const vehicle = $gameMap.vehicle(type);

                    if (vehicle) {
                        vehicle.setBgm({
                            name: args[1],
                            volume: Number(args[2]),
                            pitch: Number(args[3]),
                            pan: Number(args[4])
                        });
                    } else {
                        throw new Error(`ChangeVehicleBGM: Vehicle with type = ${type} not found!`);
                    }

                    break;
                }
                case 'SetVehicleLocation': {
                    const type = args[0];
                    const vehicle = $gameMap.vehicle(type);

                    if (vehicle) {
                        const mapId = Number(args[1]);
                        const x = Number(args[2]);
                        const y = Number(args[3]);

                        vehicle.setLocation(mapId, x, y);
                    } else {
                        throw new Error(`SetVehicleLocation: Vehicle with type = ${type} not found!`);
                    }

                    break;
                }
                case 'ChangeVehicleImage': {
                    const type = args[0];
                    const vehicle = $gameMap.vehicle(type);

                    if (vehicle) {
                        const name = args[1];
                        const index = Number(args[2]);

                        vehicle.setImage(name, index);
                    } else {
                        throw new Error(`ChangeVehicleImage: Vehicle with type = ${type} not found!`);
                    }

                    break;
                }
                case 'SetVehicleMoveSpeed': {
                    const type = args[0];
                    const vehicle = $gameMap.vehicle(type);

                    if (vehicle) {
                        vehicle.setMoveSpeed(Number(args[1]));
                    } else {
                        throw new Error(`SetVehicleMoveSpeed: Vehicle with type = ${type} not found!`);
                    }

                    break;
                }
            }
        };

    } else {

        PluginManager.registerCommand('DK_Land_Vehicles',
            'ChangeVehicleBGM', (args) => {
            const type = args.type;
            const vehicle = $gameMap.vehicle(type);

            if (vehicle) {
                const bgm = JSON.parse(args.bgm);

                bgm.volume = Number(bgm.volume);
                bgm.pitch = Number(bgm.pitch);
                bgm.pan = Number(bgm.pan);

                vehicle.setBgm(bgm);
            } else {
                throw new Error(`ChangeVehicleBGM: Vehicle with type = ${type} not found!`);
            }
        });

        PluginManager.registerCommand('DK_Land_Vehicles',
            'SetVehicleLocation', (args) => {
                const type = args.type;
                const vehicle = $gameMap.vehicle(type);

                if (vehicle) {
                    const mapId = Number(args.mapId);
                    const x = Number(args.x);
                    const y = Number(args.y);

                    vehicle.setLocation(mapId, x, y);
                } else {
                    throw new Error(`SetVehicleLocation: Vehicle with type = ${type} not found!`);
                }
        });

        PluginManager.registerCommand('DK_Land_Vehicles',
            'ChangeVehicleImage', (args) => {
                const type = args.type;
                const vehicle = $gameMap.vehicle(type);

                if (vehicle) {
                    const name = args.characterName;
                    const index = Number(args.characterIndex);

                    vehicle.setImage(name, index);
                } else {
                    throw new Error(`ChangeVehicleImage: Vehicle with type = ${type} not found!`);
                }
        });

        PluginManager.registerCommand('DK_Land_Vehicles',
            'SetVehicleMoveSpeed', (args) => {
                const type = args.type;
                const vehicle = $gameMap.vehicle(type);

                if (vehicle) {
                    vehicle.setMoveSpeed(Number(args.speed));
                } else {
                    throw new Error(`SetVehicleMoveSpeed: Vehicle with type = ${type} not found!`);
                }
            });

    }

})();
回复

使用道具 举报

梦石
0
星屑
841
在线时间
113 小时
注册时间
2022-4-30
回帖
45
发表于 2022-5-27 11:41:40 | 显示全部楼层

如何在载具状态下有shift效果(加速)
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部