Class: Pathfinding::Target::Character

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

Returns a new instance of Character.



71
72
73
74
75
76
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 71

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



111
112
113
114
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 111

def self.load(data)
  data[0] = (data[0] == 0 ? $game_player : $game_map.events[data[0]])
  return Character.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)


91
92
93
94
95
96
97
98
99
100
101
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 91

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 fiveng 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)


83
84
85
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 83

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

#saveArray<Object>

Gather the savable data

Returns:



105
106
107
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00650 RMXP/00710 Pathfinding_targets.rb', line 105

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