| 赞 | 15 |
| VIP | |
| 好人卡 | |
| 积分 | 3 |
| 经验 | |
| 最后登录 | 2026-5-25 |
| 在线时间 | 217 小时 |
- 梦石
- 0
- 星屑
- 296
- 在线时间
- 217 小时
- 注册时间
- 2008-12-18
- 回帖
- 30
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 魏玉龙 于 2018-9-17 12:16 编辑
将NPC视野改为 NPC朝向的一个直径为5的三角形区域
当玩家没有进入NPC视野中时,NPC可静止或自由移动
当玩家进入NPC视野内,NPC会发现玩家并快速靠近
NPC自由移动时不会突兀的转身(即突然向后看),所以该插件适合做潜行玩法。
启用插件后NPC自主移动类型选接近就可以了!
- //=============================================================================
- // DiscoverThePlayer.js
- //=============================================================================
- /*:
- * @plugindesc NPC视野算法插件
- * @author 魏玉龙
- * @since 2018.09.17
- * @version 1.0
- *
- * @param range
- * @desc 视野范围
- * @default 5
- *
- * @param Enc-None
- * @desc 开启不遇敌时,NPC是否逃离?true 逃离,false 不逃离
- * @default true
- *
- * @param flee
- * @desc 空闲时的状态 0:静止不动 1:随机移动
- * @default 0
- *
- * @help
- * 此插件为NPC提供了视野算法,当玩家出现在NPC视野内才会被发现并迅速靠近。
- *
- * 此插件提供以下插件命令
- *
- * DTP range number
- * DTP encNone true/false
- * DTP flee number
- *
- */
- (function () {
- var parameters = PluginManager.parameters('DiscoverThePlayer');
- var config = {
- range: Number(parameters['range'] || 5),
- encNone: JSON.parse(parameters['Enc-None']),
- flee: Number(parameters['flee'] || 0)
- };
- var _Game_Event_initMembers = Game_Event.prototype.initMembers;
- Game_Event.prototype.initMembers = function () {
- _Game_Event_initMembers.call(this);
- this._discover = false;
- };
- Game_Event.prototype.moveTypeTowardPlayer = function () {
- var page = this.page();
- var direction = this.direction();
- if (!this._discover && this.isNearThePlayer() && this.isDiscoverThePlayer()) {
- this._discover = true;
- AudioManager.playSe({
- name: 'Jump1',
- volume: 75,
- pitch: 85,
- pan: 0
- });
- this.requestBalloon(1);
- this.setMoveSpeed($gamePlayer.moveSpeed());
- this.setMoveFrequency($gamePlayer.moveFrequency());
- }
- if (this._discover && this.isNearThePlayer()) {
- if ($gameSystem.isEncounterEnabled()) {
- this.moveTowardPlayer();
- } else if (config.encNone) {
- this.moveAwayFromPlayer();
- }
- } else {
- this._discover = false
- this.setMoveSpeed(page.moveSpeed);
- this.setMoveFrequency(page.moveFrequency);
- if (config.flee === 1) {
- var d = [2,4,6,8].filter(v=>v!=(10-direction));
- var i = Math.randomInt(3);
- this.moveStraight(d[i]);
- }
- }
- };
- Game_Event.prototype.isNearThePlayer = function () {
- var sx = Math.abs(this.deltaXFrom($gamePlayer.x));
- var sy = Math.abs(this.deltaYFrom($gamePlayer.y));
- return sx <= config.range && sy <= config.range;
- };
- Game_Event.prototype.isDiscoverThePlayer = function () {
- var direction = this.direction();
- var sx = this.deltaXFrom($gamePlayer.x);
- var sy = this.deltaYFrom($gamePlayer.y);
- switch (direction) {
- case 2:
- if (sy < 0 && sy >= -(config.range)) {
- if (sx < Math.abs(sy) && sx > -(Math.abs(sy))) {
- return true;
- }
- }
- break;
- case 4:
- if (sx > 0 && sx <= config.range) {
- if (sy < Math.abs(sx) && sy > -(Math.abs(sx))) {
- return true;
- }
- }
- break;
- case 6:
- if (sx < 0 && sx >= -(config.range)) {
- if (sy < Math.abs(sx) && sy > -(Math.abs(sx))) {
- return true;
- }
- }
- break;
- case 8:
- if (sy > 0 && sy <= config.range) {
- if (sx < Math.abs(sy) && sx > -(Math.abs(sy))) {
- return true;
- }
- }
- break;
- }
- return false;
- };
- var alias_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function (command, args) {
- alias_Game_Interpreter_pluginCommand.call(this, command, args);
- if (command === "DTP") {
- switch (args[0]) {
- case 'range':
- config.range = Number(args[1] || 5)
- break;
- case 'encNone':
- config.encNone = JSON.parse(args[1] || 5)
- break;
- case 'flee':
- config.flee = Number(args[1] || 5)
- break;
- }
- }
- }
- })();
复制代码 |
评分
-
查看全部评分
|