#--------------------------------------------------------------------------
# ◎获取基本移动范围
#--------------------------------------------------------------------------
def base_move_range
return $data_classes[@class_id].move_range
end
#--------------------------------------------------------------------------
# ◎获取基本自身动作延迟
#--------------------------------------------------------------------------
def base_motion_delay
n = $data_classes[@class_id].motion_delay
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += armor1 != nil ? armor1.motion_delay : 0
n += armor2 != nil ? armor2.motion_delay : 0
n += armor3 != nil ? armor3.motion_delay : 0
n += armor4 != nil ? armor4.motion_delay : 0
return n
end
#--------------------------------------------------------------------------
# ◎获取基本自身行动延迟
#--------------------------------------------------------------------------
def base_action_delay
return $data_weapons[@weapon_id].action_delay
end
#--------------------------------------------------------------------------
# ◎获取基本射程
#--------------------------------------------------------------------------
def base_range
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.range : 1
end
#--------------------------------------------------------------------------
# ◎获取基本范围
#--------------------------------------------------------------------------
def base_aoe
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.aoe : 1
end
#--------------------------------------------------------------------------
# ● 获取角色 ID
#--------------------------------------------------------------------------
def id
return @actor_id
end
#==========================================================================
# ■ 移动范围算法
#
# 严重不建议移动范围大于10,运算范围时会耗费大量时间
# 移动范围20是我这台破机器的极限..所以照顾一下最低配置的玩家吧
# 虽然用Graphics.update可以避免因长时间运算导致跳出游戏,
# 但运算时间会增加4倍左右(移动范围20+Graphics.update用了40秒运算)
#==========================================================================
#--------------------------------------------------------------------------
# 获得可移动范围
#--------------------------------------------------------------------------
def get_move_range(grid, range)
# 防止死机
if range > 20
p '移动范围过大!'
return
end
# 初始化可移动格集合
@available_grids = [grid]
@ori_event = $game_map.events[@active_battler.event_id]
find_next_grid(grid, 0, range)
return @available_grids
end
#--------------------------------------------------------------------------
# 寻找下一格
#--------------------------------------------------------------------------
def find_next_grid(grid, direction=0, range=5)
# 超出范围就返回结果
if grid.move_steps >= range
return
end
# direction 的作用是避免其返回上一格,减轻1/4计算量
# 向上寻找
if @ori_event.slg_passable?(grid.x, grid.y, 8) and direction != 2
new_grid = Grid.new(grid.x, grid.y-1, grid.path+[8])
# 防止重复
if !repeat?(new_grid)
@available_grids.push(new_grid)
find_next_grid(new_grid, 8, range)
end
end
# 向左寻找
if @ori_event.slg_passable?(grid.x, grid.y, 4) and direction != 6
new_grid = Grid.new(grid.x-1, grid.y, grid.path+[4])
# 防止重复
if !repeat?(new_grid)
@available_grids.push(new_grid)
find_next_grid(new_grid, 4, range)
end
end
# 向下寻找
if @ori_event.slg_passable?(grid.x, grid.y, 2) and direction != 8
new_grid = Grid.new(grid.x, grid.y+1, grid.path+[2])
# 防止重复
if !repeat?(new_grid)
@available_grids.push(new_grid)
find_next_grid(new_grid, 2, range)
end
end
# 向右寻找
if @ori_event.slg_passable?(grid.x, grid.y, 6) and direction != 4
new_grid = Grid.new(grid.x+1, grid.y, grid.path+[6])
# 防止重复
if !repeat?(new_grid)
@available_grids.push(new_grid)
find_next_grid(new_grid, 6, range)
end
end
end
#--------------------------------------------------------------------------
# 检查是否格子重复
#--------------------------------------------------------------------------
def repeat?(grid)
for old_grid in @available_grids
if grid.x == old_grid.x and grid.y == old_grid.y
# 有更短的路径的话
if grid.move_steps < old_grid.move_steps
@available_grids.delete(old_grid)
return false
else
return true
end
end
end
return false
end
end
# 默认移动范围
DEFAULT_MOVE = 0
# 移动范围属性(最后一个保留作飞行/地面)
first = 66
MOVE_ELEMENT = [first,first+1,first+2,first+3,first+4]
#==============================================================================
# ■ Grid
#------------------------------------------------------------------------------
# SLG地图格子的类。
#==============================================================================
class Grid
attr_accessor :x # x坐标
attr_accessor :y # y坐标
attr_accessor :path # 路径(移动用)
attr_accessor :range # 距离(保留作攻击用)
def initialize(x, y, path=[], range=-1)
@x = x
@y = y
@path = path
@range = range
end
# 取得移动步数
def move_steps
return @path.size
end
#--------------------------------------------------------------------------
# ◎比较坐标
#--------------------------------------------------------------------------
def compare_grids(grids)
for grid in grids
if @x == grid.x and @y == grid.y
return true
end
end
return false
end
end
2、添加角色问题——添加角色后,把现有角色身上的事件复制粘贴后,发现移动范围和攻击范围都是本身的一格,在哪里能改
3、将角色设置为不可穿越
相关脚本如下
#--------------------------------------------------------------------------
# 加入路径
#--------------------------------------------------------------------------
def setup_path(event_id, target_grid)
event = $game_map.events[event_id]
event.path = RPG::MoveRoute.new
event.path.repeat = false
event.path.skippable = false
event.path.list.clear
path = target_grid.path
for step in path
# 下
event.path.list.push RPG::MoveCommand.new(1) if step == 2
# 左
event.path.list.push RPG::MoveCommand.new(2) if step == 4
# 右
event.path.list.push RPG::MoveCommand.new(3) if step == 6
# 上
event.path.list.push RPG::MoveCommand.new(4) if step == 8
end
end
#--------------------------------------------------------------------------
# 开始移动
#--------------------------------------------------------------------------
def start_event(event_id)
event = $game_map.events[event_id]
event.path.list.push RPG::MoveCommand.new(0)
event.move_route = event.path
event.move_route_index = 0
end
#--------------------------------------------------------------------------
# ◎获得指定坐标
#--------------------------------------------------------------------------
def get_grid(grids, x, y)
for grid in grids
# 坐标对应
if grid.x == x and grid.y == y
# 该格有战斗者的话返回false
if @battler_coordinate[x, y] != 0
return false
# 否则返回该格
else
return grid
end
end
end
return false
end
#--------------------------------------------------------------------------
# ◎获得路径终点(防止战斗者重叠用)
#--------------------------------------------------------------------------
def get_path_end_grid(start_grid, path)
x = start_grid.x
y = start_grid.y
for step in path
next if step == nil
case step.code
# 下
when 1
y += 1
# 左
when 2
x -= 1
# 右
when 3
x += 1
# 上
when 4
y -= 1
end
end
return Grid.new(x,y)
end
end
如果帖子回复不太方便可以加我qq526012523,谢谢各位高手了!!如果需要报酬的话我可以往银行卡上打钱(50元以内)作者: mmll0070 时间: 2009-11-21 15:41
要这么麻烦么,职业属性一栏的移动范围从C(关闭)点一下到B(打开)
选择你想要的步数。4格就选+4 5格就选+4 +1 7格就选+4 +2 +1
想要同职业步数不同就多设置一个职业
比如同样战士,一个移动力5格一个6格
就设置2种职业。都叫战士。技能什么都一样。一个点+4+1
另一个点+4+2
不就好了