赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 1300 |
最后登录 | 2015-4-27 |
在线时间 | 16 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 16 小时
- 注册时间
- 2009-11-16
- 帖子
- 7
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
1、修改移动范围问题——想让每个角色的移动范围各不相同,但不知道如何针对角色来修改
相关脚本如下:
#--------------------------------------------------------------------------
# ● 设置
# actor_id : 角色 ID
#--------------------------------------------------------------------------
def setup(actor_id)
actor = $data_actors[actor_id]
@actor_id = actor_id
@name = actor.name
@character_name = actor.character_name
@character_hue = actor.character_hue
@battler_name = actor.battler_name
@battler_hue = actor.battler_hue
@class_id = actor.class_id
@weapon_id = actor.weapon_id
@armor1_id = actor.armor1_id
@armor2_id = actor.armor2_id
@armor3_id = actor.armor3_id
@armor4_id = actor.armor4_id
@level = actor.initial_level
@exp_list = Array.new(101)
make_exp_list
@exp = @exp_list[@level]
@skills = []
@hp = maxhp
@sp = maxsp
@states = []
@states_turn = {}
@maxhp_plus = 0
@maxsp_plus = 0
@str_plus = 0
@dex_plus = 0
@agi_plus = 0
@int_plus = 0
#----------
# 学会特技
for i in 1..@level
for j in $data_classes[@class_id].learnings
if j.level == i
learn_skill(j.skill_id)
end
end
end
# 刷新自动状态
update_auto_state(nil, $data_armors[@armor1_id])
update_auto_state(nil, $data_armors[@armor2_id])
update_auto_state(nil, $data_armors[@armor3_id])
update_auto_state(nil, $data_armors[@armor4_id])
end
#--------------------------------------------------------------------------
# ◎获取基本移动范围
#--------------------------------------------------------------------------
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元以内) |
|