Class: Pathfinding::Target::Character_Reject

Inherits:
Object
  • Object
show all
Defined in:
scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Character_Reject

Returns a new instance of Character_Reject.



118
119
120
121
122
123
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 118

def initialize(*args)
  @character = args[0]
  @radius = args[1]
  @sx = @character.x
  @sy = @character.y
end

Class Method Details

.load(data)

Create new target from the given data

Parameters:

  • data (Array)

    saved data



158
159
160
161
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 158

def self.load(data)
  data[0] = (data[0] == 0 ? $game_player : $game_map.events[data[0]])
  return Character_Reject.new(*data)
end

Instance Method Details

#check_move(x, y) ⇒ Boolean

Check if the character targetted has moved, considering the distance for optimisation and return true if the target is considered as moved

Parameters:

  • x (Integer)

    the x coordinate of the heading event

  • y (Integer)

    the y coordinate of the heading event

Returns:

  • (Boolean)


138
139
140
141
142
143
144
145
146
147
148
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 138

def check_move(x, y)
  if ((c = @character).x - x).abs + (c.y - y).abs > 15
    if (@sx - c.x).abs + (@sy - c.y).abs > 10
      @sx = c.x
      @sy = c.y
      return true
    end
    return false
  end
  return @sx != (@sx = c.x) || @sy != (@sy = c.y)
end

#reached?(x, y, z) ⇒ Boolean

Test if the target is reached at the given coords

Parameters:

  • x (Integer)

    the x coordinate to test

  • y (Integer)

    the y coordinate to test

  • z (Integer)

    the x coordinate to test

Returns:

  • (Boolean)


130
131
132
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 130

def reached?(x, y, z)
  return ((@character.x - x).abs + (@character.y - y).abs) > @radius
end

#saveArray<Object>

Gather the savable data

Returns:



152
153
154
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 152

def save
  return [:Character_Reject, @character.id, @radius]
end