Skip to content

Instantly share code, notes, and snippets.

@agoaj

agoaj/AltimitMovement.js Secret

Created Aug 23, 2020
Embed
What would you like to do?
/*
* MIT License
*
* Copyright (c) 2017-2018 Altimit Community Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
//=============================================================================
// AltimitMovement.js
//=============================================================================
/*:
* @target mz
* @plugindesc Vector-based character movement and collision
* @author Altimit Community Contributors
* @url https://github.com/AltimitSystems/mv-plugins/tree/master/movement
*
* @param player
* @text Player
* @desc Parameters related to player character.
*
* @param player_collider_list
* @text Collider
* @desc Default collider list for player character.
* @parent player
* @type note
* @default "<circle cx='0.5' cy='0.7' r='0.25' />"
*
* @param player_circular_movement
* @text Normalize the movement?
* @desc Should the diagonal movement be the same distance as the straight movement?
* @parent player
* @type boolean
* @on Yes
* @off No
* @default true
*
* @param
*
* @param followers
* @text Followers
* @desc Parameters related to party followers.
*
* @param followers_distance
* @text Follow distance
* @desc Distance of 1 results in a tight chain. Distance of 2 will double the spacing.
* @parent followers
* @type number
* @min 0
* @decimals 2
* @default 1.50
*
* @param followers_collider_list
* @text Collider
* @desc Default collider list for followers.
* @parent followers
* @type note
* @default "<circle cx='0.5' cy='0.7' r='0.25' />"
*
* @param followers_circular_movement
* @text Normalize the movement?
* @desc Should the diagonal movement be the same distance as the straight movement?
* @parent followers
* @type boolean
* @on Yes
* @off No
* @default true
*
* @param
*
* @param vehicles
* @text Vehicles
* @desc Parameters related to the vehicles.
*
* @param vehicles_boat_collider_list
* @text Boat collider
* @desc Default collider list for the boat.
* @parent vehicles
* @type note
* @default "<circle cx='0.5' cy='0.5' r='0.333' />"
*
* @param vehicles_ship_collider_list
* @text Ship collider
* @desc Default collider list for the ship.
* @parent vehicles
* @type note
* @default "<circle cx='0.5' cy='0.5' r='0.5' />"
*
* @param vehicles_airship_collider_list
* @text Airship collider
* @desc Default collider list for the airship.
* @parent vehicles
* @type note
* @default "<circle cx='0.5' cy='0.5' r='0.25' />"
*
* @param
*
* @param event
* @text Events
* @desc Parameters related to events.
*
* @param event_character_collider_list
* @text Character collider
* @desc Default collider list for character events.
* @parent event
* @type note
* @default "<circle cx='0.5' cy='0.7' r='0.25' />"
*
* @param event_tile_collider_list
* @text Tile collider
* @desc Default collider list for tile events.
* @parent event
* @type note
* @default "<rect x='0' y='0' width='1' height='1' />"
*
* @param
*
* @param presets
* @text Collider presets
* @desc Preset colliders to be referenced by events.
* @type note[]
* @default []
*
* @param
*
* @param move_route
* @text Move route behaviour
* @desc Parameters related to character move routes.
*
* @param move_route_align_grid
* @text Align move-routes to grid?
* @desc If character is offset on a tile align them to the tile grid when moving.
* @parent move_route
* @type boolean
* @on Yes
* @off No
* @default true
*
* @param
*
* @param input_config
* @text Input config
* @desc Configuration for input method.
*
* @param input_config_enable_touch_mouse
* @text Use touch/mouse?
* @desc Enables pointer-based input.
* @parent input_config
* @type boolean
* @on Yes
* @off No
* @default true
*
* @param input_config_gamepad_mode
* @text Gamepad mode
* @desc Gamepad analogue stick input control.
* @parent input_config
* @type select
* @option Movement + Facing
* @value 3
* @option Movement only
* @value 2
* @option Facing only
* @value 1
* @option Disabled
* @value 0
* @default 3
*
* @param
*
* @param play_test
* @text Play-testing
* @desc Parameters when running in Play-test mode.
*
* @param play_test_collision_mesh_caching
* @text Use cached collision?
* @desc Disabled caching will re-compile the collision mesh for maps that are in-development.
* @parent play_test
* @type boolean
* @on Yes
* @off No
* @default false
*
*
* @help
*
*
* Usage:
* Plugin will automatically apply when ON.
*
* About:
* Version 0.50 Beta
* Website https://github.com/AltimitSystems/mv-plugins/tree/master/movement
* @end
* =============================================================================
* Plugin Commands
* =============================================================================
*
* @command setPlayerCollider
* @text Change Player Collider
* @desc Change Player's Collider to another preset.
*
* @arg colliderPreset
* @text Change To
* @type text
* @default 1
* @desc Change the collider to this preset(Defined in plugin settings).
* Numbers are treated as an index into the preset array. 0 is the default collider.
* Text will find a collider with a matching Name field.
*
* @command setThisCollider
* @text Change This Collider
* @desc Change this event's Collider to another preset.
*
* @arg colliderPreset
* @text Change To
* @type text
* @default 1
* @desc Change the collider to this preset(Defined in plugin settings).
* Numbers are treated as an index into the preset array. 0 is the default collider.
* Text will find a collider with a matching Name field.
*
* @command setEventCollider
* @text Change Event Collider
* @desc Change an event's Collider to another preset.
*
* @arg eventId
* @text Event
* @type text
* @default 1
* @desc Enter the event name or the ID number.
*
* @arg colliderPreset
* @text Change To
* @type text
* @default 1
* @desc Change the collider to this preset(Defined in plugin settings).
* Numbers are treated as an index into the preset array. 0 is the default collider.
* Text will find a collider with a matching Name field.
*
* @command setVehicleCollider
* @text Change Vehicle Collider
* @desc Change a vehicle's Collider to another preset.
*
* @arg vehicleId
* @text Vehicle
* @type select
* @option Boat
* @value boat
* @option Ship
* @value ship
* @option Airship
* @value airship
* @default boat
* @desc Select the vehicle to change the collider for.
*
* @arg colliderPreset
* @text Change To
* @type text
* @default 1
* @desc Change the collider to this preset(Defined in plugin settings).
* Numbers are treated as an index into the preset array. 0 is the default collider.
* Text will find a collider with a matching Name field.
*
* @command setFollowerCollider
* @text Change Follower Collider
* @desc Change a Follower's Collider to another preset.
*
* @arg followerId
* @text Follower
* @type select
* @option 1
* @value 1
* @option 2
* @value 2
* @option 3
* @value 3
* @default 1
* @desc Select the follower to change the collider for.
*
* @arg colliderPreset
* @text Change To
* @type text
* @default 1
* @desc Change the collider to this preset(Defined in plugin settings).
* Numbers are treated as an index into the preset array. 0 is the default collider.
* Text will find a collider with a matching Name field.
*
*
* @command setFollowersDistance
* @text Change Followers Distance
* @desc Change a Follower's follow distance from the player.
*
* @arg distance
* @text Following Distance
* @type number
* @decimals 2
* @default 0.25
* @desc The follow distance in tiles.
*
* @command setFollowersFollow
* @text Set Followers Can Follow
* @desc Change if followers can follow the player.
*
* @arg followerId
* @text Follower
* @type select
* @option 1
* @value 1
* @option 2
* @value 2
* @option 3
* @value 3
* @option All
* @value all
* @default 1
* @desc Select the follower to change.
*
* @arg shouldFollow
* @text Should Follow?
* @type boolean
* @on Follow
* @off Don't Follow
* @default true
* @desc Select if the follower should follow the player.
*
* @command setMoveAlign
* @text Change Move Route Alignment
* @desc Change if move routes should align to the grid.
*
* @arg alignToGrid
* @text Align To Grid?
* @type boolean
* @on Align To Grid
* @off Don't Align To Grid
* @default true
* @desc Move route commands will align to the grid.
*
*
* @command move
* @text Move
* @desc Do an advanced movement command
*
* @arg moveCommand
* @text Move Command
* @type struct<MoveStep>
* @desc Enter advanced movement commands
*
* @arg wait
* @text Wait For Completion
* @type boolean
* @on Yes
* @off No
* @default true
* @desc Waits for all movement to finish
*
* @arg isSkippable
* @text Skip If Cannot Move
* @type boolean
* @on Yes
* @off No
* @default false
* @desc Skips any command that would move a character into an impassable location.
*
*
* @command setTouchMouse
* @text Change Touch/Mouse Input
* @desc Change if Touch/Mouse Input is enabled.
*
* @arg value
* @text Touch/Mouse Enabled
* @type boolean
* @default false
* @desc Allows the player can move their character with mouse or touchscreen input.
*
* =============================================================================
* Struct Definitions
* =============================================================================
*/
/*~struct~MoveStep:
*
* @param mvr
* @text Mover
* @type select
* @default this
* @option Player
* @value player
* @option This
* @value this
* @option Event
* @value event
* @option Follower1
* @value follower1
* @option Follower2
* @value follower2
* @option Follower3
* @value follower3
* @option Boat
* @value boat
* @option Ship
* @value ship
* @option Airship
* @value airship
*
* @desc Select what you want to move.
* If you select event, also fill out the Mover Event Id field.
*
* @param dir
* @text Direction
* @type select
* @default random
* @option Random
* @value random
* @option
* @option
* @option
* @option
* @option
* @option
* @option
* @option
* @option Forward
* @value forward
* @option Backward
* @value backward
* @option Away From Other
* @value away
* @option Towards Other
* @value towards
*
* @param dist
* @text Distance
* @type number
* @decimals 2
* @default 1
* @desc Distance to move in tiles. Or set to the text edge and the character will align to the current tiles edge.
*
* @param other
* @text Other
* @type select
* @default player
* @option Player
* @value player
* @option This
* @value this
* @option Event
* @value event
* @option Boat
* @value boat
* @option Ship
* @value ship
* @option Airship
* @value airship
*
* @param moverEventId
* @text Mover Event Id
* @type text
* @desc Id number or name of event to move. Mover must be set to Event or this will be ignored.
*
* @param otherEventId
* @text Other Event Id
* @type text
* @desc Id number or name of event to move around. Direction must be set to Event or this will be ignored.
*/
( function() {
const pluginName = "AltimitMovement";
var DOM_PARSER = new DOMParser();
var PARAMETERS = PluginManager.parameters( 'AltimitMovement' );
var GAME_PAD_THRESHOLD = 1 / 5;
var GAME_PAD_LIMIT = 1 - GAME_PAD_THRESHOLD;
/**
* PLAYER
*/
var PLAYER;
( function() {
PLAYER = {
CIRCULAR_MOVEMENT: ( PARAMETERS['player_circular_movement'] != 'false' ),
};
var colliderList = PARAMETERS['player_collider_list'];
if ( colliderList ) {
PLAYER.COLLIDER_LIST = '<collider>' + JSON.parse( colliderList ) + '</collider>';
} else {
PLAYER.COLLIDER_LIST = "<collider><circle cx='0.5' cy='0.7' r='0.25' /></collider>";
}
} )();
/**
* FOLLOWERS
*/
var FOLLOWERS;
( function() {
FOLLOWERS = {
DISTANCE: Number( PARAMETERS['followers_distance'] ),
CIRCULAR_MOVEMENT: ( PARAMETERS['followers_circular_movement'] != 'false' ),
};
var colliderList = PARAMETERS['followers_collider_list'];
if ( colliderList ) {
FOLLOWERS.COLLIDER_LIST = '<collider>' + JSON.parse( colliderList ) + '</collider>';
} else {
FOLLOWERS.COLLIDER_LIST = "<collider><circle cx='0.5' cy='0.7' r='0.25' /></collider>";
}
} )();
/**
* VEHICLES
*/
var VEHICLES;
( function() {
VEHICLES = {};
var colliderList = PARAMETERS['vehicles_boat_collider_list'];
if ( colliderList ) {
VEHICLES.BOAT_COLLIDER_LIST = '<collider>' + JSON.parse( colliderList ) + '</collider>';
} else {
VEHICLES.BOAT_COLLIDER_LIST = "<collider><circle cx='0.5' cy='0.5' r='0.333' /></collider>";
}
var colliderList = PARAMETERS['vehicles_ship_collider_list'];
if ( colliderList ) {
VEHICLES.SHIP_COLLIDER_LIST = '<collider>' + JSON.parse( colliderList ) + '</collider>';
} else {
VEHICLES.SHIP_COLLIDER_LIST = "<collider><circle cx='0.5' cy='0.5' r='0.5' /></collider>";
}
var colliderList = PARAMETERS['vehicles_airship_collider_list'];
if ( colliderList ) {
VEHICLES.AIRSHIP_COLLIDER_LIST = '<collider>' + JSON.parse( colliderList ) + '</collider>';
} else {
VEHICLES.AIRSHIP_COLLIDER_LIST = "<collider><circle cx='0.5' cy='0.5' r='0.25' /></collider>";
}
} )();
/**
* EVENT
*/
var EVENT;
( function() {
EVENT = {};
var colliderList = PARAMETERS['event_character_collider_list'];
if ( colliderList ) {
EVENT.CHARACTER_COLLIDER_LIST = '<collider>' + JSON.parse( colliderList ) + '</collider>';
} else {
EVENT.CHARACTER_COLLIDER_LIST = "<collider><circle cx='0.5' cy='0.7' r='0.25' /></collider>";
}
var colliderList = PARAMETERS['event_tile_collider_list'];
if ( colliderList ) {
EVENT.TILE_COLLIDER_LIST = '<collider>' + JSON.parse( colliderList ) + '</collider>';
} else {
EVENT.TILE_COLLIDER_LIST = "<collider><rect x='0' y='0' width='1' height='1' /></collider>";
}
} )();
/**
* PRESETS
*/
var PRESETS;
( function() {
var presets = PARAMETERS['presets'];
if ( presets ) {
PRESETS = JSON.parse( presets );
} else {
PRESETS = [];
}
} )();
var MOVE_ROUTE = {
ALIGN_GRID: ( PARAMETERS['move_route_align_grid'] != 'false' ),
};
var INPUT_CONFIG = {
ENABLE_TOUCH_MOUSE: ( PARAMETERS['input_config_enable_touch_mouse'] != 'false' ),
GAMEPAD_MODE: parseInt( PARAMETERS['input_config_gamepad_mode'] ),
};
var PLAY_TEST = {
COLLISION_MESH_CACHING: ( PARAMETERS['play_test_collision_mesh_caching'] != 'false' ),
};
/**
* Game_System
*/
( function() {
/**
* Overrides
*/
( function() {
var Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
Game_System_initialize.call( this );
this._eventColliders = [];
this._staticMoveAlignGrid = MOVE_ROUTE.ALIGN_GRID;
this._moveAlignGrid = MOVE_ROUTE.ALIGN_GRID;
this._staticFollowerDistance = FOLLOWERS.DISTANCE;
this._followerDistance = FOLLOWERS.DISTANCE;
this._staticEnableTouchMouse = INPUT_CONFIG.ENABLE_TOUCH_MOUSE;
this._enableTouchMouse = INPUT_CONFIG.ENABLE_TOUCH_MOUSE;
};
Game_System.prototype.createColliderFromXML = function( xml ) {
return Collider.createFromXML( xml );
};
} )();
} )();
/**
* Game_Interpreter
*/
( function() {
/**
* Overrides
*/
( function() {
var Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function( command, args ) {
Game_Interpreter_pluginCommand.call( this, command, args );
if ( command === 'AltMovement' ) {
switch ( args[0] ) {
case 'collider':
this.altMovementCollider( args );
break;
case 'followers':
switch ( args[1] ) {
case 'set':
switch ( args[2] ) {
case 'distance':
$gameSystem._followerDistance = Number( args[3] );
break;
default:
var index = parseInt( args[2] );
switch ( args[3] ) {
case 'following':
if ( args[4] ) {
switch ( args[4].toLowerCase() ) {
case 'disable':
case 'off':
case 'false':
case 'no':
$gamePlayer.followers().follower( index ).setFrozen( true );
break;
case 'enable':
case 'on':
case 'true':
case 'yes':
$gamePlayer.followers().follower( index ).setFrozen( false );
break;
}
} else {
$gamePlayer.followers().follower( index ).setFrozen( false );
}
break;
}
break;
}
break;
}
break;
case 'move':
this.altMovementMoveCharacter( args );
break;
case 'move_align':
switch ( args[1] ) {
case 'set':
switch ( args[2].toLowerCase() ) {
case 'disable':
case 'off':
case 'false':
case 'no':
$gameSystem._moveAlignGrid = false;
break;
case 'enable':
case 'on':
case 'true':
case 'yes':
$gameSystem._moveAlignGrid = true;
break;
}
break;
}
break;
case 'input':
switch ( args[1] ) {
case 'touch':
case 'mouse':
switch ( args[2].toLowerCase() ) {
case 'disable':
case 'off':
case 'false':
case 'no':
$gameSystem._enableTouchMouse = false;
break;
case 'enable':
case 'on':
case 'true':
case 'yes':
$gameSystem._enableTouchMouse = true;
break;
}
break;
}
break;
}
}
};
var Game_Interpreter_updateWaitMode = Game_Interpreter.prototype.updateWaitMode;
Game_Interpreter.prototype.updateWaitMode = function() {
if ( 'target' == this._waitMode ) {
return this._character._moveTarget;
}
return Game_Interpreter_updateWaitMode.call( this );
};
} )();
/**
* Extensions
*/
( function() {
Game_Interpreter.prototype.altMovementStringArgs = function( args ) {
if(Array.isArray(args))
return args;
var str = args.join( ' ' );
var args = [];
var readingPart = false;
var part = '';
for ( var ii = 0; ii < str.length; ii++ ) {
if ( str.charAt( ii ) === ' ' && !readingPart ) {
args.push( part );
part = '';
} else {
if ( str.charAt( ii ) === '\"' ) {
readingPart = !readingPart;
}
part += str.charAt( ii );
}
}
args.push( part );
return args;
};
Game_Interpreter.prototype.altMovementCommandToDirection = function( command ) {
var gc = Game_Character;
switch ( command ) {
case gc.ROUTE_MOVE_DOWN:
return 2;
case gc.ROUTE_MOVE_LEFT:
return 4;
case gc.ROUTE_MOVE_RIGHT:
return 6;
case gc.ROUTE_MOVE_UP:
return 8;
case gc.ROUTE_MOVE_LOWER_L:
return 1;
case gc.ROUTE_MOVE_LOWER_R:
return 3;
case gc.ROUTE_MOVE_UPPER_L:
return 7;
case gc.ROUTE_MOVE_UPPER_R:
return 9;
case gc.ROUTE_MOVE_RANDOM:
return 1 + Math.randomInt( 8 );
case gc.ROUTE_MOVE_FORWARD:
return subject._direction;
case gc.ROUTE_MOVE_BACKWARD:
return subject.reverseDir( subject._direction );
default:
return 5;
}
};
Game_Interpreter.prototype.altMovementCharacterEdgeDxDy = function( subject, dx, dy ) {
var stepDistance;
var box = subject.collider().aabbox;
if ( dx && dy ) {
var xd;
if ( dx < 0 ) {
var px = subject.x + box.left;
xd = Math.floor( px ) - px;
} else {
var px = subject.x + box.right;
xd = Math.ceil( px ) - px;
}
var yd;
if ( dy < 0 ) {
var py = subject.y + box.top;
yd = Math.floor( py ) - py;
} else {
var py = subject.y + box.bottom;
yd = Math.ceil( py ) - py;
}
stepDistance = xd < yd ? xd : yd;
} else if ( dx ) {
if ( dx < 0 ) {
var px = subject.x + box.left;
stepDistance = Math.floor( px ) - px;
} else {
var px = subject.x + box.right;
stepDistance = Math.ceil( px ) - px;
}
} else {
if ( dy < 0 ) {
var py = subject.y + box.top;
stepDistance = Math.floor( py ) - py;
} else {
var py = subject.y + box.bottom;
stepDistance = Math.ceil( py ) - py;
}
}
return stepDistance;
};
Game_Interpreter.prototype.altMovementProcessMoveCommand = function( subject, command, distance, options, object ) {
$gameMap.refreshIfNeeded();
this._character = subject;
if ( options.wait ) {
this.setWaitMode( 'target' );
}
subject._moveTargetSkippable = options.skip;
subject._moveTarget = true;
if ( object ) {
var dx = object.x - subject.x;
var dy = object.y - subject.y;
var length = Math.sqrt( dx * dx + dy * dy );
dx /= length;
dy /= length;
var stepDistance;
if ( 'edge' == distance ) {
stepDistance = this.altMovementCharacterEdgeDxDy( subject, dx, dy );
} else {
stepDistance = Number( distance );
}
if ( command == Game_Character.ROUTE_MOVE_AWAY ) {
stepDistance *= -1;
}
subject._moveTargetX = subject.x + dx * stepDistance;
subject._moveTargetY = subject.y + dy * stepDistance;
} else {
var direction = this.altMovementCommandToDirection( command );
var dx = Direction.isLeft( direction ) ? -1 : ( Direction.isRight( direction ) ? 1 : 0 );
var dy = Direction.isUp( direction ) ? -1 : ( Direction.isDown( direction ) ? 1 : 0 );
var stepDistance;
if ( 'edge' == distance ) {
stepDistance = this.altMovementCharacterEdgeDxDy( subject, dx, dy );
} else {
stepDistance = Number( distance );
}
subject._moveTargetX = subject.x + dx * stepDistance;
subject._moveTargetY = subject.y + dy * stepDistance;
}
};
Game_Interpreter.prototype.altMovementMoveCharacter = function( args ) {
args = this.altMovementStringArgs( args );
var subject = this.altMovementGetTargetCharacter( args[1] );
var command = this.altMovementGetMoveCommand( args[2] );
switch ( command ) {
case Game_Character.ROUTE_MOVE_AWAY:
case Game_Character.ROUTE_MOVE_TOWARD:
var object = this.altMovementGetTargetCharacter( args[3] );
var options = {
wait: args[5] == 'wait' || args[6] == 'wait',
skip: args[5] == 'skip' || args[6] == 'skip' || args[5] == 'skippable' || args[6] == 'skippable',
};
this.altMovementProcessMoveCommand( subject, command, args[4], options, object );
break;
default:
var options = {
wait: args[4] == 'wait' || args[5] == 'wait',
skip: args[4] == 'skip' || args[5] == 'skip' || args[4] == 'skippable' || args[5] == 'skippable',
};
this.altMovementProcessMoveCommand( subject, command, args[3], options );
break;
}
};
Game_Interpreter.prototype.altMovementCollider = function( args ) {
args = this.altMovementStringArgs( args );
switch ( args[1] ) {
case 'set':
this.altMovementColliderSet( args );
break;
}
};
Game_Interpreter.prototype.altMovementColliderSet = function( args ) {
var target = this.altMovementGetTargetCharacter( args[2] );
if ( !target ) {
return;
}
var presetIndex = Number( args[3] );
if ( isNaN( presetIndex ) ) {
target.setCollider( Collider.getPreset( args[3].substring( 1, args[3].length - 1 ) ) );
target._hasCustomCollider = true;
} else {
target.setCollider( Collider.getPreset( presetIndex ) );
target._hasCustomCollider = true;
}
};
Game_Interpreter.prototype.altMovementGetMoveCommand = function( cmdStr ) {
switch ( cmdStr ) {
case 'down_left': case 'bottom_left': case 'lower_left': case 'lower_l':
case 'left_down': case 'left_bottom': case 'left_lower': case 'l_lower':
case 'south_west': case 'west_south': case '1': case '↙':
return Game_Character.ROUTE_MOVE_LOWER_L;
case 'down': case 'bottom': case 'lower': case 'south': case '2': case '↓':
return Game_Character.ROUTE_MOVE_DOWN;
case 'down_right': case 'bottom_right': case 'lower_right': case 'lower_r':
case 'right_down': case 'right_bottom': case 'right_lower': case 'r_lower':
case 'south_east': case 'east_south': case '3': case '↘':
return Game_Character.ROUTE_MOVE_LOWER_R;
case 'left': case 'west': case '4': case '←':
return Game_Character.ROUTE_MOVE_LEFT;
case 'right': case 'east': case '6': case '→':
return Game_Character.ROUTE_MOVE_RIGHT;
case 'up_left': case 'top_left': case 'upper_left': case 'upper_l':
case 'left_up': case 'left_top': case 'left_upper': case 'l_upper':
case 'north_west': case 'west_north': case '7': case '↖':
return Game_Character.ROUTE_MOVE_UPPER_L;
case 'up': case 'top': case 'upper': case 'north': case '8': case '↑':
return Game_Character.ROUTE_MOVE_UP;
case 'up_right': case 'top_right': case 'upper_right': case 'upper_r':
case 'right_up': case 'right_top': case 'right_upper': case 'r_upper':
case 'north_east': case 'east_north': case '9': case '↗':
return Game_Character.ROUTE_MOVE_UPPER_R;
case 'away': case 'away_from':
return Game_Character.ROUTE_MOVE_AWAY;
case 'toward': case 'towards': case 'toward_to':
return Game_Character.ROUTE_MOVE_TOWARD;
case 'forward': case 'forwards':
return Game_Character.ROUTE_MOVE_FORWARD;
case 'backward': case 'backwards': case 'back':
return Game_Character.ROUTE_MOVE_BACKWARD;
case 'random': case 'randomly':
return Game_Character.ROUTE_MOVE_RANDOM;
default:
return null;
}
};
Game_Interpreter.prototype.altMovementGetTargetCharacter = function( target ) {
if ( target.startsWith( '\"' ) && target.endsWith( '\"' ) ) {
// Event name
var eventName = target.substring( 1, target.length - 1 );
for ( var ii = 0; ii < $dataMap.events.length; ii++ ) {
if ( $dataMap.events[ii] && $dataMap.events[ii].name === eventName ) {
return $gameMap.event( $dataMap.events[ii].id );
}
}
} else {
// System name
switch ( target ) {
case 'this':
var eventId = this._eventId;
// This Event ID #
return $gameMap.event( eventId );
case 'player':
return $gamePlayer;
case 'boat':
return $gameMap.boat();
case 'ship':
return $gameMap.ship();
case 'airship':
return $gameMap.airship();
default:
if ( target.startsWith( 'follower') ) {
var index = Number( target.substring( 8 ) );
// Follower index
return $gamePlayer.followers().follower( index );
} else {
var eventId = Number( target );
// Event ID #
return $gameMap.event( eventId );
}
}
}
return null;
};
} )();
} )();
/**
* Game_CharacterBase
*/
( function() {
/**
* Overrides
*/
( function() {
var Game_CharacterBase_update = Game_CharacterBase.prototype.update;
Game_CharacterBase.prototype.update = function() {
if ( this._moveTarget ) {
var dx = $gameMap.directionX( this._x, this._moveTargetX );
var dy = $gameMap.directionY( this._y, this._moveTargetY );
var length = Math.sqrt( dx * dx + dy * dy );
if ( length <= this.stepDistance ) {
this._moveTarget = false;
this._moveTargetSkippable = false;
this.setDirectionFix( this._wasDirectionFixed );
this._x = $gameMap.roundX( this._moveTargetX );
this._y = $gameMap.roundY( this._moveTargetY );
} else {
dx /= length;
dy /= length;
this.moveVector( dx * this.stepDistance, dy * this.stepDistance );
if ( !this.isMovementSucceeded() ) {
if ( this._moveTargetSkippable || ( !!this._moveRoute && this._moveRoute.skippable ) ) {
this._moveTarget = false;
this._moveTargetSkippable = false;
this.setDirectionFix( this._wasDirectionFixed );
}
}
}
}
Game_CharacterBase_update.call( this );
};
Game_CharacterBase.prototype.isOnLadder = function() {
var aabbox = this.collider().aabbox;
if ( aabbox.left >= 0 && aabbox.right <= 1 ) {
// To use ladder the bounding box must fit on a tile
return false;
}
// If middle is on ladder
if ( $gameMap.isLadder( $gameMap.roundX( this._x + ( aabbox.left + aabbox.right ) / 2 ), $gameMap.roundY( this._y + ( aabbox.top + aabbox.bottom ) / 2 ) ) ) {
// If bottom middle is on ladder
if ( $gameMap.isLadder( $gameMap.roundX( this._x + ( aabbox.left + aabbox.right ) / 2 ), $gameMap.roundY( this._y + aabbox.bottom ) ) ) {
return true;
}
}
return false;
};
Game_CharacterBase.prototype.moveStraight = function( d ) {
var vy = Direction.isUp( d ) ? -1 : ( Direction.isDown( d ) ? 1 : 0 );
var vx = Direction.isLeft( d ) ? -1 : ( Direction.isRight( d ) ? 1 : 0 );
if ( this._circularMovement ) {
var length = Math.sqrt( vx * vx + vy * vy );
vx /= length;
vy /= length;
}
this.moveVector( vx * this.stepDistance, vy * this.stepDistance );
};
Game_CharacterBase.prototype.moveDiagonally = function( horz, vert ) {
var vy = Direction.isUp( vert ) ? -1 : ( Direction.isDown( vert ) ? 1 : 0 );
var vx = Direction.isLeft( horz ) ? -1 : ( Direction.isRight( horz ) ? 1 : 0 );
if ( this._circularMovement ) {
var length = Math.sqrt( vx * vx + vy * vy );
vx /= length;
vy /= length;
}
this.moveVector( vx * this.stepDistance, vy * this.stepDistance );
};
var Game_CharacterBase_isMoving = Game_CharacterBase.prototype.isMoving;
Game_CharacterBase.prototype.isMoving = function() {
return Game_CharacterBase_isMoving.call( this ) || this._isMoving;
};
var Game_CharacterBase_updateAnimation = Game_CharacterBase.prototype.updateAnimation;
Game_CharacterBase.prototype.updateAnimation = function() {
Game_CharacterBase_updateAnimation.call( this );
this._wasMoving = this._isMoving;
this._isMoving = this._x !== this._realX || this._y !== this._realY;
if ( !this._isMoving ) {
this.refreshBushDepth();
}
};
Game_CharacterBase.prototype.isOnBush = function() {
var aabbox = this.collider().aabbox;
// If middle is in bush
if ( $gameMap.isBush( $gameMap.roundX( this._x + ( aabbox.left + aabbox.right ) / 2 ), $gameMap.roundY( this._y + ( aabbox.top + aabbox.bottom ) / 2 ) ) ) {
// If bottom middle is in bush
if ( $gameMap.isBush( $gameMap.roundX( this._x + ( aabbox.left + aabbox.right ) / 2 ), $gameMap.roundY( this._y + aabbox.bottom ) ) ) {
return true;
}
}
return false;
};
Game_CharacterBase.prototype.canPass = function( x, y, d ) {
if ( this.isThrough() || this.isDebugThrough() ) {
return true;
}
var x2 = $gameMap.roundXWithDirection( x, d );
var y2 = $gameMap.roundYWithDirection( y, d );
if ( !$gameMap.canWalk( this, x2, y2 ) ) {
return false;
}
return true;
};
Game_CharacterBase.prototype.canPassDiagonally = function( x, y, horz, vert ) {
if ( this.isThrough() || this.isDebugThrough() ) {
return true;
}
var x2 = $gameMap.roundXWithDirection( x, horz );
var y2 = $gameMap.roundYWithDirection( y, vert );
if ( !$gameMap.canWalk( this, x2, y2 ) ) {
return false;
}
return true;
};
var Game_CharacterBase_setDirection = Game_CharacterBase.prototype.setDirection;
Game_CharacterBase.prototype.setDirection = function( d ) {
Game_CharacterBase_setDirection.call( this, d );
this._direction8 = this._direction;
};
var Game_CharacterBase_screenX = Game_CharacterBase.prototype.screenX;
Game_CharacterBase.prototype.screenX = function() {
var round = Math.round;
Math.round = Math.floor;
var val = Game_CharacterBase_screenX.call( this );
Math.round = round;
return val;
};
var Game_CharacterBase_screenY = Game_CharacterBase.prototype.screenY;
Game_CharacterBase.prototype.screenY = function() {
var round = Math.round;
Math.round = Math.floor;
var val = Game_CharacterBase_screenY.call( this );
Math.round = round;
return val;
};
} )();
/**
* Extensions
*/
( function() {
Object.defineProperties( Game_CharacterBase.prototype, {
stepDistance: { get: function() { return this.distancePerFrame(); }, configurable: true },
} );
Game_CharacterBase.prototype.collidableWith = function( character ) {
return !!character
&& character !== this
&& character.isNormalPriority()
&& this.isNormalPriority()
&& !this.isThrough()
&& ( !character.isVisible ? true : character.isVisible() )
&& ( !this.vehicle ? true : this.vehicle() !== character )
&& ( !this.followers ? true : !this.followers().contains( character ) )
&& ( character instanceof Game_Follower ? true : !character.isThrough() )
&& !( this instanceof Game_Follower ? character instanceof Game_Follower : false )
&& !( this instanceof Game_Follower ? character instanceof Game_Player : false )
&& !( this instanceof Game_Vehicle ? character instanceof Game_Player : false )
&& !( this instanceof Game_Vehicle ? character instanceof Game_Follower : false )
&& ( character instanceof Game_Vehicle ? character._mapId === $gameMap.mapId() : true );
}
Game_CharacterBase.prototype.moveVectorCharacters = function( owner, collider, characters, loopMap, move ) {
characters.forEach( function( character ) {
var characterX = character._x;
var characterY = character._y;
if ( loopMap[character] == 1 ) { characterX += $gameMap.width(); }
else if ( loopMap[character] == 2 ) { characterX -= $gameMap.width(); }
else if ( loopMap[character] == 3 ) { characterY += $gameMap.height(); }
else if ( loopMap[character] == 4 ) { characterY -= $gameMap.height(); }
else if ( loopMap[character] == 5 ) { characterX += $gameMap.width(); characterY += $gameMap.height(); }
else if ( loopMap[character] == 6 ) { characterX -= $gameMap.width(); characterY += $gameMap.height(); }
else if ( loopMap[character] == 7 ) { characterX += $gameMap.width(); characterY -= $gameMap.height(); }
else if ( loopMap[character] == 8 ) { characterX -= $gameMap.width(); characterY -= $gameMap.height(); }
move = Collider.move( owner._x, owner._y, collider, characterX, characterY, character.collider(), move );
if ( move.x === 0 && move.y === 0 ) {
return;
}
} );
};
Game_CharacterBase.prototype.moveVectorMap = function( owner, collider, bboxTests, move, vx, vy ) {
for ( var ii = 0; ii < bboxTests.length; ii++ ) {
var offsetX = 0;
var offsetY = 0;
if ( bboxTests[ii].type == 1 ) { offsetX += $gameMap.width(); }
else if ( bboxTests[ii].type == 2 ) { offsetX -= $gameMap.width(); }
else if ( bboxTests[ii].type == 3 ) { offsetY += $gameMap.height(); }
else if ( bboxTests[ii].type == 4 ) { offsetY -= $gameMap.height(); }
else if ( bboxTests[ii].type == 5 ) { offsetX += $gameMap.width(); offsetY += $gameMap.height(); }
else if ( bboxTests[ii].type == 6 ) { offsetX -= $gameMap.width(); offsetY += $gameMap.height(); }
else if ( bboxTests[ii].type == 7 ) { offsetX += $gameMap.width(); offsetY -= $gameMap.height(); }
else if ( bboxTests[ii].type == 8 ) { offsetX -= $gameMap.width(); offsetY -= $gameMap.height(); }
var mapColliders = Collider.polygonsWithinColliderList( bboxTests[ii].x + vx, bboxTests[ii].y + vy, bboxTests[ii].aabbox, 0, 0, $gameMap.collisionMesh( this._collisionType ) );
if ( mapColliders.length > 0 ) {
if ( move.x !== 0 ) {
var sigMove = { x: move.x, y: 0 };
mapColliders.forEach( function( mapCollider ) {
sigMove = Collider.move( owner._x, owner._y, collider, offsetX, offsetY, mapCollider, sigMove );
} );
move.x = sigMove.x;
}
mapColliders.forEach( function( mapCollider ) {
move = Collider.move( owner._x, owner._y, collider, offsetX, offsetY, mapCollider, move );
} );
}
}
};
Game_CharacterBase.prototype.moveVector = function( vx, vy ) {
var move;
var characterCollided = false;
if ( this.isThrough() || this.isDebugThrough() ) {
var aabbox = this.collider().aabbox;
move = { x: 0, y: 0 };
if ( !$gameMap.isLoopHorizontal() && this._x + vx + aabbox.left < 0 ) {
move.x = 0 - ( this._x + aabbox.left );
} else if ( !$gameMap.isLoopHorizontal() && this._x + vx + aabbox.right > $gameMap.width() ) {
move.x = $gameMap.width() - ( this._x + aabbox.right );
} else {
move.x = vx;
}
if ( !$gameMap.isLoopVertical() && this._y + vy + aabbox.top < 0 ) {
move.y = 0 - ( this._y + aabbox.top );
} else if ( !$gameMap.isLoopVertical() && this._y + vy + aabbox.bottom > $gameMap.height() ) {
move.y = $gameMap.height() - ( this._y + aabbox.bottom );
} else {
move.y = vy;
}
} else {
var owner = this;
var collider = owner.collider();
var bboxTests = $gameMap.getAABBoxTests( this, vx, vy );
// Gather any solid characters within the movement bounding box
var loopMap = {};
var characters = $gameMap.characters().filter( function( character ) {
if ( owner === $gamePlayer && owner.followers().contains( character ) ) {
return false;
}
if ( owner.collidableWith( character ) ) {
for ( var ii = 0; ii < bboxTests.length; ii++ ) {
if ( Collider.aabboxCheck( bboxTests[ii].x, bboxTests[ii].y, bboxTests[ii].aabbox, character._x, character._y, character.collider().aabbox, vx, vy ) ) {
loopMap[character] = bboxTests[ii].type;
return true;
}
}
}
return false;
} );
move = { x: vx, y: vy };
// Test collision with characters
this.moveVectorCharacters( owner, collider, characters, loopMap, move );
if ( move.x !== vx || move.y !== vy ) {
// Collided with character, disable direction change
characterCollided = true;
}
// Test collision with map
this.moveVectorMap( owner, collider, bboxTests, move, vx, vy );
}
// Resolve too much precision
move.x = Math.floor( move.x * Collider.PRECISION ) / Collider.PRECISION;
move.y = Math.floor( move.y * Collider.PRECISION ) / Collider.PRECISION;
// Special ladder behaviour
if ( this.isOnLadder() && ( this.isInAirship ? !this.isInAirship() : true ) ) {
var tileX = Math.round( this._x );
if ( !$gameMap.isPassable( tileX, this._y + move.y, Direction.LEFT ) ) {
if ( !$gameMap.isPassable( tileX, this._y + move.y, Direction.RIGHT ) ) {
move.x = tileX - this._x;
}
}
}
var length = Math.sqrt( move.x * move.x + move.y * move.y );
if ( length > Collider.I_PRECISION ) {
this._x = $gameMap.roundX( this._x + move.x );
this._y = $gameMap.roundY( this._y + move.y );
this._realX = this._x - move.x;
this._realY = this._y - move.y;
this.setMovementSuccess( true );
if ( characterCollided ) {
this.setDirectionVector( vx, vy );
} else {
this.setDirectionVector( move.x, move.y );
}
this.increaseSteps();
this._isMoving = true;
this.checkEventTriggerTouchFrontVector( move.x, move.y );
} else {
this.setMovementSuccess( false );
this.setDirectionVector( vx, vy );
this._isMoving = false;
this.checkEventTriggerTouchFrontVector( vx, vy );
}
};
Game_CharacterBase.prototype.setDirectionVector = function( vx, vy ) {
if ( this.isDirectionFixed() ) {
return;
}
var direction = Math.atan2( vy, vx ) / Math.PI;
var direct = false;
if ( direction >= -0.2 && direction < 0.2 ) {
// East
this.setDirection( Direction.RIGHT );
direct = true;
} else if ( direction >= 0.3 && direction < 0.7 ) {
// South
this.setDirection( Direction.DOWN );
direct = true;
} else if ( direction >= -0.7 && direction < -0.3 ) {
// North
this.setDirection( Direction.UP );
direct = true;
} else if ( direction >= -1.2 && direction < -0.8 ) {
// West
this.setDirection( Direction.LEFT );
direct = true;
} else if ( direction >= 0.8 && direction < 1.2 ) {
// West
this.setDirection( Direction.LEFT );
direct = true;
}
if ( !direct ) {
var dx = vx > 0 ? Direction.RIGHT : ( vx ? Direction.LEFT : 0 );
var dy = vy > 0 ? Direction.DOWN : ( vy ? Direction.UP : 0 );
if ( dx && dy ) {
if ( this._direction === this.reverseDir( dx ) ) {
this.setDirection( dx );
} else if ( this._direction === this.reverseDir( dy ) ) {
this.setDirection( dy );
} else {
this.resetStopCount();
}
} else {
this.setDirection( dx || dy );
}
}
var direction8 = Math.round( ( direction + 1 ) * 4 ) % 8; // 8 directions
switch ( direction8 ) {
case 0:
this._direction8 = Direction.LEFT;
break;
case 1:
this._direction8 = Direction.UP_LEFT;
break;
case 2:
this._direction8 = Direction.UP;
break;
case 3:
this._direction8 = Direction.UP_RIGHT;
break;
case 4:
this._direction8 = Direction.RIGHT;
break;
case 5:
this._direction8 = Direction.DOWN_RIGHT;
break;
case 6:
this._direction8 = Direction.DOWN;
break;
case 7:
this._direction8 = Direction.DOWN_LEFT;
break;
}
};
Game_CharacterBase.prototype.checkEventTriggerTouchFrontVector = function( vx, vy ) {
this.checkEventTriggerTouch( this._x + vx, this._y + vy );
};
Game_CharacterBase.prototype.align = function() {
this._x = this._x | 0;
this._y = this._y | 0;
};
Game_CharacterBase.prototype.collider = function() {
return this._collider || Collider.sharedTile();
};
Game_CharacterBase.prototype.setCollider = function( collider ) {
this._collider = collider;
};
Game_CharacterBase.prototype.direction8 = function() {
return this._direction8;
};
} )();
} )();
/**
* Game_Character
*/
( function() {
/**
* Overrides
*/
( function() {
Game_Character.prototype.updateRoutineMove = function() {
if ( this._moveTarget ) {
var moveRoute = this._moveRoute;
if ( !moveRoute.skippable || this._wasMoving ) {
return;
}
}
if ( this._waitCount > 0 ) {
this._waitCount--;
} else {
this.setMovementSuccess( true );
var command = this._moveRoute.list[this._moveRouteIndex];
if ( command ) {
this.processMoveCommand( command );
this.advanceMoveRouteIndex();
}
}
};
Game_Character.prototype.moveRandom = function() {
if ( this._moveTarget ) {
return;
}
var d = 1 + Math.randomInt( 8 );
var vx = Direction.isLeft( d ) ? -1 : ( Direction.isRight( d ) ? 1 : 0 );
var vy = Direction.isUp( d ) ? -1 : ( Direction.isDown( d ) ? 1 : 0 );
this.setDirectionVector( vx, vy );
this._moveTarget = true;
this._moveTargetSkippable = true;
this._moveTargetX = Math.round( this.x + vx );
this._moveTargetY = Math.round( this.y + vy );
};
Game_Character.prototype.moveTowardCharacter = function( character ) {
var vx = character.x - this.x;
var vy = character.y - this.y;
var length = Math.sqrt( vx * vx + vy * vy );
if ( length > this.stepDistance ) {
this.setDirectionVector( vx, vy );
vx /= length;
vy /= length;
this._moveTarget = true;
this._moveTargetSkippable = true;
this._moveTargetX = Math.round( this.x + vx );
this._moveTargetY = Math.round( this.y + vy );
}
};
Game_Character.prototype.moveAwayFromCharacter = function( character ) {
var vx = character.x - this.x;
var vy = character.y - this.y;
var length = Math.sqrt( vx * vx + vy * vy );
this.setDirectionVector( -vx, -vy );
vx /= length;
vy /= length;
this._moveTarget = true;
this._moveTargetSkippable = true;
this._moveTargetX = Math.round( this.x - vx );
this._moveTargetY = Math.round( this.y - vy );
};
var Game_Character_processMoveCommand = Game_Character.prototype.processMoveCommand;
Game_Character.prototype.processMoveCommand = function( command ) {
var gc = Game_Character;
var params = command.parameters;
switch ( command.code ) {
case gc.ROUTE_MOVE_DOWN:
this._moveTarget = true;
this._moveTargetX = ( this._x );
this._moveTargetY = ( this._y + 1 );
break;
case gc.ROUTE_MOVE_LEFT:
this._moveTarget = true;
this._moveTargetX = ( this._x - 1 );
this._moveTargetY = ( this._y );
break;
case gc.ROUTE_MOVE_RIGHT:
this._moveTarget = true;
this._moveTargetX = ( this._x + 1 );
this._moveTargetY = ( this._y );
break;
case gc.ROUTE_MOVE_UP:
this._moveTarget = true;
this._moveTargetX = ( this._x );
this._moveTargetY = ( this._y - 1 );
break;
case gc.ROUTE_MOVE_LOWER_L:
this._moveTarget = true;
this._moveTargetX = ( this._x - 1 );
this._moveTargetY = ( this._y + 1 );
break;
case gc.ROUTE_MOVE_LOWER_R:
this._moveTarget = true;
this._moveTargetX = ( this._x + 1 );
this._moveTargetY = ( this._y + 1 );
break;
case gc.ROUTE_MOVE_UPPER_L:
this._moveTarget = true;
this._moveTargetX = ( this._x - 1 );
this._moveTargetY = ( this._y - 1 );
break;
case gc.ROUTE_MOVE_UPPER_R:
this._moveTarget = true;
this._moveTargetX = ( this._x + 1 );
this._moveTargetY = ( this._y - 1 );
break;
case gc.ROUTE_MOVE_FORWARD:
this._wasDirectionFixed = this.isDirectionFixed();
this.setDirectionFix( true );
var vx = Direction.isLeft( this._direction ) ? -1 : ( Direction.isRight( this._direction ) ? 1 : 0 );
var vy = Direction.isUp( this._direction ) ? -1 : ( Direction.isDown( this._direction ) ? 1 : 0 );
this._moveTarget = true;
this._moveTargetX = ( this._x + vx );
this._moveTargetY = ( this._y + vy );
break;
case gc.ROUTE_MOVE_BACKWARD:
this._wasDirectionFixed = this.isDirectionFixed();
this.setDirectionFix( true );
var vx = Direction.isLeft( this._direction ) ? -1 : ( Direction.isRight( this._direction ) ? 1 : 0 );
var vy = Direction.isUp( this._direction ) ? -1 : ( Direction.isDown( this._direction ) ? 1 : 0 );
this._moveTarget = true;
this._moveTargetX = ( this._x - vx );
this._moveTargetY = ( this._y - vy );
break;
default:
Game_Character_processMoveCommand.call( this, command );
break;
}
if ( $gameSystem._staticMoveAlignGrid !== MOVE_ROUTE.ALIGN_GRID ) {
$gameSystem._staticMoveAlignGrid = MOVE_ROUTE.ALIGN_GRID;
$gameSystem._moveAlignGrid = MOVE_ROUTE.ALIGN_GRID;
}
if ( this._moveTarget && $gameSystem._moveAlignGrid ) {
this._moveTargetX = Math.round( this._moveTargetX );
this._moveTargetY = Math.round( this._moveTargetY );
}
};
} )();
} )();
/**
* Game_Player
*/
( function() {
/**
* Overrides
*/
( function() {
var Game_Player_initMembers = Game_Player.prototype.initMembers;
Game_Player.prototype.initMembers = function() {
Game_Player_initMembers.call(this);
this._collider = Collider.createFromXML( PLAYER.COLLIDER_LIST );
this._circularMovement = PLAYER.CIRCULAR_MOVEMENT;
};
Game_Player.prototype.checkEventTriggerTouch = Game_CharacterBase.prototype.checkEventTriggerTouch;
var Game_Player_encounterProgressValue = Game_Player.prototype.encounterProgressValue;
Game_Player.prototype.encounterProgressValue = function() {
return this.stepDistance * Game_Player_encounterProgressValue.call( this );
};
var Game_Player_clearTransferInfo = Game_Player.prototype.clearTransferInfo;
Game_Player.prototype.clearTransferInfo = function() {
Game_Player_clearTransferInfo.call( this );
this._moveTarget = false;
this._moveTargetSkippable = false;
};
Game_Player.prototype.update = function( sceneActive ) {
var lastScrolledX = this.scrolledX();
var lastScrolledY = this.scrolledY();
var wasMoving = this._wasMoving;
this.updateDashing();
if ( sceneActive ) {
this.moveByInput();
}
Game_Character.prototype.update.call( this );
this.updateScroll( lastScrolledX, lastScrolledY );
this.updateVehicle();
if ( !this._isMoving ) {
this.updateNonmoving( wasMoving, sceneActive );
}
this._followers.update();
};
Game_Player.prototype.getInputDirection = function() {
return Input.dir8;
};
Game_Player.prototype.moveByInput = function() {
if ( $gameSystem._staticEnableTouchMouse != INPUT_CONFIG.ENABLE_TOUCH_MOUSE ) {
$gameSystem._staticEnableTouchMouse = INPUT_CONFIG.ENABLE_TOUCH_MOUSE;
$gameSystem._enableTouchMouse = INPUT_CONFIG.ENABLE_TOUCH_MOUSE;
}
if ( this._moveTarget ) {
this._touchTarget = null;
}
if ( !this.isMoving() && this.canMove() ) {
if ( navigator.getGamepads ) {
// Gamepad movement
var gamepads = navigator.getGamepads();
var didMove = false;
var didTurn = false;
if ( gamepads ) {
for ( var ii = 0; ii < gamepads.length; ii++ ) {
var gamepad = gamepads[ii];
if ( gamepad && gamepad.connected ) {
if ( !didMove ) {
if ( INPUT_CONFIG.GAMEPAD_MODE & 0x2 ) {
var vy = gamepad.axes[1];
var vx = gamepad.axes[0];
var length = Math.sqrt( vy * vy + vx * vx );
if ( length > GAME_PAD_THRESHOLD ) {
if ( length - GAME_PAD_THRESHOLD > GAME_PAD_LIMIT ) {
vx /= length;
vy /= length;
}
if ( this._circularMovement ) {
this.moveVector( vx * this.stepDistance, vy * this.stepDistance );
} else {
var vector = Direction.normalizeSquare( vx, vy );
this.moveVector( vector.x * this.stepDistance, vector.y * this.stepDistance );
}
didMove = true;
}
} else {
didMove = true;
}
}
if ( !didTurn && ( INPUT_CONFIG.GAMEPAD_MODE & 0x1 ) ) {
var vy = gamepad.axes[3];
var vx = gamepad.axes[2];
var length = Math.sqrt( vy * vy + vx * vx );
if ( length > GAME_PAD_THRESHOLD ) {
this.setDirectionVector( vx, vy );
didTurn = true;
}
}
}
}
}
if ( didMove ) {
this._touchTarget = null;
return;
}
}
var direction = this.getInputDirection();
if ( direction > 0 ) {
// Regular movement
this.executeMove( direction );
this._touchTarget = null;
} else if ( $gameSystem._enableTouchMouse && $gameTemp.isDestinationValid() ) {
// Touch movement
var characterTarget = null;
var touchedCharacters = $gameMap.getCharactersUnderPoint( $gameTemp.destinationX(), $gameTemp.destinationY() ).filter( function( character ) {
// Filter out events that player cannot reach
return !( character._eventId && !character.isNormalPriority() );
} );
if ( this.isInVehicle() ) {
// In vehicle
if ( touchedCharacters.contains( $gamePlayer.vehicle() ) ) {
// Get off vehicle
this.getOffVehicle();
}
} else {
// Check if we're touching an interactable
if ( touchedCharacters.contains( $gameMap.airship() ) && $gameMap.airship()._mapId === $gameMap.mapId() ) {
characterTarget = $gameMap.airship();
} else if ( touchedCharacters.contains( $gameMap.ship() ) && $gameMap.ship()._mapId === $gameMap.mapId() ) {
characterTarget = $gameMap.ship();
} else if ( touchedCharacters.contains( $gameMap.boat() ) && $gameMap.boat()._mapId === $gameMap.mapId() ) {
characterTarget = $gameMap.boat();
} else if ( touchedCharacters.length === 1 && touchedCharacters[0] === $gamePlayer ) {
// Only touched player, action time
if ( !this.getOnVehicle() ) {
this.checkEventTriggerHere( [0] );
}
characterTarget = $gamePlayer;
} else if ( this.canStartLocalEvents() ) {
// Only care about events now
touchedCharacters = touchedCharacters.filter( function( character ) {
return !!character._eventId && character._trigger === 0;
} );
if ( touchedCharacters.length ) {
// Move toward character
characterTarget = touchedCharacters[0];
}
}
}
// Move toward destination
if ( !characterTarget ) {
this._touchTarget = new Point( $gameTemp.destinationX() - 0.5, $gameTemp.destinationY() - 0.5 );
} else {
this._touchTarget = characterTarget;
}
$gameTemp.clearDestination();
}
if ( this._touchTarget ) {
var dx = $gameMap.directionX( this._x, this._touchTarget.x );
var dy = $gameMap.directionY( this._y, this._touchTarget.y );
var length = Math.sqrt( dx * dx + dy * dy );
if ( length <= this.stepDistance ) {
this._touchTarget = null;
} else {
dx /= length;
dy /= length;
if ( this._circularMovement ) {
this.moveVector( dx * this.stepDistance, dy * this.stepDistance );
} else {
var vector = Direction.normalizeSquare( dx, dy );
this.moveVector( vector.x * this.stepDistance, vector.y * this.stepDistance );
}
if ( Math.abs( dx ) > Math.abs( dy ) ) {
this.setDirectionVector( dx, 0 );
} else {
this.setDirectionVector( 0, dy );
}
if ( this.isOnLadder() ) {
this.setDirection( 8 );
}
// Can't move any more, so stop walking
if ( !this.isMovementSucceeded() ) {
var collider = this._touchTarget.collider ? this._touchTarget.collider() : null;
if ( collider ) {
// Touching a character, check if we've reached it
var rx = dx * this.stepDistance;
var ry = dy * this.stepDistance;
if ( Collider.intersect( this._touchTarget.x, this._touchTarget.y, collider, this._x + rx, this._y + ry, this.collider() ) ) {
var vehicle;
if ( !!this._touchTarget._eventId ) {
this._touchTarget.start();
} else if ( this._touchTarget === $gameMap.airship() ) {
vehicle = $gameMap.airship();
this._vehicleType = 'airship';
this._collisionType = CollisionMesh.AIRSHIP;
} else if ( this._touchTarget === $gameMap.ship() ) {
vehicle = $gameMap.ship();
this._vehicleType = 'ship';
this._collisionType = CollisionMesh.SHIP;
} else if ( this._touchTarget === $gameMap.boat() ) {
vehicle = $gameMap.boat();
this._vehicleType = 'boat';
this._collisionType = CollisionMesh.BOAT;
}
if ( vehicle ) {
this._vehicleGettingOn = true;
vehicle._passengerCollider = this.collider();
this._collider = vehicle.collider();
var dx = $gameMap.directionX( this._x, vehicle._x );
var dy = $gameMap.directionY( this._y, vehicle._y );
var wasThrough = this.isThrough();
this.setThrough( true );
this.moveVector( dx, dy );
this.setThrough( wasThrough );
this.gatherFollowers();
}
} else if ( !!this._touchTarget ) {
// Check if our target can only be reached by action
if ( !this.getOnVehicle() ) {
this.checkEventTriggerThere( [0] );
}
}
}
this._touchTarget = null;
}
}
}
}
};
Game_Player.prototype.checkEventTriggerHere = function( triggers ) {
if ( this.canStartLocalEvents() ) {
var collider = this.collider();
var bboxTests = $gameMap.getAABBoxTests( this );
var player = this;
var vx = Direction.isLeft( this._direction ) ? -this.stepDistance : ( Direction.isRight( this._direction ) ? this.stepDistance : 0 );
var vy = Direction.isUp( this._direction ) ? -this.stepDistance : ( Direction.isDown( this._direction ) ? this.stepDistance : 0 );
// Gather any solid characters within the "here" bounding box
var loopMap = {};
var events = $gameMap.events().filter( function( event ) {
for ( var ii = 0; ii < bboxTests.length; ii++ ) {
if ( event.isTriggerIn( triggers ) ) {
if ( event.isNormalPriority() ) {
if ( Collider.aabboxCheck( bboxTests[ii].x + vx, bboxTests[ii].y + vy, bboxTests[ii].aabbox, event._x, event._y, event.collider().aabbox ) ) {
loopMap[event] = bboxTests[ii].type;
return true;
}
} else {
if ( Collider.aabboxCheck( bboxTests[ii].x, bboxTests[ii].y, bboxTests[ii].aabbox, event._x, event._y, event.collider().aabbox ) ) {
loopMap[event] = bboxTests[ii].type;
return true;
}
}
}
}
return false;
} );
// Test collision with characters
for ( var ii = 0; ii < events.length; ii++ ) {
var entryX = events[ii]._x;
var entryY = events[ii]._y;
if ( loopMap[events[ii]] == 1 ) { entryX += $gameMap.width(); }
else if ( loopMap[events[ii]] == 2 ) { entryX -= $gameMap.width(); }
else if ( loopMap[events[ii]] == 3 ) { entryY += $gameMap.height(); }
else if ( loopMap[events[ii]] == 4 ) { entryY -= $gameMap.height(); }
else if ( loopMap[events[ii]] == 5 ) { entryX += $gameMap.width(); entryY += $gameMap.height(); }
else if ( loopMap[events[ii]] == 6 ) { entryX -= $gameMap.width(); entryY += $gameMap.height(); }
else if ( loopMap[events[ii]] == 7 ) { entryX += $gameMap.width(); entryY -= $gameMap.height(); }
else if ( loopMap[events[ii]] == 8 ) { entryX -= $gameMap.width(); entryY -= $gameMap.height(); }
if ( events[ii].isNormalPriority() && Collider.intersect( this._x + vx, this._y + vy, collider, entryX, entryY, events[ii].collider() ) ) {
// Normal priority player-touch/event-touch
events[ii].start();
} else if ( events[ii]._trigger === 2 ) {
// Event touch is encasing
if ( Collider.encase( entryX, entryY, events[ii].collider(), this._x, this._y, collider ) || Collider.encase( this._x, this._y, collider, entryX, entryY, events[ii].collider() ) ) {
events[ii].start();
}
} else if ( Collider.intersect( this._x, this._y, collider, entryX, entryY, events[ii].collider() ) ) {
events[ii].start();
}
}
}
};
Game_Player.prototype.checkEventTriggerThere = function( triggers ) {
if ( this.canStartLocalEvents() ) {
var vx = Direction.isLeft( this._direction ) ? -this.actionWidth() : ( Direction.isRight( this._direction ) ? this.actionWidth() : 0 );
var vy = Direction.isUp( this._direction ) ? -this.actionHeight() : ( Direction.isDown( this._direction ) ? this.actionHeight() : 0 );
var collider = this.collider();
var bboxTests = $gameMap.getAABBoxTests( this, vx, vy );
var player = this;
// Gather any solid characters within the "there" bounding box
var loopMap = {};
var events = $gameMap.events().filter( function( event ) {
for ( var ii = 0; ii < bboxTests.length; ii++ ) {
if ( event.isTriggerIn( triggers ) && event.isNormalPriority() && Collider.aabboxCheck( bboxTests[ii].x, bboxTests[ii].y, bboxTests[ii].aabbox, event._x, event._y, event.collider().aabbox ) ) {
loopMap[event] = bboxTests[ii].type;
return true;
}
}
return false;
} );
// Test collision with characters
for ( var ii = 0; ii < events.length; ii++ ) {
var entryX = events[ii]._x;
var entryY = events[ii]._y;
if ( loopMap[events[ii]] == 1 ) { entryX += $gameMap.width(); }
else if ( loopMap[events[ii]] == 2 ) { entryX -= $gameMap.width(); }
else if ( loopMap[events[ii]] == 3 ) { entryY += $gameMap.height(); }
else if ( loopMap[events[ii]] == 4 ) { entryY -= $gameMap.height(); }
else if ( loopMap[events[ii]] == 5 ) { entryX += $gameMap.width(); entryY += $gameMap.height(); }
else if ( loopMap[events[ii]] == 6 ) { entryX -= $gameMap.width(); entryY += $gameMap.height(); }
else if ( loopMap[events[ii]] == 7 ) { entryX += $gameMap.width(); entryY -= $gameMap.height(); }
else if ( loopMap[events[ii]] == 8 ) { entryX -= $gameMap.width(); entryY -= $gameMap.height(); }
if ( events[ii]._trigger === 2 ) {
// Event touch is encasing
if ( Collider.encase( this._x + vx, this._y + vy, collider, entryX, entryY, events[ii].collider() ) || Collider.encase( entryX, entryY, events[ii].collider(), this._x + vx, this._y + vy, collider ) ) {
events[ii].start();
}
} else if ( Collider.intersect( this._x + vx, this._y + vy, collider, entryX, entryY, events[ii].collider() ) ) {
events[ii].start();
}
}
if ( !$gameMap.isAnyEventStarting() ) {
// Check for counters
var events = [];
var tiles = $gameMap.getTilesUnder( this, vx, vy );
for ( var ii = 0; ii < tiles.length; ii++ ) {
if ( $gameMap.isCounter( tiles[ii][0], tiles[ii][1] ) ) {
var x3 = $gameMap.roundXWithDirection( tiles[ii][0], this._direction );
var y3 = $gameMap.roundYWithDirection( tiles[ii][1], this._direction );
// Gather any solid characters within the "over counter" bounding box
events = events.concat( $gameMap.events().filter( function( event ) {
if ( event.isTriggerIn( triggers ) && event.isNormalPriority() && Collider.aabboxCheck( x3, y3, Collider.sharedTile().aabbox, event._x, event._y, event.collider().aabbox ) ) {
return true;
}
return false;
} ) );
}
}
if ( events.length === 0 ) {
return;
}
var closest;
var dist = Number.POSITIVE_INFINITY;
for ( var ii = 0; ii < events.length; ii++ ) {
var entryX = events[ii]._x;
var entryY = events[ii]._y;
var dx = this._x - entryX;
var dy = this._y - entryY;
var td = ( dx * dx + dy * dy );
if ( td < dist ) {
dist = td;
closest = events[ii];
}
}
closest.start();
}
}
};
Game_Player.prototype.startMapEvent = function( x, y, triggers, normal ) {
if ( !$gameMap.isEventRunning() ) {
$gameMap.eventsXy( x, y ).forEach( function( event ) {
if ( event.isTriggerIn( triggers ) && event.isNormalPriority() === normal ) {
event.start();
}
} );
}
};
Game_Player.prototype.moveStraight = function( d ) {
Game_Character.prototype.moveStraight.call( this, d );
};
Game_Player.prototype.moveDiagonally = function( horz, vert ) {
Game_Character.prototype.moveDiagonally.call( this, horz, vert );
};
Game_Player.prototype.getOnVehicle = function() {
var vx = Direction.isLeft( this._direction ) ? -0.5 : ( Direction.isRight( this._direction ) ? 0.5 : 0 );
var vy = Direction.isUp( this._direction ) ? -0.5 : ( Direction.isDown( this._direction ) ? 0.5 : 0 );
var bboxTests = $gameMap.getAABBoxTests( this, vx, vy );
var vehicle;
var airship = $gameMap.airship();
var ship = $gameMap.ship();
var boat = $gameMap.boat();
for ( var ii = 0; ii < bboxTests.length; ii++ ) {
if ( !!airship && airship._mapId === $gameMap.mapId() && Collider.aabboxCheck( bboxTests[ii].x, bboxTests[ii].y, bboxTests[ii].aabbox, airship._x, airship._y, airship.collider().aabbox ) ) {
this._vehicleType = 'airship';
this._collisionType = CollisionMesh.AIRSHIP;
vehicle = airship;
break;
}
if ( !!ship && ship._mapId === $gameMap.mapId() && Collider.aabboxCheck( bboxTests[ii].x, bboxTests[ii].y, bboxTests[ii].aabbox, ship._x, ship._y, ship.collider().aabbox ) ) {
this._vehicleType = 'ship';
this._collisionType = CollisionMesh.SHIP;
vehicle = ship;
break;
}
if ( !!boat && boat._mapId === $gameMap.mapId() && Collider.aabboxCheck( bboxTests[ii].x, bboxTests[ii].y, bboxTests[ii].aabbox, boat._x, boat._y, boat.collider().aabbox ) ) {
this._vehicleType = 'boat';
this._collisionType = CollisionMesh.BOAT;
vehicle = boat;
break;
}
}
if ( this.isInVehicle() ) {
this._vehicleGettingOn = true;
vehicle._passengerCollider = this.collider();
this._collider = vehicle.collider();
var dx = $gameMap.directionX( this._x, vehicle._x );
var dy = $gameMap.directionY( this._y, vehicle._y );
var wasThrough = this.isThrough();
this.setThrough( true );
this.moveVector( dx, dy );
this.setThrough( wasThrough );
this.gatherFollowers();
}
return this._vehicleGettingOn;
};
Game_Player.prototype.getOffVehicle = function() {
if ( this.vehicle().isLandOk( this.x, this.y, this.direction() ) ) {
if ( this.isInAirship() ) {
this.setDirection( 2 );
}
var vhx = this.vehicle().x;
var vhy = this.vehicle().y;
var vhd = this.vehicle().direction();
for (const follower of this._followers._data) {
follower._x = vhx;
follower._y = vhy;
follower._realX = vhx;
follower._realY = vhy;
follower.setDirection( vhd );
}
// this._followers.synchronize( this.vehicle().x, this.vehicle().y, this.vehicle().direction() );
this.vehicle().getOff();
if ( !this.isInAirship() ) {
var vehicleBox = this.vehicle().collider().aabbox;
var passengerBox = this.vehicle()._passengerCollider.aabbox;
var d = this.direction();
// Get disembark direction
var vx;
if ( Direction.isLeft( d ) ) {
vx = Math.floor( ( -passengerBox.right + vehicleBox.left ) * 64 ) / 64;
} else if ( Direction.isRight( d ) ) {
vx = Math.ceil( ( vehicleBox.right - passengerBox.left ) * 64 ) / 64;
} else {
vx = 0;
}
var vy;
if ( Direction.isUp( d ) ) {
vy = Math.floor( ( -passengerBox.bottom + vehicleBox.top ) * 64 ) / 64;
} else if ( Direction.isDown( d ) ) {
vy = Math.ceil( ( vehicleBox.bottom - passengerBox.top ) * 64 ) / 64;
} else {
vy = 0;
}
this.setThrough( true );
this.moveVector( vx, vy );
this.setThrough( false );
this.setTransparent( false );
}
this._vehicleGettingOff = true;
this.setMoveSpeed( 4 );
this.setThrough( false );
this.makeEncounterCount();
this.gatherFollowers();
}
return this._vehicleGettingOff;
};
Game_Player.prototype.updateVehicleGetOff = function() {
if ( !this.areFollowersGathering() && this.vehicle().isLowest() && this._collisionType !== CollisionMesh.WALK ) {
this._collider = this.vehicle()._passengerCollider;
this.vehicle()._passengerCollider = undefined;
this._collisionType = CollisionMesh.WALK;
this._vehicleGettingOff = false;
this._vehicleType = 'walk';
this.setTransparent( false );
}
};
} )();
/**
* Extensions
*/
( function() {
Game_Player.prototype.actionWidth = function() {
var bbox = this.collider().aabbox;
var width = bbox.right - bbox.left;
return width < 1 ? width : 1;
};
Game_Player.prototype.actionHeight = function() {
var bbox = this.collider().aabbox;
var height = bbox.bottom - bbox.top;
return height < 1 ? height : 1;
};
} )();
} )();
/**
* Game_Follower
*/
( function() {
/**
* Overrides
*/
( function() {
Game_Follower.prototype.initMembers = function() {
Game_Character.prototype.initMembers.call( this );
this._collider = Collider.createFromXML( FOLLOWERS.COLLIDER_LIST );
this._isFrozen = false;
this._circularMovement = FOLLOWERS.CIRCULAR_MOVEMENT;
};
Game_Follower.prototype.chaseCharacter = function( character ) {
if ( this._moveTarget || this._isFrozen ) {
return;
}
var displayWidth = Graphics.width / $gameMap.tileWidth();
var displayHeight = Graphics.height / $gameMap.tileHeight();
var aabbox = this.collider().aabbox;
var width = aabbox.right - aabbox.left;
var height = aabbox.bottom - aabbox.top;
var ax = this._x + ( aabbox.left + aabbox.right ) / 2;
var ay = this._y + ( aabbox.top + aabbox.bottom ) / 2;
// Teleportation
var midX = $gameMap.canvasToMapX( Graphics.width / 2 );
var dmX = $gameMap.directionX( ax, midX );
if ( dmX > displayWidth + width ) {
// Off left edge
var tx = $gameMap.canvasToMapX( 0 ) - width;
if ( $gameMap.canWalk( this, tx, this._y ) ) {
this.setPosition( tx, this._y );
}
} else if ( dmX < -displayWidth - width ) {
// Off right edge
var tx = $gameMap.canvasToMapX( Graphics.width ) + width;
if ( $gameMap.canWalk( this, tx, this._y ) ) {
this.setPosition( tx, this._y );
}
}
var midY = $gameMap.canvasToMapY( Graphics.height / 2 );
var dmY = $gameMap.directionY( ay, midY );
if ( dmY > displayHeight + height ) {
// Off top edge
var ty = $gameMap.canvasToMapY( 0 ) - height;
if ( $gameMap.canWalk( this, this._x, ty ) ) {
this.setPosition( this._x, ty );
}
} else if ( dmY < -displayHeight - height ) {
// Off bottom edge
var ty = $gameMap.canvasToMapY( Graphics.height ) + height;
if ( $gameMap.canWalk( this, this._x, ty ) ) {
this.setPosition( this._x, ty );
}
}
var characterBox = character.collider().aabbox;
var cWidth = characterBox.right - characterBox.left;
var cHeight = characterBox.bottom - characterBox.top;
var bx = character._x + ( characterBox.left + characterBox.right ) / 2;
var by = character._y + ( characterBox.top + characterBox.bottom ) / 2;
var dx = $gameMap.directionX( ax, bx );
var dy = $gameMap.directionY( ay, by );
var distance = Math.sqrt( dx * dx + dy * dy );
var radius = ( this.collider().type === Collider.CIRCLE ? this.collider().radius : ( width > height ? width : height ) / 2 );
var characterRadius = ( character.collider().type === Collider.CIRCLE ? character.collider().radius : ( cWidth > cHeight ? cWidth : cHeight ) / 2 );
if ( distance > ( radius + characterRadius ) * $gameSystem._followerDistance ) {
// Chase if far away
this.setMoveSpeed( character.realMoveSpeed() );
this.setThrough( $gamePlayer.isThrough() || $gamePlayer.isDebugThrough() );
if ( distance > 2 ) {
dx /= distance;
dy /= distance;
}
if ( this._circularMovement ) {
this.moveVector( dx * this.stepDistance, dy * this.stepDistance );
} else {
var vector = Direction.normalizeSquare( dx, dy );
this.moveVector( vector.x * this.stepDistance, vector.y * this.stepDistance );
}
this.setThrough( true );
}
if ( this.isOnLadder() ) {
this.setDirection( 8 );
} else if ( !this._wasMoving ) {
var adx = Math.abs( dx );
var ady = Math.abs( dy );
if ( adx > ady ) {
this.setDirectionVector( dx, 0 );
} else if ( ady > adx ) {
this.setDirectionVector( 0, dy );
}
}
};
} )();
/**
* Extensions
*/
( function() {
Game_Follower.prototype.setFrozen = function( frozen ) {
this._isFrozen = frozen;
};
} )();
} )();
/**
* Game_Followers
*/
( function() {
/**
* Overrides
*/
( function() {
Game_Followers.prototype.update = function() {
if ( this.areGathering() ) {
var direction = $gamePlayer.direction();
var visibleFollowers = this.visibleFollowers();
for ( var ii = 0; ii < visibleFollowers.length; ii++ ) {
var follower = visibleFollowers[ii];
var dx = $gameMap.directionX( follower._x, this._targetX );
var dy = $gameMap.directionY( follower._y, this._targetY );
var distance = Math.sqrt( dx * dx + dy * dy );
dx /= distance;
dy /= distance;
follower.setThrough( true );
follower.moveVector( dx * follower.stepDistance, dy * follower.stepDistance );
follower.setThrough( false );
follower.setDirection( direction );
}
if ( this.areGathered() ) {
this._gathering = false;
}
} else {
this.updateMove();
}
this.visibleFollowers().forEach( function( follower ) {
follower.update();
}, this );
if ( $gameSystem._staticFollowerDistance != FOLLOWERS.DISTANCE ) {
$gameSystem._staticFollowerDistance = FOLLOWERS.DISTANCE;
$gameSystem._followerDistance = FOLLOWERS.DISTANCE;
}
};
Game_Followers.prototype.gather = function() {
this._gathering = true;
this._targetX = $gamePlayer._x;
this._targetY = $gamePlayer._y;
};
Game_Followers.prototype.areGathered = function() {
var screenRadius = Math.sqrt( Graphics.width * Graphics.width + Graphics.height * Graphics.height ) / 2;
screenRadius /= Math.sqrt( $gameMap.tileWidth() * $gameMap.tileWidth() + $gameMap.tileHeight() * $gameMap.tileHeight() ) / 2;
var visibleFollowers = this.visibleFollowers();
for ( var ii = 0; ii < visibleFollowers.length; ii++ ) {
var follower = visibleFollowers[ii];
var dx = $gameMap.directionX( follower._realX, this._targetX );
var dy = $gameMap.directionY( follower._realY, this._targetY );
var distance = Math.sqrt( dx * dx + dy * dy );
if ( distance > screenRadius ) {
// Don't count if off screen
continue;
} else if ( distance > follower.stepDistance ) {
return false;
} else {
follower._x = this._targetX;
follower._y = this._targetY;
follower._realX = this._targetX;
follower._realY = this._targetY;
}
}
return true;
};
} )();
/**
* Extensions
*/
( function() {
Game_Followers.prototype.contains = function( item ) {
return this._data.indexOf( item ) >= 0;
};
} )();
} )();
/**
* Game_Vehicle
*/
( function() {
/**
* Overrides
*/
( function() {
var Game_Vehicle_initialize = Game_Vehicle.prototype.initialize;
Game_Vehicle.prototype.initialize = function( type ) {
Game_Vehicle_initialize.call( this, type );
if ( this.isAirship() ) {
this._collider = Collider.createFromXML( VEHICLES.AIRSHIP_COLLIDER_LIST );
} else if ( this.isShip() ) {
this._collider = Collider.createFromXML( VEHICLES.SHIP_COLLIDER_LIST );
} else if ( this.isBoat() ) {
this._collider = Collider.createFromXML( VEHICLES.BOAT_COLLIDER_LIST );
} else {
this._collider = Collider.sharedCharacter();
}
};
Game_Vehicle.prototype.isLandOk = function( x, y, d ) {
if ( this.isAirship() ) {
$gamePlayer