| 赞 | 276 |
| VIP | |
| 好人卡 | |
| 积分 | 154 |
| 经验 | |
| 最后登录 | 2026-11-3 |
| 在线时间 | 2110 小时 |
- 梦石
- 1
- 星屑
- 14389
- 在线时间
- 2110 小时
- 注册时间
- 2017-9-28
- 回帖
- 607
|
发表于 2018-4-28 20:37:29
|
显示全部楼层
本帖最后由 Nil2018 于 2018-4-28 21:10 编辑
- #-------------------------------------------------------------------------------
- # * [ACE] Khas 寻路
- #-------------------------------------------------------------------------------
- # * By Khas Arcthunder - arcthunder.site40.net
- # * Version: 1.0 EN
- # * Released on: 28/02/2012
- #
- #-------------------------------------------------------------------------------
- # * Terms of Use
- #-------------------------------------------------------------------------------
- # When using any Khas script, you agree with the following terms:
- # 1. You must give credit to Khas;
- # 2. All Khas scripts are licensed under a Creative Commons license;
- # 3. All Khas scripts are for non-commercial projects. If you need some script
- # for your commercial project (I accept requests for this type of project),
- # send an email to nilokruch@live.com with your request;
- # 4. All Khas scripts are for personal use, you can use or edit for your own
- # project, but you are not allowed to post any modified version;
- # 5. You can’t give credit to yourself for posting any Khas script;
- # 6. If you want to share a Khas script, don’t post the script or the direct
- # download link, please redirect the user to arcthunder.site40.net
- # 7. You are not allowed to convert any of Khas scripts to another engine,
- # such converting a RGSS3 script to RGSS2 or something of that nature.
- #
- # Check all terms at [url]http://arcthunder.site40.net/terms/[/url]
- #
- #-------------------------------------------------------------------------------
- # * Features
- #-------------------------------------------------------------------------------
- # Smart pathfinding
- # Fast Algorithm
- # Easy to use
- # Plug'n'Play
- # Game_Character objects compatible
- # Log tool
- #
- #-------------------------------------------------------------------------------
- # * 使用方法
- #-------------------------------------------------------------------------------
- # 使用脚本
- # find_path(id,x,y)
- #
- # id => -1玩家, 0本事件,x事件ID
- #
- # find_path(id,x,y,true)
- # 等待直到结束
- #
- # 如果你要启用寻路日志的功能, 请将"Log"设定为true.
- #
- #-------------------------------------------------------------------------------
- # * Register
- #-------------------------------------------------------------------------------
- $khas_awesome = [] if $khas_awesome.nil?
- $khas_awesome << ["Pathfinder",1.0]
- #-------------------------------------------------------------------------------
- # * Script
- #-------------------------------------------------------------------------------
- class Game_Interpreter
- def find_path(char,fx,fy,wait=false)
- $game_map.refresh if $game_map.need_refresh
- character = get_character(char)
- return if character.nil?
- return unless Path_Core.runnable?(character,fx,fy)
- path = Path_Core.run(character,fx,fy)
- return if path.nil?
- route = RPG::MoveRoute.new
- route.repeat = false
- route.wait = wait
- route.skippable = true
- route.list = []
- path << 0x00
- path.each { |code| route.list << RPG::MoveCommand.new(code)}
- character.force_move_route(route)
- @moving_character = character if wait
- end
- end
- class Path
- attr_accessor :axis
- attr_accessor :from
- attr_accessor :cost
- attr_accessor :dir
- def initialize(x,y,f,c,d)
- @axis = [x,y]
- @from = f
- @cost = c
- @dir = d
- end
- end
- module Path_Core
- Log = false #是否启用寻路日志
- Directions = {[1,0] => 3,[-1,0] => 2,[0,-1] => 4,[0,1] => 1}
- def self.runnable?(char,x,y)
- return false unless $game_map.valid?(x,y)
- return false if char.collide_with_characters?(x,y)
- $game_map.all_tiles(x,y).each { |id|
- flag = $game_map.tileset.flags[id]
- next if flag & 0x10 != 0
- return flag & 0x0f != 0x0f}
- return false
- end
- def self.run(char,fx,fy)
- return nil if char.x == fx && char.y == fy
- st = Time.now
- @char = char
- @start = Path.new(@char.x,@char.y,nil,0,nil)
- @finish = Path.new(fx,fy,nil,0,nil)
- @list = []
- @queue = []
- @preference = ((@char.x-fx).abs > (@char.y-fy).abs ? 0x0186aa : 0x01d)
- class << @list
- def new_path?(path_class)
- for path in self
- return false if path.axis == path_class.axis
- end
- return true
- end
- end
- class << @queue
- def new_path?(path_class)
- for path in self
- return false if path.axis == path_class.axis
- end
- return true
- end
- end
- if @preference & 0x02 == 0x02
- @queue << Path.new(@char.x,@char.y+1,@start,1,[0,1]) if @char.passable?(@char.x,@char.y,2)
- @queue << Path.new(@char.x,@char.y-1,@start,1,[0,-1]) if @char.passable?(@char.x,@char.y,8)
- @queue << Path.new(@char.x+1,@char.y,@start,1,[1,0]) if @char.passable?(@char.x,@char.y,6)
- @queue << Path.new(@char.x-1,@char.y,@start,1,[-1,0]) if @char.passable?(@char.x,@char.y,4)
- @list << @start
- loop do
- break if @queue.empty?
- @cpath = @queue[0]
- if @cpath.axis == @finish.axis
- @finish.cost = @cpath.cost
- @finish.from = @cpath
- break
- end
- @list << @cpath
- @path_array = []
- p1 = Path.new(@cpath.axis[0]+1,@cpath.axis[1],@cpath,@cpath.cost+1,[1,0])
- p2 = Path.new(@cpath.axis[0]-1,@cpath.axis[1],@cpath,@cpath.cost+1,[-1,0])
- p3 = Path.new(@cpath.axis[0],@cpath.axis[1]+1,@cpath,@cpath.cost+1,[0,1])
- p4 = Path.new(@cpath.axis[0],@cpath.axis[1]-1,@cpath,@cpath.cost+1,[0,-1])
- @path_array << p3 if @char.passable?(@cpath.axis[0],@cpath.axis[1],2) && @list.new_path?(p3) && @queue.new_path?(p3)
- @path_array << p4 if @char.passable?(@cpath.axis[0],@cpath.axis[1],8) && @list.new_path?(p4) && @queue.new_path?(p4)
- @path_array << p1 if @char.passable?(@cpath.axis[0],@cpath.axis[1],6) && @list.new_path?(p1) && @queue.new_path?(p1)
- @path_array << p2 if @char.passable?(@cpath.axis[0],@cpath.axis[1],4) && @list.new_path?(p2) && @queue.new_path?(p2)
- @path_array.each { |path| @queue << path }
- @queue.delete(@cpath)
- end
- else
- @queue << Path.new(@char.x+1,@char.y,@start,1,[1,0]) if @char.passable?(@char.x,@char.y,6)
- @queue << Path.new(@char.x-1,@char.y,@start,1,[-1,0]) if @char.passable?(@char.x,@char.y,4)
- @queue << Path.new(@char.x,@char.y+1,@start,1,[0,1]) if @char.passable?(@char.x,@char.y,2)
- @queue << Path.new(@char.x,@char.y-1,@start,1,[0,-1]) if @char.passable?(@char.x,@char.y,8)
- @list << @start
- loop do
- break if @queue.empty?
- @cpath = @queue[0]
- if @cpath.axis == @finish.axis
- @finish.cost = @cpath.cost
- @finish.from = @cpath
- break
- end
- @list << @cpath
- @path_array = []
- p1 = Path.new(@cpath.axis[0]+1,@cpath.axis[1],@cpath,@cpath.cost+1,[1,0])
- p2 = Path.new(@cpath.axis[0]-1,@cpath.axis[1],@cpath,@cpath.cost+1,[-1,0])
- p3 = Path.new(@cpath.axis[0],@cpath.axis[1]+1,@cpath,@cpath.cost+1,[0,1])
- p4 = Path.new(@cpath.axis[0],@cpath.axis[1]-1,@cpath,@cpath.cost+1,[0,-1])
- @path_array << p1 if @char.passable?(@cpath.axis[0],@cpath.axis[1],6) && @list.new_path?(p1) && @queue.new_path?(p1)
- @path_array << p2 if @char.passable?(@cpath.axis[0],@cpath.axis[1],4) && @list.new_path?(p2) && @queue.new_path?(p2)
- @path_array << p3 if @char.passable?(@cpath.axis[0],@cpath.axis[1],2) && @list.new_path?(p3) && @queue.new_path?(p3)
- @path_array << p4 if @char.passable?(@cpath.axis[0],@cpath.axis[1],8) && @list.new_path?(p4) && @queue.new_path?(p4)
- @path_array.each { |path| @queue << path }
- @queue.delete(@cpath)
- end
- end
- if @finish.from.nil?
- return nil
- else
- steps = [@finish.from]
- loop do
- cr = steps[-1]
- if cr.cost == 1
- @result = []
- steps.each { |s| @result << Directions[s.dir]}
- break
- else
- steps << cr.from
- end
- end
- self.print_log(Time.now-st) if Log
- return @result.reverse
- end
- end
- def self.print_log(time)
- print "\n--------------------\n"
- print "Khas Pathfinder\n"
- print "Time: #{time}\n"
- print "Size: #{@result.size}\n"
- print "--------------------\n"
- end
- end
复制代码
此外还有一个(看到第21行)
- ## 事件效果 v3.1 ##
- # 事件x、y坐标微调, 事件图像缩放、转动、改变色调、镜像、闪烁等功能
- #
- # 使用方法: 在事件的移动路线里使用脚本
- # offset(x,y) 事件图像横向偏移x像素,纵向偏移y像素
- #
- # set_zoom(数值) 缩放大小
- #
- # rotate(数值) 转动角度,可以是 -360 至 360
- #
- # blend(颜色) 改变颜色,"颜色"替换为颜色对象
- # -> Color.new(red,blue,green,不透明度)
- #
- # mirrored 左右镜像
- #
- # flash(颜色,时间) 闪烁效果, "颜色"替换为颜色对象
- # 时间是闪烁时间
- #
- # slide(x, y) 事件横向滑动x像素,纵向滑动y像素
- #
- # waypoint(x,y) 事件朝指定坐标移动,等待至移动结束
- #
- # moveto(x,y) 事件瞬间传送到指定坐标.(虽然用事件指令也可以做到)
- #
- # 新指令:
- # @shakechar 改变为偏移效果
- # @zoom 改变为 set_zoom
- # (旧指令仍然有效)
- #
- # fadein 一段时间(默认是10帧)事件图像不透明度淡入至 255
- # fadein(时间)
- #
- # fadeout 一段时间(默认是10帧)事件图像不透明度淡出至 0
- # fadeout(时间)
- #
- # shake 一段时间(默认是30帧)事件图像上下震动
- #
- # shake(时间)
- # random 将事件移动到随机当前地图中的随机位置,可以设
- # random(宽度,高度) 定最大范围限制.
- #
- # random_region(id) 将事件移动到随机当前地图中某区域的随机位置,
- # random_region(id,w,h) 可以设定最大范围限制.
- #
- # self_switch("字母",true/false) 开启或关闭事件的独立开关. 字母替换为
- # "A" 至 "D".
- #
- # balloon(id) 事件显示指定心情
- #
- #
- #------#
- #-- Script by: V.M of D.T
- #
- #- Questions or comments can be:
- # posted on the thread for the script
- # given by email: sumptuaryspade@live.ca
- # provided on facebook: [url]http://www.facebook.com/DaimoniousTailsGames[/url]
- #
- #- Free to use in any project with credit given,
- #-- donations always welcome via paypal!
-
- class Game_CharacterBase
- alias shake_init_public_members init_public_members
- alias shake_update update
-
- attr_accessor :zoom
- attr_accessor :flash_on
- attr_accessor :flash_color
- attr_accessor :flash_time
- attr_accessor :angle
- attr_accessor :need_rotate
- attr_accessor :mirror
- attr_accessor :blend_color
-
- def init_public_members
- shake_init_public_members
- reset_event_details
- end
- def reset_event_details
- @shakechar = [false, 0, 0]
- @zoom = 1
- @flash_on = false
- @flash_color = Color.new(0,0,0,0)
- @flash_duration = 0
- @angle = 0
- @total_angle = 0
- @need_rotate = false
- @mirror = false
- @blend_color = Color.new(0,0,0,0)
- @fade = @opacity
- @fade_time = 0
- @shake_time = 0
- @shake_direction = 0
- end
- def offset(x,y); @shakechar = [true, x, y]; end
- def reset
- reset_event_details
- rotate(@total_angle*-1)
- end
- def set_zoom(size); @zoom = size; end
- def flash(color,duration)
- @flash_color = color
- @flash_time = duration
- @flash_on = true
- end
- def rotate(angle)
- @total_angle += angle
- @angle = angle
- @need_rotate = true
- end
- def rotateoff; @need_rotate = false; end
- def flashoff; @flash_on = false; end
- def mirrored; @mirror == true ? @mirror = false : @mirror = true; end
- def blend(color); @blend_color = color; end
- def screen_x
- if @shakechar[0] == false || @shakechar[1] == nil then
- $game_map.adjust_x(@real_x) * 32 + 16 else
- $game_map.adjust_x(@real_x) * 32 + 16 + @shakechar[1] end
- end
- def screen_y
- if @shakechar[0] == false || @shakechar[2] == nil then
- $game_map.adjust_y(@real_y) * 32 + 32 - shift_y - jump_height else
- $game_map.adjust_y(@real_y) * 32 + 32 - shift_y - jump_height + @shakechar[2] end
- end
- def slide(x, y)
- @next_x = x + @shakechar[1]
- @next_y = y + @shakechar[2]
- @step_anime = true
- @shakechar[0] = true
- @sliding = true
- end
- def fadein(time = 10)
- @fade_time = time
- @fade = 255
- end
- def fadeout(time = 10)
- @fade_time = time
- @fade = 0
- end
- def shake(time = 30)
- @shakechar[0] = true
- @shake_time = time
- end
- def random(rect_x = 250, rect_y = 250)
- tiles = []
- tiles = tile_array(rect_x,rect_y)
- tiles = tiles.compact
- return if tiles.empty?
- tile = rand(tiles.size)
- moveto(tiles[tile][0],tiles[tile][1])
- end
- def random_region(id, rect_x = 250, rect_y = 250)
- tiles = tile_array(rect_x,rect_y)
- tiles.each_index do |i|
- next if tiles[i].nil?
- erase = false
- erase = true unless $game_map.region_id(tiles[i][0], tiles[i][1]) == id
- tiles[i] = nil if erase
- end
- tiles = tiles.compact
- return if tiles.empty?
- tile = rand(tiles.size)
- moveto(tiles[tile][0],tiles[tile][1])
- end
- def tile_array(rect_x,rect_y)
- tiles = [];nx = 0;ny = 0
- ($game_map.width * $game_map.height).times do |i|
- tiles.push([nx,ny])
- nx += 1
- if nx == $game_map.width
- nx = 0
- ny += 1
- end
- end
- tiles.each_index do |i|
- erase = false
- erase = true if tiles[i][0] == $game_player.x && tiles[i][1] == $game_player.y
- erase = true if tiles[i][0] == x && tiles[i][1] == y
- erase = true if tiles[i][0] > x + rect_x || tiles[i][0] < x - rect_x
- erase = true if tiles[i][1] > y + rect_y || tiles[i][1] < y - rect_y
- erase = true if !$game_map.check_passage(tiles[i][0], tiles[i][1], 0x0f)
- tiles[i] = nil if erase
- end
- return tiles
- end
- def self_switch(symbol, boolean)
- return if !self.is_a?(Game_Event)
- key = [$game_map.map_id, self.event.id, symbol]
- $game_self_switches[key] = boolean
- end
- def balloon(id)
- @balloon_id = id
- end
- def update
- shake_update
- update_sliding if @sliding
- update_fading if @opacity != @fade && @fade_time > 0
- update_shake if @shake_time > 0
- end
- def update_fading
- @opacity += (255 / @fade_time) if @fade > @opacity
- @opacity -= (255 / @fade_time) if @fade < @opacity
- @opacity = 0 if @opacity < 0; @opacity = 255 if @opacity > 255
- @fade_time = 0 if @opacity == 0 || @opacity == 255
- end
- def update_sliding
- @shakechar[1] += 0.5 if @next_x > @shakechar[1]
- @shakechar[1] -= 0.5 if @next_x < @shakechar[1]
- @shakechar[2] += 0.5 if @next_y > @shakechar[2]
- @shakechar[2] -= 0.5 if @next_y < @shakechar[2]
- return unless @shakechar[1] == @next_x
- return unless @shakechar[2] == @next_y
- @sliding = false
- @step_anime = false
- end
- def update_shake
- @shake_time -= 1
- @shakechar[2] += 1 if @shake_direction == 0
- @shakechar[2] -= 1 if @shake_direction == 1
- if @shake_time % 3 == 0
- @shake_direction += 1
- @shake_direction = 0 if @shake_direction > 1
- end
- end
- end
-
- class Game_Character
- alias eft_init_private_members init_private_members
- def init_private_members
- eft_init_private_members
- @waypoint = [-1,-1]
- end
- def update_routine_move
- if @wait_count > 0
- @wait_count -= 1
- else
- @move_succeed = true
- command = @move_route.list[@move_route_index]
- if command
- if @waypoint[0] != -1
- process_waypoint_command
- advance_waypoint_route_index
- else
- process_move_command(command)
- advance_move_route_index
- end
- end
- end
- end
- def process_waypoint_command
- sx = distance_x_from(@waypoint[0])
- sy = distance_y_from(@waypoint[1])
- if sx.abs > sy.abs
- move_straight(sx > 0 ? 4 : 6)
- move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0
- elsif sy != 0
- move_straight(sy > 0 ? 8 : 2)
- move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0
- end
- @waypoint = [-1,-1] if !@move_succeed && @move_route.skippable
- end
- def advance_waypoint_route_index
- return unless @x == @waypoint[0]
- return unless @y == @waypoint[1]
- @waypoint = [-1,-1]
- end
- def waypoint(x,y); @waypoint = [x,y]; end
- end
-
- class Sprite_Character
- alias eventfp_update update
- def update
- eventfp_update
- zoom_update
- mirror_update
- blend_update
- rotate_update if @character.need_rotate
- flash_update if @character.flash_on
- end
- def blend_update; self.color = @character.blend_color; end
- def zoom_update
- self.zoom_y = @character.zoom
- self.zoom_x = @character.zoom
- end
- def mirror_update; self.mirror = @character.mirror; end
- def flash_update
- flash(@character.flash_color,@character.flash_time)
- @character.flashoff
- end
- def rotate_update
- self.angle = @character.angle
- @character.rotateoff
- end
- end
复制代码 |
|